【发布时间】:2019-10-23 17:38:38
【问题描述】:
这是作业要求的: 我需要创建一个 Java 程序来接受以下两个变量的输入:(a)学生和(b)分数。 我还需要创建一个重复循环,以便程序会询问用户是否需要另一个条目,直到用户指示“否”。 我需要包含一个变量来计算整个班级的平均分数。 我需要创建一个变量,该变量将使用图表(A=.93,A-=.90 B=.87 等)根据学生的分数分配一个字母等级 我必须创建一个变量,该变量将列出获得以下每个等级范围的学生人数:A、B、C、D 和 F。(请注意,“+”和“-”等级属于一般字母等级范围.)
我能够拼凑出部分代码,但无法将它们组合在一起。这是我的第一堂课,没有关于如何进行的真正指导或指导。以下是我正在尝试集成的代码片段。
package gradeproject;
import java.util.Scanner;
import java.util.InputMismatchException;
public class ComputeGradeTryCatch {
public static void main(String[] args) {
// This is the first piece of the code.
int score1;
Scanner s = new Scanner (System.in);
System.out.println("Enter Student Name: ");
String name = s.next();
boolean done = false;
while (!done) {
System.out.println("Enter one test score: ");
try
{
score1 = s.nextInt();
done = true;
}
catch (InputMismatchException e){
System.out.println("Enter a Numeric Value");
}
s.nextLine();
//This is a second piece of the code
Scanner s = new Scanner (System.in);
System.out.println("Enter Student Name: ");
String name = s.next();
System.out.println("Enter three test scores: ");
int score1 = s.nextInt();
int score2 = s.nextInt();
int score3 = s.nextInt();
char letterGrade;
double average = (score1 + score2 +score3)/3;
System.out.println("Name: " + name);
System.out.println("Scores are: " + score1 + "" + score2 + "" + score3);
System.out.println("Average: " + average);
if ((average >=90 && average <=100 ))
letterGrade = 'A';
else if ((average >=80 && average <=90 ))
letterGrade = 'B';
else if ((average >=70 && average <=80 ))
letterGrade = 'C';
else if ((average >=60 && average <=70 ))
letterGrade = 'D';
else letterGrade = 'F';
System.out.println(" Letter Grade is : " + letterGrade);
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\\\\This is the third piece of the code
Scanner scan = new Scanner(System.in);
static String userInput = null;
{
checkPrime();
while (true)
{
System.out.print("Do You Want to Continue (Y/N) ?");
if (userInput.equalsIgnoreCase("Y"))
checkPrime();
else if (userInput.equalsIgnoreCase("N"))
{
System.out.print("Thank you !!");
break;
}
else{
System.out.print("Try Again With (Y/N) only !");
}
\\This has been a rather challenging task. Thank you for your help and support!
There are errors in all of the three parts of the code when I run it. My goal is to put together a clean piece of code that will execute the desire outcome in a concise manner.
【问题讨论】:
标签: java while-loop