Please show me how to code this using Java : Create a program to enter grades an
ID: 3759205 • Letter: P
Question
Please show me how to code this using Java :
Create a program to enter grades and calculate averages and letter grades.
1. Need a class which will contain:
Student Name
Student Id
Student Grades (an array of 3 grades)
A constructor that clears the student data (use -1 for unset grades)
Get functions for items a, b, and c, average, and letter grade
Set functions for items a, n, and c
Note that the get and set functions for Student grades need an argument for the grade index.
2. Need another class which will contain:
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:
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.
5. The system should be able to accept a student with no grades, then later add one or more grades, and when all grades are entered, calculate the final average or grade.
6. The system should also be able to display the students in alphabetical order (no matter what order they are entered 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).
Explanation / Answer
1)
import java.util.Scanner;
import javax.swing.JOptionPane;
import java.text.DecimalFormat;
public class Grade
{//begin class
public static void main(String[] args)
{//Begin main method
//create the variables
String inputString;
double TestScore1,
TestScore2,
TestScore3,
AverageScore;
Scanner keyboard = new Scanner(System.in); //To hold the users grade
DecimalFormat formatter = new DecimalFormat("#,##0.0");
//create keyboard for input
Scanner Keyboard = new Scanner(System.in);
//Ask the user to input TestScore1
inputString=
JOptionPane.showInputDialog(" Please enter Test Score 1");
// Convert the input to a double.
TestScore1 = Double.parseDouble(inputString);
//Ask the user to input TestScore2
inputString=
JOptionPane.showInputDialog(" Please enter Test Score 2");
// Convert the input to a double
TestScore2 = Double.parseDouble(inputString);
//Ask the user to input TestScore3
inputString=
JOptionPane.showInputDialog(" Please enter Test Score 3");
// Convert the input to a double
TestScore3 = Double.parseDouble(inputString);
//Calculate the average score for the tests
AverageScore = ((TestScore1 + TestScore2 + TestScore3)/3);
//Display Average test Score
JOptionPane.showMessageDialog(null, " Your Test Score 1 is : " +formatter.format(TestScore1) +" Grade: " + getLetterGrade(TestScore1)
+ " Your Test Score 2 is : " +formatter.format(TestScore2) +" Grade: " + getLetterGrade(TestScore2)
+ " Your Test Score 3 is : " +formatter.format(TestScore3) +" Grade: " + getLetterGrade(TestScore3)
+ " Your Average Score is : " +formatter.format(AverageScore)+" Grade: " + getLetterGrade(AverageScore));
}//End main method
// Determine the letter grade for the average and 3 test scores
public static char getLetterGrade(double testScore)
{
if(testScore < 60)
return 'F';
else if (testScore >=60 && testScore < 69)
return 'D';
else if (testScore >=70 && testScore < 79)
return 'C';
else if (testScore >=80 && testScore < 89)
return 'B';
else if (testScore >=90)
return 'A';
else
return '0';
}//End Char method
}//End class
You need to create a menu interface that allows you to:
import java.util.Scanner;
public classStudent_Grade {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
Char choice;
String[] subjects = new String[10];
int grades[] = new int[10];
double sum = 0.0;
do
{
System.out.println("A. Enter a course name and a grade");
System.out.println("B. Display all grades");
System.out.println("C. Calculate the average grade");
System.out.println("D. Exit program");
if ( choice == A )
{
Scanner scansubjects = new Scanner(System.in);
Scanner scangrades = new Scanner(System.in);
System.out.println("Enter 10 subjects and their corresponding grades:");
System.out.println();
int i = 0;
for( i = 0; i < 10; i++ )
{
System.out.println("Subject:");
String temp = scansubjects.nextLine();
subjects[i] = temp.toLowerCase();
System.out.println("Grade:");
grades[i] = scangrades.nextInt();
if( i == ( subjects.length - 1 ) )
{
System.out.println("Thank you!");
System.out.println();
}
}
}
if ( choice == B )
{
System.out.println("Subjects" + " Grades");
System.out.println("---------------------");
for(int p = 0; p < subjects.length; p++)
{
System.out.println(subjects[p] + " " + " " + grades[p]);
}
}
if ( choice == C )
{
System.out.println("Total of grades: " + getSum(grades));
System.out.println("Count of grades: " + grades.length);
System.out.println("Average of grades: " + getAverage(grades));
System.out.println();
}
} while ( choice != D);
}
public static double getAverage(int[] array)
{
int sum = 0;
for(int i : array) sum += i;
return ((double) sum)/array.length;
}
public static double getSum(int[] array)
{
int sum = 0;
for (int i : array)
{
sum += i;
}
return sum;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.