Question

In: Computer Science

Write a program which asks the user for grade, in integer form, from 0 to 100....

Write a program which asks the user for grade, in integer form, from 0 to 100.

If the user's response is negative or greater than 100, insult them.

Otherwise, use if / else statements to print out the letter grade corresponding to the user's input.

  • 90 - 100 : A
  • 80 - 89 : B
  • 70 - 79 : C
  • 60 - 69 : D
  • 0 - 59 : F

Then, write a second version of the program which uses a switch instead of if else. (HINT: divide the user's response by 10)

in java

Solutions

Expert Solution


import java.util.*;
public class Main
{
   public static void main(String[] args) {
   int n;
   Scanner sc = new Scanner(System.in);
       System.out.print("Enter mark 0 to 100: ");
       n=sc.nextInt();
       int i=n;
       if(i>=0 && i<=100)
       {
       if(i>=90)
       {
           System.out.println("A");
       }
       else if(i>=80)
       {
           System.out.println("B");
       }
       else if(i>=70)
       {
           System.out.println("C");
       }
      
       else if(i>=60)
       {
           System.out.println("D");
       }
       else
       {
           System.out.println("F");
       }
       }
  
    else
       {
           System.out.println("INVALID");
       }
   }
}


import java.util.*;
public class Main
{
   public static void main(String[] args) {
   int n;
   Scanner sc = new Scanner(System.in);
       System.out.print("Enter mark 0 to 100: ");
       n=sc.nextInt();
       int i=n/10;
       switch(i)
       {
       case 10:
       {
           System.out.println("A");
           break;
       }
       case 9:
       {
           System.out.println("A");
           break;
       }
       case 8:
       {
           System.out.println("B");
           break;
       }
       case 7:
       {
           System.out.println("C");
           break;
       }case 6:
       {
           System.out.println("D");
           break;
       }
      
       default:
       {
           System.out.println("F");
           break;
       }
       }
  

   }
}


Related Solutions

Write a program which asks the user for grade, in integer form, from 0 to 100....
Write a program which asks the user for grade, in integer form, from 0 to 100. If the user's response is negative or greater than 100, insult them. Otherwise, use if / else statements to print out the letter grade corresponding to the user's input. 90 - 100 : A 80 - 89 : B 70 - 79 : C 60 - 69 : D 0 - 59 : F Then, write a second version of the program which uses...
Write a program that prompts the user for a grade (0-100), and asks if the student...
Write a program that prompts the user for a grade (0-100), and asks if the student is a graduate student or not. (Y/N).   If the student is a graduate student, the grade is reduced by 10%, because we have a higher expectation for graduate students, in an undergraduate class. The program then computes, and prints the letter grade based on the scale below. 90-100 A 80-89 B 70-79 C 60-69 D 0-60 F The program also provides feedback based on...
Write a C# program using Repl.it that asks the user for a numeric grade between 0...
Write a C# program using Repl.it that asks the user for a numeric grade between 0 and 100, and displays a letter grade using the following conversion table: Numeric grade   Letter grade 90 < grade <= 100 A 80 < grade <= 90 B 70 < grade <= 80 C 60< grade <= 70 D grade <= 0.0 F Don’t forget the comments in your code. The output should be similar to: Enter the test score: 87 The letter grade...
Write a program that asks the user for an integer. The program checks and prints to...
Write a program that asks the user for an integer. The program checks and prints to the screen whether the number is prime or not. For example, if user enters 17, the program should print “17 is prime”; if the user enters 20, the program should print “20 is not prime”. please do it with a “ while Loop”, Thanks..
Write a program which: Prompts the user for a positive integer >= 0 Validates the user...
Write a program which: Prompts the user for a positive integer >= 0 Validates the user input to ensure it is a positive integer >= 0 Allocate (dynamically) an array big enough for the data. Load the array with random numbers ranging in value from1 to 100 Display the elements of the array (unsorted) Display the elements of the array (sorted) Display the average Display the median Display the mode, if none, display appropriate message RESTRICTIONS No global variables No...
Write a program in Cthat asks for an integer y ≥ 0, which represents a year....
Write a program in Cthat asks for an integer y ≥ 0, which represents a year. The program should output “YES” if the y is leap (and “NO” if it is not). A leap year is a year that has 366 days (or February 29), that is a year which is divisible by 4 but, not by 100; in exception if it is divisible by 400.
Write a Java program that asks the user to enter an integer that is used to...
Write a Java program that asks the user to enter an integer that is used to set a limit that will generate the following four patterns of multiples of five using nested loops •Ascending multiples of five with ascending length triangle •Ascending multiples of five with descending length (inverted) triangle •Descending multiples of five with ascending length triangle •Descending multiples of five with descending length (inverted) triangle Use error checking to keep asking the user for a positive number until...
python programming. Write a program that prompts the user to enter an integer from 0 to...
python programming. Write a program that prompts the user to enter an integer from 0 to 9. The program will check if the input is a positive integer. It displays the correct answer and shows the guess is correct or not. The demos are shown as following.(Hint:1. Use a random math function 2. Use str.isdigit() to check the input)
a). Write a program that asks the user to enter an integer N and prints two...
a). Write a program that asks the user to enter an integer N and prints two integers, root and power, such that 1 < power < 6 and N = root ** power. If no such pair of integers exists, it should print a message to that effect. There are two loops, one for power and one for root. Order the loops so that if N = 64, then your program find that N = 8 ** 2 rather than...
Write a program that asks the user for an integer and then prints out all its...
Write a program that asks the user for an integer and then prints out all its factors. For example, when the user enters 84, the program should print 2 2 3 7 Validate the input to make sure that it is not a character or a string using do loop.in c++
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT