CSE 8B Spring 2001
Homework #2

Required reading: Savitch text Chapters 7

Turn in due date: Wednesday April 18 (i.e., 8 am April 19)
Interview due date: Monday April 23.
DO NOT turnin hw2 before April 13. You can do hw2 before then and even take an interview, just do not turn it in before April 13

Note: You can do this and take an interview without turning in the assignment, as long as it is before the turnin deadline (and until the deadline is announced it is definitely before the deadline.)

Programming: You may work in teams of two students, but once you form a team, you cannot change the team for this assignment. You may work alone if you prefer.

Define a class called CSEStudent that is a derived class of the class Student in Display 7.3 in the Savitch text. (The file Student.java is on the CD that comes with the book and is also in the public directory.)

The class CSEStudents will have two additional instance variables named language and numberOfLanguages (besides the inherited ones). The variable language will be an array of strings that can hold up to 10 strings. It will be used to hold a list of programming languages that the student knows (such as "Java", "C", "C++", etc.) The array language will typically be only partially filled. The int variable numberOfLanguages will keep track of how much of the array is used (and so will also be the number of languages the student knows).

The class CSEStudent will have a full complement of constructors, accessor, and mutator methods. It is up to you to decide how many and of what kind. BUT, you need enough for any reasonable application. Just having enough to do the program for this one assignment is not enough.

Your class CSEStudent will override the definition of the inherited method writeOutput so that it applies in a reasonable way to CSEStudents. You will also add a suitable input method called readInput.

You will not override the method equals; it will apply just as it is inherited from Student. However, you will define a new method called sameLanguages which takes two arguments of type CSEStudent and returns true if they know the exact same languages (and return false otherwise). Note that they may know the same languages even though they are stored in a different orders in the two objects. Also, two strings name the same language provided they are identical when you consider uppercase and lowercase versions of the same letter to be the same.

In a separate file you will write a program that does the following:

1. Ask for two input records of CSEStudents.

2. Echoes the input.

3. Tells if the records are for the same student (using the equals methods).

4. Tells all the languages that are known by the first student but not by the second student, and vice versa. (If they are equal they still might know different languages. Presumably, this means they were the same student at different times.)

5. Tells who knows the most languages.

It should repeat these steps for new records again and again until the user tells the program to end.

The class with this program should have no instance variables and only static methods.

For turing in, you will move the method main (and any other methods in the program class) to the class CSEStudent so that you have only a single file to turnin. After this move, the program should still run.

Sample Output:

Here is sample output of what would be considered a correct solution to this assignment.

Enter first record:
Student Names: Joe Student
Enter student year: 1
Enter languages know by this student:
(One per line. Type the word End when you are finished.)
Java
C
Pascal
End

Enter second record:
Student Names: Sally Student
Enter student year: 2
Enter languages know by this student:
(One per line. Type the word End when you are finished.)
java
C
Ada
Fortran
pascal
End

You entered:
Student one:
Student Names: Joe Student
Student year: 1
Languages know by this student:
Java, C, Pascal

Student two:
Student Names: Sally Student
Student year: 2
Languages know by this student:
Java, C, Ada, Fortran, Pascal

Students are not equal.

Languages know by student one, but not know by student two: None

Languages know by student two, but not know by student one: Ada, Fortran

Student two knows the most languages.

Compare more students? (y/n)

 

Hints and points to remember:

Follow the techniques suggested in the Gotcha sections "Returning an array Instance Variable" in Chapter 6 and the Gotcha: "Privacy Leaks" in Chapter 5. The class Student is skimpy on constructors accessor and mutator methods. You should have significantly more in CSEStudent. Use Student not Undergraduate for this exercise. It makes more sense for what we want here.

It is legal to add methods to the class CSEStudent besides the ones asked for above. However, they should be generally useful methods and not aimed solely at this program. If the method is used solely for the program, it belongs in the program. (As noted below, it will be moved to the class CSEStudent so we cannot check this as long as the method is static.)

You cannot change the definition of the class Student.

You do not turnin the class Student. We will have our own copy of Student to test your program and class definition.