package snippetweek10; import java.util.Scanner; public class SnippetWeek10 { pu
ID: 3938761 • Letter: P
Question
package snippetweek10;
import java.util.Scanner;
public class SnippetWeek10
{
public static void main(String[] args)
{
//#3: Loop to ask user to enter a numeric grade and -1 to exit.
} // main() method.
//#2: TestVoidMethod.
public static void printGrade(double score) {
if (score >= 90.0) {
System.out.println('A');
}
else if (score >= 80.0) {
System.out.println('B');
}
else if (score >= 70.0) {
System.out.println('C');
}
else if (score >= 60.0) {
System.out.println('D');
}
else {
System.out.println('F');
}
}
}
//#4: Modify the printGrade() method to calculate B-, C-, and D- letter grades.
//SnippetWeek10 Class.
Explanation / Answer
package snippetweek10;
import java.util.Scanner;
public class SnippetWeek10
{
public static void main(String[] args)
{
//#3: Loop to ask user to enter a numeric grade and -1 to exit.
Scanner input = new Scanner(System.in);
System.out.println("Please enter the score:");
double sc=input.nextDouble();
if(sc!=-1)
{
printGrade(sc);
}
else
{
System.exit(0);
}
} // main() method.
//#2: TestVoidMethod.
public static void printGrade(double score) {
if (score > 97.0) {
System.out.println("A+");
}
else if (score > 93.0 && score <= 97.0) {
System.out.println('A');
}
else if (score >= 90.0 && score <= 93.0) {
System.out.println("A-");
}
else if (score > 87.0 && score < 90.0) {
System.out.println("B+");
}
else if (score > 83.0 && score <= 87.0) {
System.out.println('B');
}
else if (score >= 80.0 && score <= 83.0) {
System.out.println("B-");
}
else if (score > 77.0 && score < 80.0) {
System.out.println("C+");
}
else if (score > 73.0 && score <= 77.0) {
System.out.println('C');
}
else if (score >= 70.0 && score <= 73.0) {
System.out.println("C-");
}
else if (score > 67.0 && score < 70.0) {
System.out.println("D+");
}
else if (score > 63.0 && score <= 67.0) {
System.out.println('D');
}
else if (score >= 60.0 && score <= 63.0) {
System.out.println("D-");
}
else {
System.out.println('F');
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.