Question: java code needed: Define Student class: Student: name: student name, including first name and last name. scores [ ] : an array with three test

java code needed:
Define Student class:
Student:
name: student name, including first name and last name.
scores[]: an array with three test scores.
Student(): constructor, creates the scores array with 3 elements.
set and get methods for name and scores.
setScore(int index, double score): set the score to the score indexed by index.
double getScore(int index): returns test score indexed by index
double getAverage(): returns the 3 tests average.
Tasks:
a.
Define Student class.
b.
Write a program to test the student class:
1.
Ask user for the number of students: n.
2.
Create a Student array with n students.
3.
Ask user to input user's name (first name and last name) and three test scores.
4.
Use set methods to set user's name and three test scores.
5.
Sort the students by test average from high to low. Display the students information before and after sort.
6.
Sort the students by name in alphabetical order. Display the students information before and after sort.
Sample run:
How many students? 3
Please input student information:
>>> Student 1
Name: Iron Man
Test 1: 96
Test 2: 88
Test 3: 90
>>> Student 2
Name: Captain American
Test 1: 80
Test 2: 85
Test 3: 100
>>> Student 3
Name: Doctor Strange
Test 1: 88
Test 2: 82
Test 3: 98
>>> Sort students by test average:
>>> Before sorting:
Student: Iron Man
Test scores: 90,98,90
Average: 92.67
Student: Captain American
Test Score: 80,85,100
Average: 88.33
Student: Doctor Strange
Test scores: 88,85,96
Average: 89.67
>>> After sorting:
Student: Iron Man
Test scores: 90,98,90
Average: 92.67
Student: Doctor Strange
Test scores: 88,85,96
Average: 89.67
Student: Captain American
Test Score: 80,85,100
Average: 88.33
>>> Sort students by name:
>>> Before sorting:
Student: Iron Man
Test scores: 90,98,90
Average: 92.67
Student: Doctor Strange
Test scores: 88,85,96
Average: 89.67
Student: Captain American
Test Score: 80,85,100
Average: 88.33
>>> After sorting:
Student: Captain American
Test Score: 80,85,100
Average: 88.33
Student: Doctor Strange
Test scores: 88,85,96
Average: 89.67
Student: Iron Man
Test scores: 90,98,90
Average: 92.67

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 Programming Questions!