Question 1: Write a program that calculates the grade averages of 10 students, e
ID: 652813 • Letter: Q
Question
Question 1: Write a program that calculates the grade averages of 10 students, each with 50 assignments. Create a struct to represent each student, containing an ID number (can be incremental starting from 0), an age (random number between 18 and 25), and 50 assignments (each with a random value between 50 and 100). Your program should be able to set the information for each of the students and output each in the following format:
Example output:
Student: 0, Age: 18, Grade: 89.3
Student: 1, Age: 23, Grade: 63.8
Explanation / Answer
Answer 1:
import java.util.Scanner;
public class CaseGrade {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
int ID;
int grade;
String exellent = "Exellent :";
String veryGgood ="Very Good :";
String good="Good :";
String pass ="Pass :";
String fail = "Fail :";
int max = 0;
int min = 100;
int sum = 0;
int avg ;
int age;
int counter =0;
boolean repeat ;
while (repeat =true)
{
System.out.println("enter student id : ");
int n = input.next();
System.out.println("Enter Grade : ");
grade = input.nextInt();
System.out.println("Enter age : ");
grade = input.next();
if (grade == -1 )
{
avg = sum / counter;
System.out.println(" result = :");
System.out.println(exellent +" "+ veryGgood +" "+ good +" "+ pass +" "+fail);
System.out.println("maximum = "+ max +" ");
System.out.println("minimum = "+ min +" ");
System.out.println(" Average = " +avg);
System.exit(0);
}
switch (grade/10)
{
case 100:
case 9 :
exellent += " "+ ID + " " +grade+" ";
break;
case 8 :
veryGgood += " " + ID + " " +grade +" ";
break ;
case 7 :
good += " " + ID + " " +grade +" ";
break;
case 6:
case 5:
pass += " " + ID + " " +grade +" ";
break;
default:
fail +=" " + ID + " " +grade +" ";
break;
}
sum = sum + grade;
counter = counter + 1;
if (grade > max)
{
max = grade;
}
if (grade < min)
{
min = grade;
}
}
}
}
Answer 2:
public void readInput ()
{
Scanner keyboard = new Scanner (System.in);
System.out.println ("Enter name of item you are purchasing:");
name = keyboard.nextLine ();
System.out.println ("Enter price of item as two numbers.");
System.out.println ("For example, 3 for $2.99 is entered as");
System.out.println ("3 2.99");
System.out.println ("Enter price of item as two numbers, now:");
groupCount = keyboard.nextInt ();
groupPrice = keyboard.nextDouble ();
System.out.println ("Would like to have another entry?");
decision = keyboard.value();
public void readmultipleinput ()
{
do while(decision
{
readinput()}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.