Goals
Students will demonstrate their understanding of arrays, object instantiation, class creation and the use of constructor, accessor, and mutator methods in Java by modifying their student account program following the details below.
Skills
- Arrays of objects
Program Details
Create a program that can create, access and modify an array of student accounts from a student account class. You can use your Student Account Class or Game Character Overloaded Class from prior assignments, make a copy of the file, and then just add to it for this assignment.
- Student Account or Game Character Overloaded Class
- One new private Data Variable
- Keep the others the same (name, address, and graduation year)
- A String array of 7 course names that the student is taking or an inventory for the Game Character.
- Methods
Two Constructors methodsOne with no parameters and asks the user to enter the data.Modify this so that the user also enters the class names.
- One that sets all variables by directly passing the values in directly as parameters.
- You can pass the array values in individually or as an array. You choose which is easier for you.
- Two new Accessor methods (getters)
- Keep the ones already written.
- A new getCourses () or getInventory()
- Has no parameters.
- Returns an array of all the classes or inventory items.
- A new getCourse (int period) or getInventoryItem (int num)
- Passes in an integer as the course period or inventory number to know which item in the inventory will be returned.
- Hint: array indexing starts at zero, not one.
- Returns a string with the class or inventory name for the given number.
- Two new Mutator methods (setters)
- Keep the seven mutators you already have .
- A new setCourses ( String [ ] ) or setInventory( String [ ] )
- Passes in an array of new course or inventory names.
- Sets courses to the new courses.
- Reports the old and new values.
- A new setCourse (String, int) or setInventoryItem (String, num)
- Passes in two variables
- A String as the new course or inventory name.
- An integer as the course or inventory number.
- Sets the correct name.
- Outputs that the information changed from the old to the new information.
- Passes in two variables
- A toString method
- A normal toString method that outputs everything including the new list of courses or inventory.
- You might use an Arrays.toString() method to print the classes/inventory array or you can write your own code to do this.
- One new private Data Variable
- Character Data Text File
- Create a text file that your main program will read to initialize your character objects. You can just modify the one used from the Game Character Overloaded assignment.
- In addition to the Name, Attribute, and Statistic for each Game Character, you need to add an class list or inventory for each character.
- The file should have information for at least 3 different Game Characters.
- Main Program:
- Scan the file with the Character information.
- See above for creation of the file.
- See Game Character Overloaded for scanning from files.
- Creates an array of four different objects
One is initialized with the constructor that asks the user for all the input.- The other three are initialized from the data in the Character Data file
- Modify the student classes or inventory items
- You do not have to run the setters nor getters that you imported from the old class. Only run the new setters.
- Run the setCourses or setInventory method to modify all of the items for a single student or character.
- Run the setCourse or setInventoryItem method at least once on the other two students. Make sure it works on the first and last item in course/inventory array.
- Each setter method should output that the values have changed.
- Output the initial and final student values using the toString method.
- Scan the file with the Character information.
Resources
Java Textbook
Chapter 8: Arrays