Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I've finished my java project but I don't know how to display the students in alphabetical order, also I want you to check it for

I've finished my java project but I don't know how to display the students in alphabetical order, also I want you to check it for me if everything is correct.image text in transcribed

//class

public class Student 28 { 29 private String name; 30 private int id; 31 private int[] grades = new int[3]; 32 33 public Student(String aName, int aID) 34 { 35 name = aName; 36 id = aID; 37 grades[0] = -1; 38 grades[1] = -1; 39 grades[2] = -1; 40 } 41 //Get functions for Student (Name, Id, and Grades), average, and letter grade 42 43 public String getName() 44 { 45 return name; 46 } 47 48 public int getID() 49 { 50 return id; 51 } 52 53 public int getGrade(int index) 54 { 55 return grades[index]; 56 } 57 58 public int[] getGrades() 59 { 60 return grades; 61 } 62 63 public double getAverage() 64 { 65 return (grades[0] + grades[1] + grades[2]) / 3.0; 66 } 67 68 public char getLetterGrade() 69 { 70 double avgGrd = getAverage(); 71 72 if(avgGrd >= 90) 73 return 'A'; 74 else if(avgGrd >= 80) 75 return 'B'; 76 else if(avgGrd >= 70) 77 return 'C'; 78 else if(avgGrd >= 60) 79 return 'D'; 80 else 81 return 'F'; 82 } 83 //Set functions for items Student (Name, Id, and Grades) 84 85 86 public void setName(String aName) 87 { 88 name = aName; 89 } 90 91 public void setID(int aID) 92 { 93 id = aID; 94 } 95 96 public void setGrade(int index, int grade) 97 { 98 grades[index] = grade; 99 } 100 101 public void setGrades(int[] aGrades) 102 { 103 grades[0] = aGrades[0]; 104 grades[1] = aGrades[1]; 105 grades[2] = aGrades[2]; 106 } 107 }

// demo:

27 import java.util.Scanner; 28 29 public class StudentDemo 30 { 31 public static void main(String[] args) 32 { 33 Scanner input = new Scanner(System.in); 34 //A count of number of students in use 35 36 Student[] students = new Student[20]; 37 int count = 0; 38 char option; 39 String sname; 40 int sid; 41 int grade; 42 int index; 43 44 do 45 { 46 47 //create a menu interface that allows you to: 48 System.out.println("Welcome to Students Program ---------"); 49 System.out.println("~~~~~Here is the MENU of the Program~~~~~"); 50 System.out.println("========================================="); 51 System.out.println("a. Add new student"); 52 System.out.println("b. Enter test grades"); 53 System.out.println("c. Display all students"); 54 System.out.println("d. Exit the program"); 55 System.out.print("Enter your option: "); 56 option = input.next().charAt(0); 57 58 switch(option) 59 { 60 case 'a': // add new student 61 // Prompt the user to enter student's name 62 63 System.out.print(" Enter the name of a student: "); 64 sname = input.next(); 65 66 // Prompt the user to enter student's ID 67 68 System.out.print("Enter the id of the student: "); 69 sid = input.nextInt(); 70 71 students[count] = new Student(sname, sid); 72 count++; 73 break; 74 75 case 'b': // enter test grades 76 if(count == 0) 77 { 78 System.out.println("No students are in the list."); 79 break; 80 } 81 82 System.out.print(" Enter the index of student: "); 83 index = input.nextInt(); 84 85 if(index =0 and Create a program to enter grades and calculate averages and letter grades 1. Need a class which will contain: a. Student Name b. Student Id c. Student Grades (an array of 3 grades) d. A constructor that clears the student data (use -1 for unset grades) e. Get functions for items a, b, and c, average, and letter grade f. Set functions for items a, n, and c g. Note that the get and set functions for Student grades need an argument for the grade index 2. Need another class which will contain: a. b. An Array of Students (1 above) A count of number of students in use 3. You need to create a menu interface that allows you to: a. b. c. d. Add new students Enter test grades Display all the students with their names, ids, test grades, average, and letter grade Exit the program 4. Add comments and use proper indentation I would like that system to accept a student with no grades, then later add one or more grades, and when all * I would like the system to display the students in alphabetical order (no matter what order they are entered Nice Features: grades are entered, calculate the final average or grade in) An example menu might be Enter A to Add Students Enter B to Enter Test Grades Enter C to Display Results Enter D to Exit Program Please select A, B, C, or D For item B, you will need to prompt the user to enter the test number and then enter the value for each student for that test (if there is a previous value, you should display it and if the user enters the empty string, not change the value

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

More Books

Students also viewed these Databases questions

Question

What are the main differences between rigid and flexible pavements?

Answered: 1 week ago

Question

What is the purpose of a retaining wall, and how is it designed?

Answered: 1 week ago

Question

How do you determine the load-bearing capacity of a soil?

Answered: 1 week ago

Question

what is Edward Lemieux effect / Anomeric effect ?

Answered: 1 week ago