使用Java语言写了一个大学英语四级成绩计算器。
在程序中输入写作与翻译的成绩、听力与阅读的做对题数,程序系统自动算分,并将成绩与及格线(425分)比较。
以下为程序代码:
//CET4类:实现成绩的输入与输出
import java.util.Scanner;
public class CET4{
int news; //短篇新闻听力做对题数
int conversation; //对话听力做对题数
int passage; //短文听力做对题数
int choose; //十五选十做对题数
int longreading; //长篇阅读做对题数
int mainreading; //精细阅读做对题数
double writingGrade; //写作成绩
double listeningGrade; //听力成绩
double readingGrade; //阅读成绩
double translationGrade; //翻译成绩
double allGrade; //总成绩
public void setData() //成绩输入模块
{
Scanner setWriting=new Scanner(System.in);
System.out.println("请输入写作成绩:");
writingGrade=setWriting.nextDouble();
Scanner setNews=new Scanner(System.in);
System.out.println("请输入短篇新闻听力做对题数:");
news=setNews.nextInt();
Scanner setConversation=new Scanner(System.in);
System.out.println("请输入对话听力做对题数:");
conversation=setConversation.nextInt();
Scanner setPassage=new Scanner(System.in);
System.out.println("请输入短文听力做对题数:");
passage=setPassage.nextInt();
Scanner setChoose=new Scanner(System.in);
System.out.println("请输入十五选十做对题数:");
choose=setChoose.nextInt();
Scanner setLongReading=new Scanner(System.in);
System.out.println("请输入长篇阅读做对题数:");
longreading=setLongReading.nextInt();
Scanner setMainReading=new Scanner(System.in);
System.out.println("请输入精细阅读作对题数:");
mainreading=setMainReading.nextInt();
Scanner setTranslation=new Scanner(System.in);
System.out.println("请输入翻译得分:");
translationGrade=setTranslation.nextDouble();
}
public void calculate() //成绩计算模块
{
double newsGrade;
newsGrade=news*7.1;
double conversationGrade;
conversationGrade=conversation*7.1;
double passageGrade;
passageGrade=passage*14.2;
double chooseGrade;
chooseGrade=choose*3.55;
double longReadingGrade;
longReadingGrade=longreading*7.1;
double mainReadingGrade;
mainReadingGrade=mainreading*14.2;
listeningGrade=newsGrade+conversationGrade+passageGrade;
readingGrade=chooseGrade+longReadingGrade+mainReadingGrade;
allGrade=writingGrade+listeningGrade+readingGrade+translationGrade;
}
public void display() //成绩显示模块
{
System.out.println("写作成绩:"+String.format("%.2f", writingGrade));
System.out.println("听力成绩:"+String.format("%.2f", listeningGrade));
System.out.println("阅读成绩"+String.format("%.2f", readingGrade));
System.out.println("翻译成绩:"+String.format("%.2f", translationGrade));
System.out.println("四级总成绩:"+String.format("%.2f", allGrade));
}
public void compare() //成绩比较模块
{
if (allGrade>425){
System.out.println("通过四级考试!");
}else{
System.out.println("未通过四级考试!");
}
}
}
//main函数程序:创建CET-4对象
public class GradeSystem {
public static void main(String[] args){
CET4 candidate1 = new CET4();
candidate1.setData();
candidate1.calculate();
candidate1.display();
candidate1.compare();
}
}
|