Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

2. Write a program to determine the letter grade for a student based on the tota

ID: 3591736 • Letter: 2

Question

2. Write a program to determine the letter grade for a student based on the totals marks the student received. Your program should prompt the student to enter the marks received, then read the marks and display the marks on the screen (e.g, You entered). Next, use the if, else if selection structure to determine the letter grade for a student based on the following criteria: Student Marks Letter Grade Marks greater than or equal to 80 Marks greater than or equal to 70 Marks less than 60 Your program should then output the letter grade of the student 3. Rewrite the program in Q2, using the switch structure instead of the if, else if selection format Hint: Recl that switch uses int/char type labels. Range of marks can be converted to an int value by diving by 10. Example for marks in the range of 70 to 79 (70 marks

Explanation / Answer

Marks2Grade.java

// Using IF, ELSE IF

import java.util.Scanner;

public class Marks2Grade {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int marks;

char grade_using_if;

System.out.println("Please Enter the Marks Recieved between 0 - 100");

marks = sc.nextInt();

sc.nextLine();

System.out.println("You have enterd" + marks);

grade_using_if = useIfForGrade(marks);

System.out.println("Grade using IF Logic : "+ grade_using_if);

}

public static char useIfForGrade(int marks) {

char grade = 0;

if(marks >= 90)

grade = 'A';

else if (marks >= 80 && marks < 90)

grade = 'B';

else if (marks >= 70 && marks < 80)

grade = 'C';

else if (marks >= 60 && marks < 70)

grade = 'D';

else if (marks < 60)

grade = 'F';

return grade;

}

}

Marks2Grade2.java

// Using Switch

import java.util.Scanner;

public class Marks2Grade2 {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int marks;

char grade_using_switch;

System.out.println("Please Enter the Marks Recieved between 0 - 100");

marks = sc.nextInt();

sc.nextLine();

System.out.println("You have enterd" + marks);

grade_using_switch = useSwitchForGrade(marks);

System.out.println("Grade using Switch Logic : "+ grade_using_switch);

}

public static char useSwitchForGrade(int marks) {

char grade =0;

int mark;

mark = marks/10;

switch (mark) {

case 10:

grade = 'A';

break;

case 9:

grade = 'A';

break;

case 8:

grade = 'B';

break;

case 7:

grade = 'C';

break;

case 6:

grade = 'D';

break;

default:

grade = 'F';

break;

}

return grade;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote