Rewrite Grade Program below using arrays: package chapter6; //import java.lang.C
ID: 647243 • Letter: R
Question
Rewrite Grade Program below using arrays:
package chapter6;
//import java.lang.Character;
import java.text.DecimalFormat;
import java.util.Scanner;
//import java.io.*;
public class studentgradeFinal
{
public static final double TEST_RATE = 0.20;
public static final double LAB_RATE = 0.15;
public static final double FINAL_RATE = 0.30;
public static final int STUDENT_NUMBER = 2;
// public static double test1, test2, lab, quiz;
// public static double final_grade, score, gradePoints;
// public static String name, grade;
// public static Scanner keyboard = new Scanner(System.in);
public static void main(String[] args) {
double final_grade=0, score, gradePoints=0, test1=0, test2=0, lab=0, quiz=0;
String name="", grade="";
for (int i=0;i<STUDENT_NUMBER;i++)
{
getdata(name, test1,test2,lab, quiz,final_grade); // read data from keyboard
score = getTotal(test1,test2,lab,quiz,final_grade); // find total score of the student
findGrade(score,gradePoints,grade); // find letter grade and gradepoints average
display(name,test1,test2,lab, quiz, final_grade,score, grade, gradePoints); // display students information
}
} // end of main
public static void getdata(String name, double test1, double test2, double lab, double quiz, double final_grade)
{
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter name of the student: ");
name = keyboard.nextLine();
System.out.print("Enter score of test one: ");
test1 = keyboard.nextDouble();?
System.out.print("Enter score of test two: ");
test2 = keyboard.nextDouble();
System.out.print("Enter score of Lab: ");
lab = keyboard.nextDouble();
System.out.print("Enter score of Quiz: ");
quiz = keyboard.nextDouble();
System.out.print("Enter score of Final test: ");
final_grade = keyboard.nextDouble();
keyboard.nextLine(); // flushes the new line character from bugger
}
public static double getTotal(double test1, double test2, double lab, double quiz, double final_grade)
{
// Calculate total score for the student
double score = (test1 + test2)*TEST_RATE + (lab + quiz)*LAB_RATE + final_grade*FINAL_RATE;
return score;
}
public static void findGrade(double score, double gradePoints, String grade)
{
int total = (int)Math.round(score);
// Compute Letter Grade using If-else-if statements
if (total >= 98)
{
grade = " A+ ";
gradePoints = 4.0;
}
else if (total >= 93)
{
grade = " A ";
gradePoints = 4.0;
}
else if (total>=90)
{
grade = " A- ";
gradePoints = 3.67;
}
else if (total>=87)
{
grade = " B+ ";
gradePoints = 3.33;
}
else if (total>=83)
{
grade = " B ";
gradePoints = 3.0;
}
else if (total>=80)
{
grade = " B- ";
gradePoints = 2.67;
}
else if (total>=77)
{
grade = " C+ ";
gradePoints = 2.33;
}
else if (total>=70)
{
grade = " C ";
gradePoints = 2.0;
}
else if (total>=60)
{
grade = " D ";
gradePoints = 1.0;
}
else
{
grade = " F ";
gradePoints = 0.0;
}
}
public static void display(String name, double test1,double test2,double lab, double quiz, double final_grade,
double score, String grade, double gradePoints)
{
DecimalFormat df = new DecimalFormat("##.##");
System.out.println(name+ ".... Here is your percentile grade :");
System.out.println("The scores you have entered ==> Test1:"+df.format(test1) +" Test2:"+df.format(test2)
?? +" Lab:"+df.format(lab)+" Quiz:"+df.format(quiz)+" Final:"+df.format(final_grade) );
System.out.println("Your Grade is : "+df.format(score)+" Letter Grade is "+ grade
+" Grade Points is "+ gradePoints );
}
}
Explanation / Answer
inspite of using for loop for variouse element directlydeclare the array with its value.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.