Goals
Students will demonstrate their understanding of object instantiation, class creation and the use of constructor, accessor, and mutator methods in Java by creating a game character program following the details below and the programming rubric.
Skills
- Object oriented programming
- Class creation
- Object instantiation
Program Details
Create a program that can create, access and modify game characters from a game character class.
- Game Character Class
- 3 private Data Variables
- String Name
- String Attribute (class, position, address, etc.)
- Integer Statistic (health, intelligence, age, grade, etc.)
- Methods
- Constructor method
- Passes in all three values as parameters.
- Sets the values for the Name, Attribute, and Statistic.
- Three Accessor methods (getters)
- Must be declared Public.
- One for each of the above data variables.
- Pass in no parameters.
- Return the appropriate variable.
- Four Mutator methods (setters)
- Sets the Name on the character
- Must be declared public void.
- Passes in the new name as the parameter.
- Sets the Attribute of the character.
- Must be declared public void.
- Passes in the new Attribute
- Sets the Statistic
- Must be declared Public void.
- Passes in the new Statistic value.
- Sets the Statistic to the new value.
- Value must be a positive value.
- Change Statistic
- Must be declared Public void.
- Passes in an integer value to change the Statistic by.
- Increments or decrements the Statistic by the value.
- Checks to see if the statistic is beyond a threshold value and will report if it is. For example: if the character’s health drops below zero, the program should report that the character has died.
- Sets the Name on the character
- Constructor method
- 3 private Data Variables
- Main Program Class:
- Object Instantiation
- Create at least 2 objects (characters) from the above class.
- Use the constructor method to create the objects.
- Enter the data directly in your program. You don’t need to ask the user to input the data.
- Object modification
- Change the Name, Attribute, and Statistic of one object using the Setter methods.
- Call the Change Statistic method twice
- Increment or decrement one character’s Statistic, but not outside of the threshold
- Increment or decrement the other character’s Statistic to a value outside of the threshold limit. This should trigger an output from the Change Statistic method.
- Enter the data directly in your program. You don’t need to ask the user to input the data.
- Output
- Output the following information to the console:
- The initial values of both characters
- The changes that were made to each character
- The final values of both characters
- Your Change Statistic from above should output when the character Statistic is modified too much. Your main program does not need to do this directly.
- Use the Getter methods to output the data.
- Output the following information to the console:
- Object Instantiation
Resources
Java Textbook
Chapter 4: Writing Classes
Chapter 7: Object Oriented Design