Question: Student Write a fully-documented class named Student which contains the name of the student (String), and how much lunch money the student has brought (double).

Student

Write a fully-documented class named Student which contains the name of the student (String), and how much lunch money the student has brought (double). You should provide getter and setter methods for all member variables. In addition, you should provide a constructor as detailed below, though you may create a custom constructor which takes any arguments you see fit. You should also provide clone() and equals() methods for the Student class. Lastly, you should provide a toString() method that returns a printable representation of the Student and its data members (name, specialInstruction, price).

private String name

private double money

public Student(String name, double money)

Default constructor.

Postconditions:

This object has been initialized to an Student object with specified name and price).

public boolean equals(Object obj)

Compare this Student to another object for equality.

Returns a value of true if the obj refers to a Student object with the same properties as this Student. Otherwise, returns a value of false.

StudentLine

Write a fully-documented class named StudentLine which implements an ArrayLst-like data structure based on the final int CAPACITY. The StudentList should contain a list of all the students on the line. It may not contain "holes" in the array (there should not be a non-null array element with a higher index than any null element in the array). The only exception to this is if you choose to always maintain array index 0 as null and have the array of size CAPACITY+1 so that the first student is stored internally as index 1 (otherwise, when you print to the user, you will have to add one to the student index, and subtract 1 from user input to get true index).

private Student [] students

private int studentCount

final int CAPACITY

public StudentLine()

Default constructor which initializes this object to an empty list of Students.

Postconditions:

The array students has been initialized, and studentCount has been set to 0

public int numStudents()

Returns the total number of Students in the list.

This method should run in O(1) time.

public Student getStudent(int index)

Gets the reference to the Student at the given index

Throws an ArrayIndexOutOfBoundsException if the index is invalid

The list should be unchanged

public Student removeStudent(int index)

Gets the reference to the Student at the given index

Throws an ArrayIndexOutOfBoundsException if the index is invalid

Throws an EmptyLineException (you must write this, an empty class extending Exception is the best way to do this) if there is no student on the line.

Removes the given student and moves all students behind this student forward by one index

public Student addStudent(int index, Student student)

Adds a student at the given index, moving all other students behind the current student back one index.

Throws an InvalidArgumentException (custom class) or Illegal Argument Exception if the index is too high and would create a hole in the array

Throws a DeanException (you must write this, just make an empty class that extends Exception) if the array is full.

public void swapStudents(int index1, int index2)

If the indices are valid, the two students are swapped.

Throws an ArrayIndexOutOfBoundsException if either index is invalid

The list should be unchanged if either index was invalid

public StudentLine clone()

Creates a deep copy of this StudentLine object

If the copy is modified, this object should remain unmodified.

All the students inside should be deep copied as well.

public boolean equals(Object o)

Checks if this student line is equal to another object

The other object must be of type StudentLine, and contain students with the same names in the same order with the same balances for this method to return true.

public String toString()

You must write a toString() method. You can use this method to help you with printing the StudentList for the output.

LunchLineSimulator

Write a fully-documented class named LunchLineSimulator which creates two instances of the StudentLine object and provides an interface for a user to manipulate the list. Please see the UI required functions for the required functionality

public static void main(String[] args)

The main method runs a menu driven application which first creates two empty StudentLines and then prompts the user for a menu command selecting the operation. The required information is then requested from the user based on the selected operation. You can find the list of menu options in the UI required functions section.

private static StudentLine realityA

private static StudentLine realityB

DeanException

An Exception class which indicates that the user attempted to fill a full array should be created.

Note on Exceptions: all exceptions should be handled gracefully - they should be caught in the main, and the user should be notified by a nice printout (ie: "You tried to add a student to a full lunch line. Dean Mean has picked up the student and given them a healthy dose of detention. Therefore, they will not be added to the lunch line." or "There are no students to serve lunch to. Mystery Meat Martha is sad." or "That is an invalid index."). Your messages will not be graded for creativity, but they should clearly indicate what the problem is (bad index, full list, negative number, etc.). The program should continue to run normally after an exception is encountered. We will not be checking Input Mismatch cases.

UI Required Functions

A - Add Student

Name

Money amount

C - Cut Friend

Name

Money amount

Index of friend to cut

B - Bully

Index of kid to bully

U - update lunch money amount

Index of kid to update

P - Print lunch line in current reality

Also state if it's reality A - or reality B

S - Serve student

O - Other reality (switch realities)

T - Trade places with friend

Index of friend 1

Index of friend 2

E - check if the two realities are equal

D - Duplicate realities (copy this reality into the other reality, overwriting what is there)

Q - Quit

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!