Java Question: Could anyone please help me with this homework assignment? Title
ID: 3795040 • Letter: J
Question
Java Question: Could anyone please help me with this homework assignment?
Title Assignment 5 - Grade Calculation Due Feb 23, 2017 5:00 pm Assignment 5 - Grade Calculation This assignment covers: Validating input data Using exceptions with try/catch Using conditionals, if or switch statements, depending on your approach to this problem Also more practice in: Using the required JAVA coding standard for the class. Using the Scanner class to read input from the user Parsing Strings into Numbers Tasks: Make a program that reads one number from the user. The program should calculate a letter grade from this number Use the table below for the number to grade conversion Then it should print out a nice message telling the user the grade. Your program must validate the user's input Use try/catch and if/else statements to do this. It must check to see that the user has entered a number. If the input is not a number, the program should print a message telling the user the error and then exit. It also must check that the number is in the range 0 to 100. If number is not in range , the program should print a message telling the user the error and then exit. The program should not crash at any point no matter what the user enters. I will try to crash it and points will be deducted if I can. Make your program user-friendly. Explain what the program does and guide the user with care, giving lots of instructions and feedback. Label user errors properly and understandably. Be sure to format your output nicely so the computing process and the results are understandable. Example input/output: Please enter a score between 0~100 97 You got an A ------------- Please enter a score between 0~100 50 You got an F ------------- Please enter a score between 0~100 78 You got a C ------------- Please enter a score between 0~100 F You make a mistake, the score that you enter should be a number from 0~100 ------------- Please enter a score between 0~100 200 The score that you entered is larger than 100, it should be a number from 0~100 Number to Grade conversion table Letter grades should be calculated as follows: From 0 to 59 grade is F From 60 to 69 grade is D From 70 to 79 grade is C From 80 to 89 grade is B From 90 to 100 grade is A Workflow: Plan your program Write the code Compile and run it. Repeat 2 & 3 until you are sure it gives correct answers. Code Requirements and Submission The program name should be Grades.java if you use any other name you will get points deducted. Comment your code using Javadoc style Indent your code and leave whitespace to make it human-readable Follow the Google Coding Style Submit your assignment via Laulima no emailed assignments will be accepted. Submit only the .java file. Do not submit the class file. If your program doesn't compile and run in jGrasp you will get NO credit
Explanation / Answer
import java.util.Scanner;
public class Grades {
public static void main(String args[])
{
int score=80,x=1;
boolean error=true;
Scanner sc=new Scanner(System.in);
do{
try
{
System.out.println("Please enter a score between 0~100");
score=sc.nextInt();
switch(x)
{
case (1): if ((score>0)&& (score<60))
{
System.out.print("You got F");
error=false;
break;
}
case (2): if ((score>=60)&& (score<70))
{
System.out.print("Grade is D");
error=false;
break;
}
case (3): if ((score>=70)&& (score<80))
{
System.out.print("Grade is C");
error=false;
break;
}
case (4): if ((score>=80)&& (score<90))
{
System.out.print("Grade is B");
error=false;
break;
}
case (5): if ((score>=90)&& (score<=100))
{
System.out.print("Grade is A");
error=false;
break;
}
default: if((score<0)||(score>100))
{
System.out.println("The score you enter should be a number from 0~100");
error=true;
}
}
}
catch(Exception e)
{
System.out.print("error");
} }
while(error);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.