我已經能夠創建一個程序來計算每個學生進入的字母等級和平均值,但我很難嘗試創建一個記錄他們都給我的最後一個計數器平均一班。這是我整個計劃中最困難的部分。我不明白如何實施櫃檯,我需要幫助。需要計算和平均finalaverage輸出
import java.util.Scanner;
public class gradebook {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
float discussionweight, hwweight, examweight, discussion, hw, exam, finalaverage;
Scanner scan = new Scanner(System.in);
System.out.print ("Enter the weight of the discussions as an integer: ");
discussionweight = scan.nextFloat();
// Prompts for the weight of the homework grade in an integer
System.out.print ("Enter the weight of the homework as an integer: ");
hwweight = scan.nextFloat();
System.out.print("Enter the weight of the exam as an integer:");
examweight = scan.nextFloat();
int again=-1;
while(again!=0){
System.out.print("Enter the students name: ");
String student = scan.next();
// Prompts for the discussions grade
System.out.print ("Enter the score of the discussion as an integer: ");
discussion = scan.nextFloat();
// Prompts for hw grade
System.out.print ("Enter the hw grade: ");
hw = scan.nextFloat();
System.out.print("Enter the exam grade");
exam = scan.nextFloat();
finalaverage = (((discussionweight * discussion) + (hw * hwweight) + (exam * examweight))/100);
if (finalaverage >= 90)
System.out.println(student +"'s " + "final grade is an A.");
else if (finalaverage >= 80)
System.out.println(student +"'s " + "final grade is a B.");
else if (finalaverage >= 70)
System.out.println(student +"'s " + "final grade is a C.");
else if (finalaverage >= 60)
System.out.println(student +"'s " + "final grade is a D.");
else if (finalaverage >= 10)
System.out.println(student +"'s " + "final grade is an F.");
System.out.println ("The final average is "+ finalaverage);
System.out.print("Would you like to continue? Enter 0 to exit or enter 1 to continue.");
again = scan.nextInt();}
System.out.print("End Gradebook");
float integer;
double sum = 0;
double average = 0;
int count = 0;
// set integer = to the nextInt() while looping so it calculates properly
while ((integer = ((finalaverage)) != 0) {
count ++;
sum += integer;
}
average = sum/count; // calculate the average after the while-loop
System.out.println("Average = " + average);
}
}