Question

In: Computer Science

Write a method with the following header: public static char calculateLetterGrade(int grade, int totalMarks) This method...

Write a method with the following header:

public static char calculateLetterGrade(int grade, int totalMarks)

This method calculates grade/totalMarks and returns a letter grade based on the following scale:

0-50 = F

51-60 = D

61-70 = C

71-80 = B

81-100 = A

Solutions

Expert Solution

Code:

class Main
{
    public static char calculateLetterGrade(int grade, int totalMarks)  //it will return grade based on total marks
    {
        if(totalMarks>=81 && totalMarks<=100)    //if marks in between of 81-100 then grade is A 
        {
            return 'A';
        }
        else if(totalMarks>=71 && totalMarks<=80)  //if marks in between of 71-80 then grade is B 
        {
           return 'B';
        } 
        else if(totalMarks>=61 && totalMarks<=70) //if marks in between of 61-70 then grade is C 
        {
            return 'C';
        }
        else if(totalMarks>=51 && totalMarks<=60) //if marks in between of 51-60 then grade is D
        {
            return 'D';
        }
        else if(totalMarks>=0 && totalMarks<=50) //if marks in between of 0-50 then grade is F 
        {
            return 'F';
        }
        return '0';                           
    }
    public static void main(String args[])
    {        
        System.out.println("Grade of marks 90 is: "+calculateLetterGrade(1,90));
        System.out.println("Grade of marks 80 is: "+calculateLetterGrade(2,80));
        System.out.println("Grade of marks 64 is: "+calculateLetterGrade(3,64));
        System.out.println("Grade of marks 57 is: "+calculateLetterGrade(4,57));
        System.out.println("Grade of marks 45 is: "+calculateLetterGrade(5,45));  
    }
}

Output:

.


Related Solutions

Write a method with the following header: public static void showGradeDistribution(int a, int b, int c,...
Write a method with the following header: public static void showGradeDistribution(int a, int b, int c, int d, int f) It should print a graph (using asterisks) for each of the letters entered in the reverse order of the parameter list and with a label. In addition, if A and B grades sum is equal or exceeds that of grades C and D and F, the message “Strong class!” should be displayed. For example a method call of: showGradeDistribution(5,7,4,4,3); Would...
rite a method with the following header: public static void showGradeDistribution(int a, int b, int c,...
rite a method with the following header: public static void showGradeDistribution(int a, int b, int c, int d, int f) It should print a graph (using asterisks) for each of the letters entered in the reverse order of the parameter list and with a label. In addition, if A and B grades sum is equal or exceeds that of grades C and D and F, the message “Strong class!” should be displayed. For example a method call of: showGradeDistribution(5,7,4,4,3); Would...
JAVA Given the header of a method public static void m1 (int[ ] max) Write down...
JAVA Given the header of a method public static void m1 (int[ ] max) Write down Java codes to invoke m1 method, declare variables as needed, (Do NOT implement the method)
public class StringTools {    public static int count(String a, char c) {          ...
public class StringTools {    public static int count(String a, char c) {           }
public static int punishOrMercy(char direction, int reward) Output: int which will be the value of zero...
public static int punishOrMercy(char direction, int reward) Output: int which will be the value of zero or the initial reward. Functionality: After the result of the reward function is stored, this function should be called. The goal of this function is to help the robot in case it faced a lot of damage in the current step. However, this function will help the robot only if the robot’s reward was negative and the direction that the user inputted was up....
(java)Write a recursive method public static int sumForEachOther(Int n) that takes a positive Int as an...
(java)Write a recursive method public static int sumForEachOther(Int n) that takes a positive Int as an argument and returns the sum for every other Int from n down to 1. For example, sumForEachOther(8) should return 20, since 8+6+4+ 2=20.And the call sumForEachOther(9) should return 25 since 9+7+5 + 3+1-=25. Your method must use recursion.
JAVA please write this method public static void recursiveSelectionSort(int[] arr) { }
JAVA please write this method public static void recursiveSelectionSort(int[] arr) { }
JAVA please write this method public static void recursiveMergeSort(int[] arr) { }
JAVA please write this method public static void recursiveMergeSort(int[] arr) { }
Given the following method declaration, write a valid method call. public static void calcArea(String roomName, int...
Given the following method declaration, write a valid method call. public static void calcArea(String roomName, int length, int width)
Consider the following recursive method in Java public static int mystery(int n) {   if (n ==...
Consider the following recursive method in Java public static int mystery(int n) {   if (n == 0)   return 1;    else    return 4 * mystery (n - 1);   } What is the output of  mystery (3) using the code segment above Show your work on your trace file
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT