Question

I am having trouble with the following programs and wasn't sure whether I did it right....

I am having trouble with the following programs and wasn't sure whether I did it right.

A. Write a program in java using a switch statement which asks the user for their letter grade then prints a message to the student according to the following chart:

Average

Message

A

Your work is outstanding!

B

You are doing good work!

C

Your work is satisfactory.

D

You need to work a little harder.

F

Please see me for extra help!

B. Write a program in java using a switch statement which gets a number from the user and then prints a message to the user according to the chart which follows. The number input must be between 1 and 10 inclusive.

Number

Message

1 or 3

Your number is a low odd number.

2 or 4

Your number is a low even number.

5

Your number is the middle odd number.

6

Your number is the middle even number.

7 or 9

Your number is a high odd number.

8 or 10

Your number is a high even number.

Any other number entered should receive a message telling the user that (s)he entered an invalid number.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code for A:

import java.util.Scanner;
public class Main
{
   public static void main(String[] args) {
       Scanner scnr = new Scanner(System.in);
       char c=scnr.next().charAt(0);
       switch(c){
       case 'A':
       System.out.println("Your work is outstanding!");
       break;
       case 'B':
       System.out.println("You are doing good work!");
       break;
       case 'C':
       System.out.println("Your work is satisfactory.");
       break;
       case 'D':
       System.out.println("You need to work a little harder.");
       break;
       case 'F':
       System.out.println("Please see me for extra help!");
       break;
       default:
       System.out.println("invalid input!!");
       break;
       }
   }
}

Output for A:

Indentation for A:

Code for B:

import java.util.Scanner;
public class Main
{
   public static void main(String[] args) {
       Scanner scnr = new Scanner(System.in);
       int n=scnr.nextInt();
       switch(n){
       case 1:
       System.out.println("Your number is a low odd number.");
       break;
       case 2:
       System.out.println("Your number is a low even number.");
       break;
       case 3:
       System.out.println("Your number is a low odd number.");
       break;
       case 4:
       System.out.println("Your number is a low even number.");
       break;
       case 5:
       System.out.println("Your number is a middle odd number.");
       break;
       case 6:
       System.out.println("Your number is a middle even number.");
       break;
       case 7:
       System.out.println("Your number is a high odd number.");
       break;
       case 8:
       System.out.println("Your number is a high even number.");
       break;
       case 9:
       System.out.println("Your number is a high odd number.");
       break;
       case 10:
       System.out.println("Your number is a high even number.");
       break;
       default:
       System.out.println("invalid input!!");
       break;
       }
   }
}

Output for B:

Indentation for B:

Add a comment
Know the answer?
Add Answer to:
I am having trouble with the following programs and wasn't sure whether I did it right....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • USING C# LANGUAGE WE USE SCANF AND PRINTF PLEASE USE THAT IN THE ANSWER WE DONT...

    USING C# LANGUAGE WE USE SCANF AND PRINTF PLEASE USE THAT IN THE ANSWER WE DONT USE CONSOLEWRITE OR READ Write a program that takes in a number from the user. Then it prints a statement telling the user if the number is even or odd. If the number is odd, it counts down from the number to 0 and prints the countdown on the screen, each number on a new line. If the number is even, it counts down...

  • 1. Write a program that takes a number as input and check whether the number is...

    1. Write a program that takes a number as input and check whether the number is positive, negative or zero. 2. Write a C++ program that prompts the user to enter a number and checks whether the entered number is even or odd. 3.  Using switch-case statement write a C++ program that prompts the user to enter 1, 2 or 3 and display "Red" if selection is 1, "Yellow" if selection is 2, or "Green" if selection is 3. 4. Write...

  • I have to write a program in java which uses while loops. 1.prompt the user to...

    I have to write a program in java which uses while loops. 1.prompt the user to input two intergers: firstnum ans second numnumber. (first number must be smaller that the second number). 2. Output all the even numbers between first number and second number inclusive. 3. Output the sum of all the even number between first number and second number inclusive. 4 Output all the odd numbers between first number and second number inclusive. 5. Output the sum of all...

  • PROJECT 6    Functions You are to write a PYTHON program which: *Defines the following 4  functions: whoamI()...

    PROJECT 6    Functions You are to write a PYTHON program which: *Defines the following 4  functions: whoamI() This function prints out your name and lists any programming course you have taken prior to this course. isEven(number) This function accepts one parameter, a number, and prints out a message indicating if the number is even or odd. Keep in mind that a number is even if there is no remainder when the number is divided by two. printEven(number) This function accepts one...

  • I am having trouble figuring out what should go in the place of "number" to make...

    I am having trouble figuring out what should go in the place of "number" to make the loop stop as soon as they enter the value they put in for the "count" input. I am also having trouble nesting a do while loop into the original while loop (if that is even what I am supposed to do to get the program to keep going if the user wants to enter more numbers???) I have inserted the question below, as...

  • Jubail University College Computer Science & Engineering Department Assessmen Assignment Course Code CS120/C5101 t Type: 1...

    Jubail University College Computer Science & Engineering Department Assessmen Assignment Course Code CS120/C5101 t Type: 1 Semester: 403 Course Title Programming Submission 27-06-2020 Total Points 8 Date Submission Instructions: • This is an individual assignment. • Please submit your program (Java fle) in Blackboard. You can create one java project, named as Assignment1_id and add separate java file for each question. You can name your javá files as 01.02.... etc. • Make sure that you include your student ID name...

  • Can i get a help with this lab please! Lab 3 - Decision Making V <...

    Can i get a help with this lab please! Lab 3 - Decision Making V < Listen OBJECTIVES FOR STUDENT • To work with relational operators • To work with conditional statements if if else, if else if, and switch Notes • The lab is due, October 14, 2020, at 9am. . If you complete the lab before the deadline, send me an email and I can give you feedback . Please update your files to the Lab 3 Dropbox...

  • I am writing a program in c programming and it is supposed to do the following using mc9s12dg256.h microcontroller When...

    I am writing a program in c programming and it is supposed to do the following using mc9s12dg256.h microcontroller When both DIP switches #8 and #1 are high, turn on all LEDS. When both DIP switches #8 and #1 are low, turn off all LEDs When DIP switch #8 is high and #1 is low, turn on all the even numbered LEDs. When DIP switch #1 is high and #8 is low, turn on all the odd numbered LEDs. Your...

  • I have to use java programs using netbeans. this course is introduction to java programming so...

    I have to use java programs using netbeans. this course is introduction to java programming so i have to write it in a simple way using till chapter 6 (arrays) you can use (loops , methods , arrays) You will implement a menu-based system for Hangman Game. Hangman is a popular game that allows one player to choose a word and another player to guess it one letter at a time. Implement your system to perform the following tasks: Design...

  • Use Java program Material Covered : Loops & Methods Question 1: Write a program to calculate...

    Use Java program Material Covered : Loops & Methods Question 1: Write a program to calculate rectangle area. Some requirements: 1. User Scanner to collect user input for length & width 2. The formula is area = length * width 3. You must implement methods getLength, getWidth, getArea and displayData ▪ getLength – This method should ask the user to enter the rectangle’s length and then return that value as a double ▪ getWidth – This method should ask the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT