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

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 ”Statistics program” to calculate the mean, variance and standard deviation for a given set of numbers. The user in entering the data interactively. The size...
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() ----- . If an amount of A dollars is borrowed at an interest rate (expressed as a decimal) r for y years, and n is the number of annual...
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 program to calculate the first n ( the user enters the integer n) rows of the Pascal triangle. On demand display the first n rows...
In VB console write a Console Application that reads an input value for ??. You can...
In VB console write a Console Application that reads an input value for ??. You can assume that the user only inputs numeric values.
7) Write a program to open an input dialog box and read a string value. Write...
7) Write a program to open an input dialog box and read a string value. Write the string back to the user using a message box. USING MIPS ASSEMBLY LANGUAGE
Please write a java program (using dialog box statements for user input) that has the following...
Please write a java program (using dialog box statements for user input) that has the following methods in it: (preferably in order)   a method to read in the name of a University and pass it back a method to read in the number of students enrolled and pass it back a method to calculate the tuition as 20000 times the number of students and pass it back a method print the name of the University, the number of students enrolled,...
The Views options of the insert component dialog box allows you to insert components symbols in...
The Views options of the insert component dialog box allows you to insert components symbols in a drawing A. inline with connectors B. above or below the wire C. with or without text D. with or without JIC symbols
CAN YOU CORRECT THIS CODE PLS. Scanner in = new Scanner (System.in);    // EXAMPLE 1...
CAN YOU CORRECT THIS CODE PLS. Scanner in = new Scanner (System.in);    // EXAMPLE 1 System.out.println("****************** EXAMPLE 1 *****************" ); int x = 4, y = 9; int a = 99, b = -22; if (x > y) System.out.println("x > y"); if (x < y) System.out.println("x < y"); if (x >= y) System.out.println("x >= y"); if (a <= 10023) System.out.println("a <= 10023"); if (b == y) System.out.println("b == y"); if (b == 5) System.out.println("b == 5"); if (x !=...
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT