1.Write a class called Student.
Data members: name: String; age: int; major: String.
constructor with 3 arguments that initializes all data members;
print(): prints all data to stdout in one line, align the printed
items in colums, no newline at the end;
println(): same as print() but with newline at the end;
2.Write a class called Group that implements a container of
Data members: capacity: int; s: array of Students;
int currentNumber: current number of students
constructor with one int argument that sets the capacity,
(that is: how many students it can contain), creates the array.
add(Student s): if Group full returns false, otherwise adds
the Student s to the Group and returns true;
remove(String name): searches for the student with the specified
name, if found, removes it from the Group. It returns nothing;
implement these as explained in class.
print(): prints a header line as shown below:
==== Group: x students ====
where x is the number of students currently in the Group, then
below the header line it prints each student's data, one student
The main() method creates a Group object of capacity 15. Then
goes into a loop in which it reads data from the file "students".
Each line in this file contains either the word "student"
followed by the data for one student, or the word "print" or
the word "remove" followed by the name of a student.
If the word is "student", main() reads the data, constructs the
student and tries to add him/her to the group. If this succeeds,
it prints "added" followed by the name of the student; otherwise
it prints "capacity" # "reached, student "name" not added";
(# is the capacity of the Group)
if the word is "print", it prints the whole group;
if the word is "remove", it tries to remove the specified student
from the Group, if this succeeds it prints "removed" followed by
the name of the student, otherwise it prints "student not
The loop stops when it runs into end of file.
Read using the Scanner class.
Exceptions: you don't need to catch the exceptions that are thrown
by either FileReader(), readLine(), or parse(), just put the clause
"throws Exception" after main(). We will do more exception handling
later in class.
3.Write a class Main in which you put the main function. Put all
classes in one file. Make all data members private, make all
methods package visibility. If one class needs to access data
members of another class, provide access methods in the other