计算GPA和学分的java程序

写一个应用程序,将计算的平均GPA。首先,程序应该要求他/她的名字的用户。然后,一次询问一个科目,程序要求的类的名称的,用户学分数,等级可能他/她将获得该类。当用户完成输入他/她的课,该程序将输出学生的名字,所有他/她的类信息,平均全球行动纲领。请打印出的一个很好的形式,类似的reportcard的产出。

输入你的名字
输入学科的名称
输入你的学分
你的成绩
有没有其他的课,是或否

case 'A': point = 4;
case 'B': point = 3;
case 'C': point = 2;
case 'D': point = 1;

acdemicPts学术分数=grade points等级* class credits学分.
Add academicPts to total AcademicsPts.

怎样可以loop?
String grade= JOptionPane.showInputDialog (" Grade you get?");
char score=Character.parseChar(grade);

switch (score) {
case 'A': point = 4;
break;
case 'B': point = 3;
break;
case 'C': point = 2;
break;
case 'D': point = 1;
break;
default: point = 0;
break;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JOptionPane;

//名字;---
//课程名称#1;----
//总共学分:
//成绩:使用ABCDF计算斗让格式;A=4分, B=3.。。
//有没有其他课程#2:Yes/no 名称---
//
//显示:
//
//名字册此:XXX
//课程 学分 成绩
//空姿局计算机课 4 B+
//数学 5 B
//平均点数GPA 3.0

class Course {

private String course;

private String unit;

private String grade;

private String score;

public String getCourse() {
return this.course;
}

public void setCourse(String course) {
this.course = course;
}

public String getUnit() {
return this.unit;
}

public void setUnit(String unit) {
this.unit = unit;
}

public String getGrade() {
return this.grade;
}

public void setGrade(String grade) {
this.grade = grade;
}

public String getScore() {
return this.score;
}

public void setScore(String score) {
this.score = score;
}
}

class GPAInfo {

private String name;

private List courseInfo;

private String gpa;

public String getName() {
return this.name;
}

public void setName(String name) {
this.name = name;
}

public List getCourseInfo() {
return this.courseInfo;
}

public void setCourseInfo(List courseInfo) {
this.courseInfo = courseInfo;
}

public String getGpa() {
return this.gpa;
}

public void setGpa(String gpa) {
this.gpa = gpa;
}
}

public class GPA {
public static void main(String[] args) {

String hasNextStudent = "y";
String hasNextCourse = "y";

List gpaInfolist = new ArrayList();

while((hasNextStudent != null) && "y".equals(hasNextStudent.toLowerCase())) {

GPAInfo gpaInfo = new GPAInfo();
String name = JOptionPane.showInputDialog("enter a name");
gpaInfo.setName(name);

List courselist = new ArrayList();

while ((hasNextCourse != null) && "y".equals(hasNextCourse.toLowerCase())) {

Course course = new Course();
String courseName = JOptionPane.showInputDialog(" What class do you have?");
course.setCourse(courseName);

String unit = JOptionPane.showInputDialog(" Enter the units you get");
course.setUnit(unit);
String grade = JOptionPane.showInputDialog(" Grade you get?");
course.setGrade(grade);
course.setScore(String.valueOf(getScore(grade.toCharArray()[0])));

courselist.add(course);

hasNextCourse = JOptionPane.showInputDialog(" other class? Yes or no");
}// while has next course

hasNextCourse = "y";

gpaInfo.setCourseInfo(courselist);
gpaInfo.setGpa(getGpa(courselist));
gpaInfolist.add(gpaInfo);

hasNextStudent = JOptionPane.showInputDialog(" other student? Yes or no");

}// while has next student

String output = "";
for (GPAInfo gpaInfo : gpaInfolist) {

output += "名字:" + gpaInfo.getName() + "\n";

output += "课程 学分 成绩" + "\n";

List courselist = gpaInfo.getCourseInfo();
for (Course course : courselist) {
output += course.getCourse() + " " + course.getUnit() + " " + course.getScore() + "\n";
}
output += "平均点数GPA " + gpaInfo.getGpa() + "\n\n";
}
JOptionPane.showMessageDialog(null, output);

System.exit(-1);
}

private static String getGpa(List courselist) {
double avg = 0;
int totalScore = 0;
int totalUnit = 0;
for (Course course : courselist) {
totalUnit += Integer.parseInt(course.getScore());
totalScore += Integer.parseInt(course.getUnit()) * Integer.parseInt(course.getScore());

}
if (totalUnit != 0) {
avg = totalScore / totalUnit;
}
if (avg > 4) {
avg = 4;
}
return String.valueOf(avg);
}

private static int getScore(char score) {
int point;
score = Character.toUpperCase(score);
switch (score) {
case 'A':
point = 4;
break;
case 'B':
point = 3;
break;
case 'C':
point = 2;
break;
case 'D':
point = 1;
break;
default:
point = 0;
break;
}
return point;
}
}
计算GPA和学分的java程序
← 上一篇: 下一篇: →