Tasks Create a new Project (Lab5). 1) Task: Practice with if statements (8 pts)
ID: 3586365 • Letter: T
Question
Tasks Create a new Project (Lab5). 1) Task: Practice with if statements (8 pts) a) Create a new package "task1" and a new class in that package "GradeMaker". Add the empty "main" method in your class o main: In the "main" method, create a Scanner object to read user keyboard input. Prompt the user to enter a grade value between 0.0 and 100.0 If the grade entered is NOT between 0.0 and 100.0 print an error message and return from "main" -just use return; Call a method called "calcGrade" (we'll write that method shortly) and pass the score the user entered as the parameter. This method should return a string so be sure to save the returned value. Print the returned value as follows (showing an example grade value): Grade: A o calcGrade Create a method "calcGrade" that accepts one parameter a score value. Create a string variable to hold the letter grade, leave it unassigned for now. Create an it/else if...else statement to support the following letter grade scheme 90.0-100.0 A 80.0-90.0 (do not include the end-point value here) B .70.0-80.0 (do not include the end-point value here) C 60.0 70.0 (do not include the end-point value here)D Otherwise, the grade is F. Return the letter grade from your function.Explanation / Answer
//Code:-
package task1;
import java.util.*;
class GradeMaker
{
public static String calcGrade(float score)
{
String Grade="";
if(score>=90.0 && score<100.0)
{
Grade = "A";
}
else if(score>=80.0 && score<90.0)
{
Grade = "B";
}
else if(score>=70.0 && score<80.0)
{
Grade = "C";
}
else if(score>=60.0 && score<70.0)
{
Grade = "D";
}
else
{
Grade = "F";
}
return Grade;
}
public static void main(String []args)
{
Scanner scan = new Scanner(System.in);
System.out.println("Enter Score between 0.0 and 100.0");
float score =scan.nextFloat();
if(score<0.0 || score>100.0)
{
return;
}
else
{
String Grade = calcGrade(score);
System.out.println("Grade: "+Grade);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.