【发布时间】:2015-01-19 01:52:42
【问题描述】:
我们正在编写一个名为 GradeBook 的程序,它允许用户输入学生数据,例如姓名和不同年级项目的分数。 GradeBook 为每个学生提供选项计算成绩并绘制班级成绩分布。用户可以随时返回并添加更多学生数据。它支持的最大学生数为 200,一个类别中的最大成绩项目数为 10。例如,它仅支持最多 10 个测验、10 个考试和 10 个家庭作业。
数据输入示例如下:
乔·W·史密斯:e100 e95 e87 q10 q10 q8 h10 h10 h10
迈克尔·布朗:q10 q10 h7 h10 h9 h10 e80
要显示学生的成绩和统计数据,我们应该使用 System.out.printf。
这是最终输出的另一个示例。
Name Exam Exam Exam Quiz Quiz Quiz HWork HWork HWork Grade
Danny Devito 100.0 80.0 90.0 10.0 10.0 0.0 10.0 5.0 10.0 84.0
Joe Smith 85.0 90.0 100.0 10.0 10.0 5.0 0.0 10.0 5.0 81.7
Will Smith 60.0 100.0 90.0 10.0 10.0 8.0 10.0 0.0 10.0 82.0
这个最后的例子应该排列得更好,并用小数对齐,所以它看起来整洁干净,但我不确定如何做到这一点。
import java.util.Scanner;
公共类 GradeCalcWithArrays { /* * Logan Wegner 目的是计算 * 输入成绩 */ public static void main(String[] args) {
Scanner s = new Scanner(System.in);
boolean done = false;
boolean quit = false;
int choice = 0;
int studentcounter = 0;
int[] examstats = new int[3]; /*
* Array created to store the information
* entered for exams
*/
int[] quizstats = new int[3]; /*
* Array created to store the information
* entered for quizzes
*/
int[] homeworkstats = new int[3]; /*
* Array created to store the
* information entered for homework
*/
String[] studentnames = new String[200]; /*
* Array created to store the
* student name information
* entered
*/
System.out.println("Welcome to GradeBook!");
System.out.println("Please provide grade item details");
System.out.print("Exams (number, points, weight):");
examstats[0] = s.nextInt(); // inputs exam number
examstats[1] = s.nextInt(); // inputs exam points
examstats[2] = s.nextInt(); // inputs exam weight
System.out.print("Quizzes (number, points, weight):");
quizstats[0] = s.nextInt(); // inputs quiz number
quizstats[1] = s.nextInt(); // inputs quiz points
quizstats[2] = s.nextInt(); // inputs quiz weight
System.out.print("Homework (number, points, weight):");
homeworkstats[0] = s.nextInt(); // inputs homework number
homeworkstats[1] = s.nextInt(); // inputs homework points
homeworkstats[2] = s.nextInt(); // inputs homework weight
System.out.println("--------------------");
do {
System.out.println("What would you like to do?");
System.out.println(" 1 Add student data");
System.out.println(" 2 Display student grades & statistics");
System.out.println(" 3 Plot grade distribution");
System.out.println(" 4 Quit");
System.out.print("Your choice:");
choice = s.nextInt(); /*
* Choice will determine what the next course of
* action will be with the program
*/
if (choice == 1) {
System.out.println("Enter student data:");
for (int i = 0; i <= 200; i++) {
studentcounter = studentcounter + 1;
System.out.print("Data>");
studentnames[i] = s.nextLine();
if (studentnames[i].equals("done")) {
break;
}
}
}
if (choice == 2) {
}
if (choice == 3) {
}
if (choice == 4) {
quit = true;
System.out.println("Good bye!");
}
} while (quit == false);
}
}
我坚持的最大部分是能够输入数据并将其放入字符串和数组中。我不确定如何获取使用 e100 q100 h100 输入的数据,因为它们可能会混淆和乱序。我真的非常感谢一些帮助。在此先感谢各位。
【问题讨论】: