Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(JAVA CODING ERROR) import java.util.*; public class Assignment2Q1 { public static void main(String[] args) { String name; String id; String grade; double score; String response

(JAVA CODING ERROR)

import java.util.*;

public class Assignment2Q1 {

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.equalsIgnoreCase("YES"))

{

System.out.println("");

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();

while (!(score >= 0 && score <= 100))

{

System.out.println("");

System.out.print("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 + "! This is a failing grade. Please work harder to pass the course!");

}

a.nextLine();

System.out.println("");

System.out.print("Do you want to exit the program? ");

response = a.nextLine();

}

}

}

Above is my java code. It works completely fine. However, When I try to input 44.5 as my score, the program does not work and an error displays. The Output should look like this:

Please enter your name (Lastname, Firstname seperated by a comma): Quan,Zixi

Please enter your ID without any spaces (7 digits): 1234567

Please enter your score (0-100) 99.5

Based on the grading system, Zixi (1234567) will probably get A! Congratulations!

However, After I put anything with a decimal to my score, the program does not work. I declared the score as a double so why this program is not working?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

(Appendix) Describe the components of the Scott formula.

Answered: 1 week ago

Question

When would you use one approach, and when would you use another?

Answered: 1 week ago