Question: 1. Create an Array object called roster to store and manage a number of Student objects. 2. Student class consists of name (as a String),

1. Create an Array object called roster to store and manage a number of Student objects. 2. Student class consists of name (as a String), Id (as a String) and score (as an int). 3. Write the appropriate program segments to carry out the following operations:

1. Add a student Given a students name, Id, and score; add the student to the roster

2. Delete a student Given a students Id, delete the student from the roster. A straight forward way of deleting a student is by replacing him by the last student on the roster

3. Display at and above the average students Display the students who have earned a score more than or equal to the average score of the class.

4. Display all the students Display all the students who are on the roster. What Given Student.java

class Student implements Comparable

{

String name;

String Id;

int score;

//----------------------------------------------------------------------------------

// Student constructor

//----------------------------------------------------------------------------------

public Student (String studentName, String studentId, int studentScore){

name = studentName;

Id = studentId;

score = studentScore;

}

public Student (){

name = "";

Id = "";

score = -1;

}

//----------------------------------------------------------------------------------

// Setters for the attributes of a student

//----------------------------------------------------------------------------------

void setName(String studentName){

name = studentName;

}

void setId(String studentId){

Id = studentId;

}

void setScore(int studentScore)

{

score = studentScore;

}

//----------------------------------------------------------------------------------

// Getters for the attributes of a student

//----------------------------------------------------------------------------------

String getName()

{

return name;

}

String getId()

{

return Id;

}

int getScore()

{

return score;

}

//-----------------------------------------------------------------

// Create a one-line description of the student as a string

//-----------------------------------------------------------------

public String toString()

{

String studentInfo = score + "\t\t" + Id + "\t\t" + name ;

return (studentInfo);

}

@Override

public int compareTo(Student aStudent) {

if (this.score < aStudent.score) return -1;

else if

(this.score == aStudent.score) return 0;

else return 1;

}

}

StudentRoster.java

public class StudentRoster {

// Declare the roster of size ARRAY_MAX_SIZE below.

// Get the student information from the keyboard

private static void getStudentInfo(Student theStudent){

}

// Display output heading

private static void displayHeading(){

}

// Display the menu

private static void displayMenu(){

}

// find the student by his id

private static int findStudent(Student[] roster, int firstIndex, int lastIndex, String studentId){

int result;

return (result);

}

// Compute the average score of all the students

private static double average(Student[] roster, int firstIndex, int lastIndex){

double scoreAverage;

return scoreAverage;

}

public static void main(String[] args) {

final int SENTINEL = 9;

int option; // Desired operation

int firstStudentIndex = 0; // Index to the first student on the roster

int lastStudentIndex = -1; // Index to the last student on the roster

int index;

String studentId;

double classAverage;

Student theStudent;

Scanner scan = new Scanner (System.in);

//***********************************************************************

// Display class information

//***********************************************************************

System.out.println(" ----- STUDENT ROSTER ----- ");

System.out.println("***********************************************************************");

System.out.println("By John Doe, CS1301-Section xx, Spring 2017");

System.out.println("*********************************************************************** ");

//***********************************************************************

// Display the menu of options and carry out the respective operations

//***********************************************************************

// Hints:

// Use a while-loop which terminates when the SENTINEL value is entered. Refer to the list of menu options!

// Inside the loop, use switch statement with an appropriate case for each respective menu option.

System.out.println(" Have a nice day! ");

}

}

Expected OutPut

Available operations: 1. Add a student 2. Delete a student 3. Display at and above the average students 4. Display all the students 9. End the program Enter your desired option: 2 Sorry, there are no students to delete! Available operations: 1. Add a student 2. Delete a student 3. Display at and above the average students 4. Display all the students 9. End the program Enter your desired option: 3 Sorry, there are no students to display! Available operations: 1. Add a student 2. Delete a student 3. Display at and above the average students 4. Display all the students 9. End the program Enter your desired option: 4 Sorry, there are no students to display!
Available operations: 1. Add a student 2. Delete a student 3. Display at and above the average students 4. Display all the students 9. End the program Enter your desired option: 5 Option 5 is invalid Available operations: 1. Add a student 2. Delete a student 3. Display at and above the average students 4. Display all the students 9. End the program Enter your desired option: 1 Enter student name: Johz Smith Enter student Id: IdOOl Enter student score: 87 Available operations: 1. Add a student 2. Delete a student 3. Display at and above the average students 4. Display all the students 9. End the program Enter your desired option: 1 Enter student name: Kim Johnson Enter student Id: 1d002 Enter student score: 94 
Available operations: 1. Add a student 2. Delete a student 3. Display at and above the average students 4. Display all the students 9. End the program Enter your desired option: 1 Enter student name: Davz Jones Enter student Id: 11.003 Enter student score: 11 Available operations: 1. Add a student 2. Delete a student 3. Display at and above the average students 4. Display all the students 9. End the program Enter your desired option: 1 Enter student name: Sherz Olson Enter student Id: Z3004 Enter student score: Available operations: 1. Add a student 2. Delete a student 3. Display at and above the average students 4. Display all the students 9. End the program Enter your desired option: 4 The students are: Score Id Name 87 Id00l John Smith 94 Id002 Kim Johnson 75 Id003 David Jones 67 Id004 Sheri Olson
Available operations: 1. Add a student 2. Delete a student 3. Display at and above the average students 4. Display all the students 9. End the program Enter your desired option: 2 Enter the student Id: Id005 The student with Id IdOOS is not found. Available operations: 1. Add a student 2. Delete a student 3. Display at and above the average students 4. Display all the students 9. End the program Enter your desired option: The students with scores at and above the average,80.75, are: Score Id Name 87 Id00l John Smith 94 1d002 Kim Johnson Available operations: 1. Add a student 2. Delete a student 3. Display at and above the average students 4. Display all the students 9. End the program Enter your desired option: 4
The students are: Score Id Name 87 Id00l John Smith 94 Id002 Kim Johnson 75 Id003 David Jones 67 1d004 Sheri Olson

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!