Question: (JAVA CODNG ) The question is below the code: import java.util.*; public class Homework{ public static void main(String[] args) { String name; String id; String
(JAVA CODNG )
The question is below the code:
import java.util.*;
public class Homework{
public static void main(String[] args)
{
String name;
String id;
String grade;
double score;
String response;
Scanner a = new Scanner(System.in);
System.out.println("++++++++++++++++++++++++++++++++++");
System.out.println("Welcome to Grading System Program!");
System.out.println("++++++++++++++++++++++++++++++++++");
System.out.println("");
while(response == "YES")
{
System.out.print("Please enter your name (Lastname, Firstname seperated by a comma): ");
name=a.nextLine();
while( !(name.length() >1 &&name.contains((","))==true))
{
System.out.println("");
System.out.print("Please enter your name (Lastname, Firstname seperated by a comma): ");
name=a.nextLine();
}
String nameArr[]=name.split(",");
name=nameArr[1] + " " + nameArr[0];
System.out.println("");
System.out.print("Please enter your ID without any spaces (7 digits): ");
id=a.nextLine();
while(!(id.length()==7))
{
System.out.println("");
System.out.print("Please enter your ID without any spaces (7 digits): ");
id=a.nextLine();
}
System.out.println("");
System.out.print("Please enter your score (0-100) ");
score=a.nextInt();
if(!(score>=0 && score <=100))
{
System.out.println("");
System.out.println("Please enter your score (0-100): ");
score=a.nextInt();
}
System.out.println("");
System.out.println(name +" got "+ score +"!");
if(score >= 80)
{
grade="A";
System.out.println("");
System.out.println("Based on the grading system, " + nameArr[1]+"("+id+") will probably get "+grade+"! Congratulations!");
}
else if(score>=70)
{
grade="B";
System.out.println("");
System.out.println("Based on the grading system, " + nameArr[1]+"("+id+") will probably get "+grade+"! Keep up the good work!");
}
else if(score>=60)
{
grade="C";
System.out.println("");
System.out.println("Based on the grading system, " + nameArr[1]+"("+id+") will probably get "+grade+"! You can do a lot better!");
}
else
{
grade="FNS";
System.out.println("");
System.out.print("Based on the grading system, " + nameArr[1]+"("+id+") will probably get "+grade+"! Please work harder to pass the course!");
}
}
System.out.println("Want to Exit?");
response=a.nextLine();
}
}
Above is the final code, but it has an error. I want to put a response into my output as: Do you want to exit the program? (put YES to terminate).
If the user puts anything other than YES, the code should re-start from "please enter your name".
I have tried doing it with "while" but it gave an error.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
