Java文本答案系统

时间:2015-12-23 03:57:20

标签: java popup window

我是Java的新手,我正在尝试编写“评分”系统。基本上,当代码运行时,会打开一个窗口,它会输出一个问题,输入一个数字值,按回车键,它会加载另一个问题,同样的过程,按回车键,然后重复最后一次。最后它需要这3个数字,数学然后显示一条消息。我有基本代码,我只是遇到了弹出窗口的问题。

public class PopUp {

public static void main(String[] args) {

    // Constant grade worth percentage
    final int examWeight = 55;
    final int hwWeight = 20;
    final int activityWeight = 25;


    // Current grades
    double examGrade = 65.8;
    double hwGrade = 55.3;
    double activityGrade = 29.5;
    double finalGrade;

    // Math to figuring out final grade.
examGrade = examGrade * (examWeight / 100.0);
hwGrade = hwGrade * (hwWeight / 100.0);
activityGrade = activityGrade * (activityWeight / 100.0);
finalGrade = examGrade + activityGrade + hwGrade;

    //round thingy
    double rounded = Math.round(finalGrade *10)/10.0;

// What you made   
if (rounded>=90.0 && rounded<100.0) {
System.out.println("You made an A");
}
if (rounded>=85.0 && rounded<92.9) {
System.out.println("You made a B");
}
if (rounded>=75.0 && rounded<84.9) {
System.out.println("You made a C");
}
if (rounded>=67.0 && rounded<74.9) {
System.out.println("You made a D");
}
if (rounded<=59.9) {
System.out.println("You are a fucking failure");
}
System.out.println("Your final grade is: " + rounded);

}    
}

我需要这些代码在新窗口中显示如下信息:

基本上是这样的:

Question one: 98.8 ENTER
Question two: 76.9 ENTER
Question three: 87.6 ENTER

Result: 93.3 END

在BlueJ中,我试图在Eclipse中复制的结果如下:

    // Ask student to input scores for exam, lab and nomework
    IO.output("Enter your exam grade: ");
    examScore = IO.inputDouble( );
    IO.output("Enter your lab grade: ");
    labScore = IO.inputDouble( );
    IO.output("Enter your homework grade: ");
    hwScore = IO.inputDouble( );
Then the very end would be

    // Output the final grade
    IO.outputln("Your final grade is " + finalGrade); 

http://prntscr.com/9hicp6 - 证明这是一个新窗口。

1 个答案:

答案 0 :(得分:0)

如果您想要弹出窗口,这可能对您有所帮助:

String grade = JOptionsPane.showInputDialog("Enter your grade:");
祝你好运。