Today's classwork focuses on Inheritance and Reading from Files
Snarf the Classwork 6 to get started.
This program represents a silly model of the students at Duke University, where students work too hard, eat poorly, and eventually die. However, the interesting part about the program is that we can use the same method to simulate a variety of different students even though each type of student is a different class: generic Student, Duke student, and Cosmic student. The School class models the school all students attend and actually runs the simulation.
First, look over the program and predict the output it will produce. After thinking about it, you can see the output here or run it in Eclipse. Once you are confident that you understand the code, make the following modifications to the program:
Write in your README file a brief description of this Student.
Then write a loop to simulate all of the students in your ArrayList
by calling the method goUntilDead
. DO NOT modify
the goUntilDead
method.
Pat Chris Sam YourNewStudent'SNameHere
Read
the student names from a file and use those names to create a Student
object
that represents each and store each in a list.
To do this, create a
Scanner
object and read each word in the file, use that word to create
a Student
object, and add the newly created student to the ArrayList of
students. You may want to cut and paste from classwork 8 ClassScores,
in particular cut and paste the JFileChooser variable and the
getScanner method. OR see how files were done with classwork 10.
Student Pat DukeStudent Chris CosmicStudent Sam Student Fred CosmicStudent Lauren etc.
Create a new method, makeStudent
, that has one paramenter
of type Scanner. This method reads
one line of the new data file (the type of student), then creates and returns the
appropriate Student
sub-class.
The method should use the first word on the line to choose the which kind
of Student
sub-class
to create and the second word as the name to initialize that object. The
result of the call to makeStudent
should be added to the ArrayList.
Add to the README file your name, how long you worked on this and anyone you received help from.
Submit through Ambient your Java project including README file to the clwk06-0215