A student has:
- a firstName (String)
- a lastName (String)
- an array of grades (int[])
Write the following methods:
- getter methods for all instance variables
- a method
getAverage()
that returns a floating point average of the values ingrades
. - a
toString()
method that displaysfirst, last
, the student's grade average, then each grade. The format should look something like this:
Jackson, Joe Average: 95.0 Grades: 90 95 100
Instaniate one or more Student objects in Main. Check to see if your methods work.
A teacher has:
- a firstName (String)
- a lastName (String)
- a salary (double)
Write the following methods:
-
getter methods for all instance variables
-
a method
getWeeklySalary
that returns the amount that this teacher should be paid each week (52 week year). -
a
toString()
method that prints a teacher's information in a similar format to this:McTeach, Teachy Salary: $100,000.00*
(note to get the currency formatting you can declare a NumberFormat
object in Techer
as follows)
private final static NumberFormat FORMATTER = NumberFormat.getCurrencyInstance();
Then call on the format()
method of FORMATTER
, which accepts a double and returns a (formatted) String.
Instantiate one or more Teacher objects in Main
. Make sure all of the methods in teacher work correctly.
You likely have noticed that there are some common features between theStudent
and Teacher
classes.
Design a class Person
that incorporates all of the common attributes. Refactor the child classes accordingly.
Thought question: Should the Person
class be abstract? Why or why not?
Confirm that both Student and Teacher objects still work as expected
Make allStudents
static, and declare it outside of any method. This will allow you to reference it any any of the methods that you write.
In main()
, populate allStudents
with a minimum of 4 student objects.
- show all students
- find student by name
- generate honor roll
Before you write the code that makes each menu option work, make the menu itself work:
- The menu must only accept the #s 1 through 3 (inclusive).
- Any other value results in an error message
- An invalid selection results in the user getting the menu prompt again, with another chance to enter a proper value.
The method is called if the user selects option 1. It should iterate through allStudents
and display each using a call to toString()
This method is called if the user selects option 2. It accepts a String, then return the first student whose name contains that String. If the search term is not found,
the method returns null
.
This method is called if the user selects option 3. This method iterates through allStudents
and returns a List
of all Students whose average is above an 85.