• Home
  • Blog
  • RU Calculating a Grade Pass Any Values as Arguments Program

RU Calculating a Grade Pass Any Values as Arguments Program

0 comments

5-16. Modify ex41.java into ex516.java with the calculating of the grade from an exam grade and a bribe. Break the program into these separate steps and methods:

Input the two inputs – we can keep that in main

Calculating the letter grade – use a calclet() method

Printing the letter grade – use a printlet() method

Pass any values as arguments that the method needs and return any values the method calculates. Declare any local variables as needed.

Run the program with a grade of 65 and a bribe of 600. Save the output as ex516.txt. Attach ex516.java and ex516.txt and submit.

 * Exercise 4-1
 * This program will calculate a grade based upon an exam grade and bribe
 * */
import java.util.Scanner;
public class ex41
{
  public static void main(String[] args)
  {
    int grade, bribe;
    char letter;
    Scanner sc = new Scanner(System.in);
    System.out.print("Enter exam grade:  ");
    grade = sc.nextInt();
    System.out.print("Enter bribe:  ");
    bribe = sc.nextInt();
    
    if (grade < 0 || grade > 100)
      letter = 'U';
    else if (grade >= 90 || (grade >= 80 && bribe >= 250) ||
       (grade >= 70 && bribe >= 500) ||
           (grade >= 60 && bribe >= 750) || bribe >= 1000)
               letter = 'A';
    else if (grade >= 80 || (grade >= 70 && bribe >= 250) ||
        (grade >= 60 && bribe >= 500) || bribe >= 750)
            letter = 'B';
    else if (grade >= 70 || (grade >= 60 && bribe >= 250) ||
         bribe >= 500)
             letter = 'C';
    else if (grade >= 60 || bribe >= 250)
      letter = 'D';
    else 
      letter = 'F';
    
    if (!(letter == 'U'))     // letter != 'U'
      System.out.println("nYour letter grade is " + letter);
    else
      System.out.println("nGrade out of range");
  }
}
    

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}