Question

In: Computer Science

JAVA Write a program that translates a user-input floating-point number between 0 and 4 into the...

JAVA Write a program that translates a user-input floating-point number between 0 and 4 into the closest letter grade. For example, the number 2.8 (which might have been the average of several grades) would be converted to B–. Break ties in favor of the better grade; for example 2.85 should be a B. NOTE: Your implementation must include the definition/implementation and use/calling of the method numberGradeToLetterGrade that is passed a double numeric grade to its parameter variable, and returns the letter grade.

Solutions

Expert Solution

Answer :-

Definition

if grade >= 3.85 && grade <= 4.0 -> letterGrade = A+
if grade >= 3.5 && grade < 3.85 -> letterGrade = A

if grade >= 3.333 && grade < 3.5 -> letterGrade = A-
             

if grade >= 3.0 && grade < 3.333 -> letterGrade = B+
if grade >= 2.85 && grade < 3.0 -> letterGrade = B
   if grade >= 2.333 && grade < 2.85 -> letterGrade = B-
                 
if grade >= 2.0 && grade < 2.333 -> letterGrade = C+
     if grade >= 1.667 && grade < 2.0 -> letterGrade = C
    if grade >= 1.333 && grade < 1.667 -> letterGrade = C-


    if grade >= 1.0 && grade < 1.333 -> letterGrade = D+
    if grade > 0 && grade < 1.0 -> letterGrade = D
if grade == 0                 -> letterGrade = F
       

Java Code :-

import java.util.Scanner;
public class grade
{
  
    public static String numberGradeToLetterGrade(double number)
    {
        String letterGrade="N";
        if (number >= 3.85 && number <= 4.0 )
       {
           letterGrade = "A+";
       }
       else if (number >= 3.5 && number < 3.85 )
       {
           letterGrade = "A";
       }
       else if (number >= 3.333 && number < 3.5 )
       {
           letterGrade = "A-";
       }
       else if (number>= 3.0 && number < 3.333 )
       {
           letterGrade = "B+";
       }
       else if (number >= 2.85 && number < 3.0 )
       {
           letterGrade = "B";
       }  
       else if (number >= 2.333 && number < 2.85 )
       {
           letterGrade = "B-";
       }      
       else if (number >= 2.0 && number < 2.333 )
       {
           letterGrade = "C+";
       }      
       else if (number >= 1.667 && number < 2.0 )
       {
           letterGrade = "C";
       }      
       else if (number >= 1.333 && number < 1.667 )
       {
           letterGrade = "C-";
       }
       else if (number >= 1.0 && number < 1.333 )
       {
           letterGrade = "D+";
       }
       else if (number> 0 && number < 1.0 )
       {
           letterGrade = "D";
       }
       else if (number == 0)       {
           letterGrade = "F";
       }
       return letterGrade; // return letter Grade
    }
   public static void main(String[] args) {
   Scanner sc= new Scanner(System.in);
      
       System.out.print("Please enter your number between 0 and 4: ");// prompt the user for a number
  
       double number = sc.nextDouble();   // store the user input
      
       while (number <0 || number > 4) // if user not enter value between 0 to 4
       {
            System.out.print("Please enter your number between 0 and 4: ");
              
            number = sc.nextDouble(); // store the user input
       }
  
       String letterGrade;
       
        // now ,call a function numberGradeToLetterGrade and print letterGrade
        System.out.println("Your grade is\t" +number+ "\t Which is equal to: \t" + numberGradeToLetterGrade(number));
      
   }
}

Screenshot of code and output :-


Related Solutions

Write a program that asks the user to input a set of floating-point values. When the...
Write a program that asks the user to input a set of floating-point values. When the user enters a value that is not a number, give the user a second chance to enter the value. After two chances, quit reading input. Add all correctly specified values and print the sum when the user is done entering data. Use exception handling to detect improper inputs.5 pts Your code with comments A screenshot of the execution Test Case:       Enter float: 1.0...
Write Java program that asks a user to input a letter, converts the user input to...
Write Java program that asks a user to input a letter, converts the user input to uppercase if the user types the letter in lowercase, and based on the letter the user the user enters, display a message showing the number that matches the letter entered. For letters A or B or C display 2 For letter D or E or F display 3 For letter G or H or I display 4 For letter J or K or L...
Java Program 1. Write a program that asks the user: “Please enter a number (0 to...
Java Program 1. Write a program that asks the user: “Please enter a number (0 to exit)”. Your program shall accept integers from the user (positive or negative), however, if the user enters 0 then your program shall terminate immediately. After the loop is terminated, return the total sum of all the previous numbers the user entered. a. What is considered to be the body of the loop? b. What is considered the control variable? c. What is considered to...
Write a java program. The program requirements are: the program will let the user input a...
Write a java program. The program requirements are: the program will let the user input a starting number, such as 2.  It will generate ten multiplication problems ranging from 2x1 to 2x10.  For each problem, the user will be prompted to enter the correct answer. The program should check the answer and should not let the user advance to the next question until the correct answer is given to the question being asked currently. After testing a total of 10 multiplication problems,...
Write a JAVA program that allow a user to enter 2 number, starting point and end...
Write a JAVA program that allow a user to enter 2 number, starting point and end point. For example a user me enter 1 and 100. Your program will Add numbers from 1 to 100, add all the even number, and add all the odd numbers Output: The sum of number 1 to 100 is: The sum of even number 1 to 100 is: The sum of odd number 1 to 100 is:
write a java program to evaluate the highest number input by user, cannot use math class,...
write a java program to evaluate the highest number input by user, cannot use math class, must use overloading . Must compute four computeHighNum methods. Here is what I have. import java.util.Scanner; public class Overload { public static void main(String[] args){ Scanner input = new Scanner(System.in); int number1 = input.nextInt(); int number2 = input.nextInt(); int number3 = input.nextInt();    //int maximum = maximum(number1, number2 ); System.out.printf("Highest integer is ");       // int number1 = input.nextInt(); // int number2 =...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input using the Scanner class. First to enter their first name. Then prompts the user to enter their last name. Then prompts the user to enter their city. Then prompts the user to enter their state. Then prompts the user to enter their zip code. Concatenate first name and last name into full_name. Using String Class is optional. Use the String Class to replace zip...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input using the Scanner class. First to enter their first name. Then prompts the user to enter their last name. Then prompts the user to enter their city. Then prompts the user to enter their state. Then prompts the user to enter their zip code.   Concatenate first name and last name into full_name. Using String Class is optional. Use the String Class to replace zip...
JAVA: Write a program that prompts the user to input a type of medication and the...
JAVA: Write a program that prompts the user to input a type of medication and the output will be a list of side effects that can occur from that medication.
Write a program that prompts the user to input a decimal number and outputs the number...
Write a program that prompts the user to input a decimal number and outputs the number rounded to the nearest integer.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT