Question

In: Computer Science

For input you can either a console Scanner or a dialog box (a modal dialog) and...

For input you can either a console Scanner or a dialog box (a modal dialog) and the static method showInputDialog() of the JOptionPane class which is within the javax.swing package like this String name= newJOptionPane.showInputDialog(” Please enter your data:”). Then convert the String object to a number using Integer.parseInt() or Double.parseDouble()

----

Write a java the ”Letter grade” program that inputs several test scores from user and displays for each the corresponding letter grade using a scale 90 – 80 – 70 – 50. Test thoroughly the program with different data sets of your own.

Solutions

Expert Solution

import javax.swing.JOptionPane;

public class LetterGrade {
        public static void main(String[] args) {
                while (true) {
                        //reading score from user
                        String str = JOptionPane.showInputDialog("Please enter your score (-1 to exit):");
                        //converting it into double
                        double score = Double.parseDouble(str);
                        //break if it is -1
                        if(score==-1) break;
                        //finding the letter for given score
                        String letter = getLetter(score);
                        //showing the score and letter
                        JOptionPane.showMessageDialog(null, score+"          "+letter);
                }
        }
//returns letter grade for given score
        private static String getLetter(double n) {
                if (n >= 90)
                        return "A";
                if (n >= 80)
                        return "B";
                if (n >= 70)
                        return "C";
                if (n >= 60)
                        return "D";
                return "F";
        }
}

NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.

I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME


Related Solutions

public static void main(String[] args) {        Scanner input = new Scanner(System.in);        String[]...
public static void main(String[] args) {        Scanner input = new Scanner(System.in);        String[] strings = new String[100];        for (int i = 0; i < strings.length; i++) {            System.out.println("Enter Strings: stop ");            strings[i]=input.nextLine();            if(strings[i].equalsIgnoreCase("stop"))                break;        }               MaxLength(strings);//here is the error    }    public static int MaxLength(String[] array) {        int max = array[0].length();       ...
You can purchase an optical scanner today for $450. The scanner provides benefits worth $66 a...
You can purchase an optical scanner today for $450. The scanner provides benefits worth $66 a year. The expected life of the scanner is 10 years. Scanners are expected to decrease in price by 20% per year. Suppose the discount rate is 10%. Should you purchase the scanner today? Yes No When is the best purchase time? Wait for 4 years Wait for 5 years Wait for 6 years
You can purchase an optical scanner today for $400. The scanner provides benefits worth $60 a...
You can purchase an optical scanner today for $400. The scanner provides benefits worth $60 a year. The expected life of the scanner is 10 years. Scanners are expected to decrease in price by 20% per year. Suppose the discount rate is 10%. Should you purchase the scanner today or wait to purchase? When is the best purchase time?
Text effects can play an important role in polishing a document, but they also can overwhelm a document and distract readers. Consider the text effects available in the Font Dialog Box.
Microsoft Word ClassText effects can play an important role in polishing a document, but they also can overwhelm a document and distract readers. Consider the text effects available in the Font Dialog Box.How many effects are too many/just right for use in a document?What is the result of using too many effects?At what point is the document overwhelmed?Should the type of effect used vary according to the type of document?Please share your experiences in which content was undermined by animated...
1.The below code has some errors, correct the errors and post the working code. Scanner console...
1.The below code has some errors, correct the errors and post the working code. Scanner console = new Scanner(System.in); System.out.print("Type your name: "); String name = console.nextString(); name = toUpperCase(); System.out.println(name + " has " + name.Length() + " letters"); Sample Ouptut: Type your name: John JOHN has 4 letters    2. Write a code that it reads the user's first and last name (read in the entire line as a single string), then print the last name   followed by...
Create a lottery game application. Include a menu that allows the user to play more than once, or quit after a game. You can either use dialog boxes or text based, up to you.
FOR JAVA:Summary:Create a lottery game application. Include a menu that allows the user to play more than once, or quit after a game. You can either use dialog boxes or text based, up to you.The solution file should be named Lottery.javaGenerate four random numbers, each between 0 and 9 (inclusive).Allow the user to guess four numbers.Compare each of the user’s guesses to the four random numbers and display a message that includes the user’s guess, the randomly determined four-digit number,...
Important notes: Use Console I/O (Scanner and System.out) for all user I/O in this lab. Do...
Important notes: Use Console I/O (Scanner and System.out) for all user I/O in this lab. Do not hard code data file paths or filenames; always ask the user for them. Complete the Monster Attack project by doing the following: In place of the driver used in homework 2, add a menu with a loop and switch (this is already done, ignore this). The user must be able to add attacks, get a report on existing attacks, save a file, retrieve...
User the Scanner class for your input Write a java program to calculate the area of...
User the Scanner class for your input Write a java program to calculate the area of a rectangle. Rectangle Area is calculated by multiplying the length by the width   display the output as follow: Length =   Width = Area = Load: 1. Design (Pseudocode ) 2. Source file (Java file, make sure to include comments) 3. Output file (word or pdf or jpig file)
Hello, Can you please write a free plagiarism report about "Dryport a modal shift in practice",...
Hello, Can you please write a free plagiarism report about "Dryport a modal shift in practice", it has to be 500 words only. Thanks in advance
“If each box of a dumb waiter weighs 10 pounds, and one pound on either box...
“If each box of a dumb waiter weighs 10 pounds, and one pound on either box is necessary to overcome friction, what weight is in a box descending 8 feet per second 4 seconds after starting down?  What is the momentum of the descending box?”
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT