CompSci 100E- Classwork 6 - Feb 15, 2011
10 pts

Today's classwork focuses on Inheritance and Reading from Files

Snarf the Classwork 6 to get started.


Students in School

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:

  1. Add a new type of student to the simulation. It should at least extend the Student super-class, but may extend one of its sub-classes as well. You decide what methods should it override, or whether it should define its own new methods.

    Write in your README file a brief description of this Student.

  2. In the main method of the School class, create an ArrayList of type Student, and add each of your students to the ArrayList. What type of import statement do you need to use an ArrayList?

    Then write a loop to simulate all of the students in your ArrayList by calling the method goUntilDead. DO NOT modify the goUntilDead method.

  3. Create a text file in the same project that lists each student's name on a separate line. Click on the project, then select "File", "new", "untitled text file". Enter the four student names in the file. When the file is saved, it will ask you for a name for the file and the location. You want it stored in the same project. Give it a name with .txt extension to indicate it is a text file.
    
         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.

  4. Modify the data file to include the type of student as well as the name of the student. Add in additional students. Now use a loop to read in the student info, assume you do not know how many students are in the datafile.
      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.

Submit

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