要求:输入单科成绩,得到该成绩的成绩绩点;课程学分; 课程分数绩点;课程分数等级。
思路如下:
package com.itbaizhan;
import java.util.*;//调用Scanner
import java.math.BigDecimal;//调用小数点,也不知是否有用
public class TestMethod6803 {
/**
* 设计某科成绩的绩点,学分绩点和等级和学分
* 1.某科成绩的绩点//double grade,使用if else 多分支句法
* 分数: scores 绩点:grade 分数等级:level 课程学分:(默认每门学分是3分)
* (1)成绩90分-100分, 4.0 A 3
* (2).86分-89分, 3.7 A 3
* (3)83分-85分, 3.3 B 3
* (4)80分-82分, 3.0 B 3
* (5)76分-79分, 2.7 B 3
* (6)73分-75分, 2.3 C 3
* (7)70分-72分, 2.0 C 3
* (8)66分-69分, 1.7 C 3
* (9)63分-65分, 1.3 C 3
* (10)60分-62分, 1.0 C 3
* (11)小于60分, 0.0 D 0
* 4.输出每门成绩绩点:grade;课程学分:3;课程分数绩点:Math.round((grade*3)*10)/10.0;课程分数等级:level; 用"\t"来做空格
* 5.@return,软件自己帮return 了,我也不知道应该在哪里输入才对
*/
public static void scoreG(int scores) {
double grade = 0.0;
Scanner s = new Scanner(System.in);
System.out.println("单科成绩绩点GPA计算器:");
while (true) {
System.out.println("请输入您的成绩");
scores = s.nextInt();//百分值成绩
if (89 < scores & scores <= 100) {
grade = 4.0;//成绩绩点
System.out.print("成绩绩点GPA:" + grade + ",课程学分绩点:" + (Math.round((grade*3)*10)/10.0) +"\t");//(Math.round((xx)*10)/10.0)这是为了保留小数点后面一位数
System.out.println("课程学分:3.0");
System.out.println("level:A");
} else if (85 < scores & scores <= 89) {
grade = 3.7;
System.out.print("成绩绩点GPA:" + grade + ",课程学分绩点:" + (Math.round((grade*3)*10)/10.0) +"\t");
System.out.println("课程学分:3.0");
System.out.println("level:A");
} else if (82 < scores & scores <= 85) {
grade = 3.3;
System.out.print("成绩绩点GPA:" + grade + ",课程学分绩点:" + (Math.round((grade*3)*10)/10.0) +"\t");
System.out.println("课程学分:3.0");
System.out.println("level:B");
} else if (79 < scores & scores <= 82) {
grade = 3.0;
System.out.print("成绩绩点GPA:" + grade + ",课程学分绩点:" + (Math.round((grade*3)*10)/10.0) +"\t");
System.out.println("课程学分:3.0");
System.out.println("level:B");
} else if (75 < scores & scores <= 79) {
grade = 2.7;
System.out.print("成绩绩点GPA:" + grade + ",课程学分绩点:" + (Math.round((grade*3)*10)/10.0) +"\t");
System.out.println("课程学分:3.0");
System.out.println("level:B");
} else if (72 < scores & scores <= 75) {
grade = 2.3;
System.out.print("成绩绩点GPA:" + grade + ",课程学分绩点:" + (Math.round((grade*3)*10)/10.0) +"\t");
System.out.println("课程学分:3.0");
System.out.println("level:C");
} else if (69 < scores & scores <= 72) {
grade = 2.0;
System.out.print("成绩绩点GPA:" + grade + ",课程学分绩点:" + (Math.round((grade*3)*10)/10.0) +"\t");
System.out.println("课程学分:3.0");
System.out.println("level:C");
} else if (65 < scores & scores <= 69) {
grade = 1.7;
System.out.print("成绩绩点GPA:" + grade + ",课程学分绩点:" + (Math.round((grade*3)*10)/10.0) +"\t");
System.out.println("课程学分:3.0");
System.out.println("level:C");
} else if (62 < scores & scores <= 65) {
grade = 1.3;
System.out.print("成绩绩点GPA:" + grade + ",课程学分绩点:" + (Math.round((grade*3)*10)/10.0) +"\t");
System.out.println("课程学分:3.0");
System.out.println("level:C");
} else if (59 < scores & scores <= 62) {
grade = 1.0;
System.out.print("成绩绩点GPA:" + grade + ",课程学分绩点:" + (Math.round((grade*3)*10)/10.0) +"\t");
System.out.println("课程学分:3.0");
System.out.println("level:C");
} else {
System.out.print("成绩绩点GPA:0.0");
System.out.println("课程学分绩点:0.0");
System.out.println("课程学分:0.0");
System.out.println("level:D");
}
System.out.println("请输入命令(exit);");
s.nextLine();//先运行一下,可以解决下面nextLine()键盘输入跳过不让输入的问题
String command=s.nextLine();
System.out.println(command+"======");
if("exit".equals(command)) {
System.out.println("退出软件");
break;
}
}
}
public static void main(String[] args) {
scoreG(90);//运行起来后,用键盘输入单科成绩分数即可
}
}
非固定课程分数,需要手动输入的Java设计,有些课程的分数不同(有1分/2分/3分)
package com.itbaizhan;
import java.util.*;//调用Scanner
public class TestMethod8604 {
/**
* 设计某科成绩的绩点,学分绩点和等级和学分
* 1.某科成绩的绩点//double grade,使用if else 多分支句法
* 分数: scores 绩点:grade 分数等级:level 课程学分(因课程的等级不同需要键盘输入:1/2/3)
* (1)成绩90分-100分, 4.0 A (因课程的等级不同需要键盘输入:1/2/3)
* (2).86分-89分, 3.7 A (因课程的等级不同需要键盘输入:1/2/3)
* (3)83分-85分, 3.3 B (因课程的等级不同需要键盘输入:1/2/3)
* (4)80分-82分, 3.0 B (因课程的等级不同需要键盘输入:1/2/3)
* (5)76分-79分, 2.7 B (因课程的等级不同需要键盘输入:1/2/3)
* (6)73分-75分, 2.3 C (因课程的等级不同需要键盘输入:1/2/3)
* (7)70分-72分, 2.0 C (因课程的等级不同需要键盘输入:1/2/3)
* (8)66分-69分, 1.7 C (因课程的等级不同需要键盘输入:1/2/3)
* (9)63分-65分, 1.3 C (因课程的等级不同需要键盘输入:1/2/3)
* (10)60分-62分, 1.0 C (因课程的等级不同需要键盘输入:1/2/3)
* (11)小于60分, 0.0 D 0(不及格)
* 4.输出每门成绩绩点:gpa;课程学分:3;课程分数绩点;课程分数等级:level; 用"\t"来做空格
* 5.@return,这次成功定义了
*/
public static double scoreGpa(int scores, int courseS) {
double gpa = 0;
Scanner s = new Scanner(System.in);
System.out.println("单科成绩GPA计算器:");
while (true) {
System.out.println("请输入你的成绩");
scores = s.nextInt();//百分值成绩
System.out.println("请输入你的课程学分");
courseS = s.nextInt();//课程学分有1,2,3,三种,手动输入
if (89 < scores & scores <= 100) {
gpa = 4.0;//成绩绩点
double courseP = Math.round((gpa * courseS ) * 10) / 10.0;//courseP 就是课程学分绩点
System.out.print("成绩绩点GPA:" + gpa + ",课程学分绩点:" + courseP + "\t");
System.out.println("level:A");
} else if (85 < scores & scores <= 89) {
gpa = 3.7;
double courseP = Math.round((gpa * courseS ) * 10) / 10.0;//courseP 就是课程学分绩点
System.out.print("成绩绩点GPA:" + gpa + ",课程学分绩点:" + courseP + "\t");
System.out.println("level:A");
} else if (82 < scores & scores <= 85) {
gpa = 3.3;
double courseP = Math.round((gpa * courseS ) * 10) / 10.0;//courseP 就是课程学分绩点
System.out.print("成绩绩点GPA:" + gpa + ",课程学分绩点:" + courseP + "\t");
System.out.println("level:B");
} else if (79 < scores & scores <= 82) {
gpa = 3.0;
double courseP = Math.round((gpa * courseS ) * 10) / 10.0;//courseP 就是课程学分绩点
System.out.print("成绩绩点GPA:" + gpa + ",课程学分绩点:" + courseP + "\t");
System.out.println("level:B");
} else if (75 < scores & scores <= 79) {
gpa = 2.7;
double courseP = Math.round((gpa * courseS ) * 10) / 10.0;//courseP 就是课程学分绩点
System.out.print("成绩绩点GPA:" + gpa + ",课程学分绩点:" + courseP + "\t");
System.out.println("level:B");
} else if (72 < scores & scores <= 75) {
gpa = 2.3;
double courseP = Math.round((gpa * courseS ) * 10) / 10.0;//courseP 就是课程学分绩点
System.out.print("成绩绩点GPA:" + gpa + ",课程学分绩点:" + courseP + "\t");
System.out.println("level:C");
} else if (69 < scores & scores <= 72) {
gpa = 2.0;
double courseP = Math.round((gpa * courseS ) * 10) / 10.0;//courseP 就是课程学分绩点
System.out.print("成绩绩点GPA:" + gpa + ",课程学分绩点:" + courseP + "\t");
System.out.println("level:C");
} else if (65 < scores & scores <= 69) {
gpa = 1.7;
double courseP = Math.round((gpa * courseS ) * 10) / 10.0;//courseP 就是课程学分绩点
System.out.print("成绩绩点GPA:" + gpa + ",课程学分绩点:" + courseP + "\t");
System.out.println("level:C");
} else if (62 < scores & scores <= 65) {
gpa = 1.3;
double courseP = Math.round((gpa * courseS ) * 10) / 10.0;//courseP 就是课程学分绩点
System.out.print("成绩绩点GPA:" + gpa + ",课程学分绩点:" + courseP + "\t");
System.out.println("level:C");
} else if (59 < scores & scores <= 62) {
gpa = 1.0;
double courseP = Math.round((gpa * courseS ) * 10) / 10.0;//courseP 就是课程学分绩点
System.out.print("成绩绩点GPA:" + gpa + ",课程学分绩点:" + courseP + "\t");
System.out.println("level:C");
} else {
System.out.print("成绩绩点GPA:0.0");
System.out.println("课程学分绩点:0.0");
System.out.println("level:D");
}
System.out.println("请输入命令(exit);");
s.nextLine();//先运行一下,可以解决下面nextLine()键盘输入跳过不让输入的问题
String command = s.nextLine();
System.out.println(command + "======");
if ("exit".equals(command)) {
System.out.println("退出软件");
break;
}
}
return gpa;
}
public static void main(String[] args) {
scoreGpa(90,2);
}
}