1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
UkoKoshka [18]
3 years ago
8

java Your program class should be called RomanNumerals Write a program that asks the user to enter a number within the range of

1 through 10. Use a switch statement to display the Roman numeral version of that number. Do not accept a number less than 1 or greater than 10. s

Engineering
2 answers:
Ann [662]3 years ago
6 0

Answer:

// Scanner class is imported to allow program

// receive input

import java.util.Scanner;

// RomanNumerals class is defined

public class RomanNumerals {

   // main method that signify beginning of program execution

   public static void main(String args[]) {

       // Scanner object scan is created

       // it receive input via keyboard

       Scanner scan = new Scanner(System.in);

       // Prompt is display asking the user to enter number

       System.out.println("Enter your number: ");

       // the user input is stored at numberOfOrder

       int number = scan.nextInt();

     

           // switch statement which takes number as argument

           // the switch statement output the correct roman numeral

           // depending on user input

          switch(number){

           case 1:

               System.out.println("I");

               break;

           case 2:

               System.out.println("II");

               break;

           case 3:

               System.out.println("III");

               break;

           case 4:

               System.out.println("IV");

               break;

           case 5:

               System.out.println("V");

               break;

           case 6:

               System.out.println("VI");

               break;

           case 7:

               System.out.println("VII");

               break;

           case 8:

               System.out.println("VIII");

               break;

           case 9:

               System.out.println("IX");

               break;

           case 10:

               System.out.println("X");

               break;

           // this part is executed if user input is not between 1 to 10

           default:

               System.out.println("Error. Number must be between 1 - 10.");

     }

   }

}

Explanation:

The program is well commented. A sample image of program output is attached.

The switch statement takes the user input (number) as argument as it goes through each case block in the switch statement and match with the corresponding case to output the roman version of that number. If the number is greater 10 or less than 1; the default block is executed and it display an error message telling the user that number must be between 1 - 10.

Iteru [2.4K]3 years ago
6 0
<h2>Answer:</h2>

//import the Scanner class to allow for user's input

import java.util.Scanner;

// Write the class header with the appropriate name

public class RomanNumerals {

   // Write the main method - this is where execution begins

   public static void main(String[] args) {

       //Create an object of the Scanner class to allow user's to enter the number

       Scanner input = new Scanner(System.in);

       

       //Prompt the user to enter a number

       System.out.println("Please enter a number within the range of 1 through 10");

       

       //Receive the number from the user and store in an int variable

       int num = input.nextInt();

       

       

       //Begin the switch statement using the num

       switch (num) {

       

           //If the number is 1

           //Print the corresponding Roman numeral -> I

           //Then break out of the switch statement

           case 1 :  

               System.out.println("I");

               break;

               

           //If the number is 2

           //Print the corresponding Roman numeral -> II

           //Then break out of the switch statement

           case 2 :

               System.out.println("II");

               break;

               

           //If the number is 3

           //Print the corresponding Roman numeral -> III

           //Then break out of the switch statement

           case 3:

               System.out.println("III");

               break;

               

           //If the number is 4

           //Print the corresponding Roman numeral -> IV

           //Then break out of the switch statement

           case 4:

               System.out.println("IV");

               break;

               

           //If the number is 5

           //Print the corresponding Roman numeral -> V

           //Then break out of the switch statement

           case 5:

               System.out.println("V");

               break;

               

           //If the number is 6

           //Print the corresponding Roman numeral -> VI

           //Then break out of the switch statement

           case 6:

               System.out.println("VI");

               break;

               

           //If the number is 7

           //Print the corresponding Roman numeral -> VII

           //Then break out of the switch statement

           case 7:

               System.out.println("VII");

               break;

             

           //If the number is 8

           //Print the corresponding Roman numeral -> VIII

           //Then break out of the switch statement

           case 8:

               System.out.println("VIII");

               break;

           

           //If the number is 9

           //Print the corresponding Roman numeral -> IX

           //Then break out of the switch statement

           case 9:

               System.out.println("IX");

               break;

               

           //If the number is 10

           //Print the corresponding Roman numeral -> X

           //Then break out of the switch statement

           case 10:

               System.out.println("X");

               break;

           

           //If the number is not within range [That is the default case]

           //Print the corresponding error message.  

           //You might want to print the error message using  

           //System.err.println() rather than

           //the regular System.out.println()

           //Then break out of the switch statement

           default:

               System.err.println("Error: The number should not be less than 1 or greater than 10");

               break;

               

       }          //End of switch statement

       

       

  }  // End of main method

   

}  // End of class declaration

=============================================================

<h2><u>Sample Output 1:</u></h2>

>> Please enter a number within the range of 1 through 10

5

>> V

<h2></h2>

==============================================================

<h2><u>Sample Output 2:</u></h2>

>> Please enter a number within the range of 1 through 10

0

>> Error: The number should not be less than 1 or greater than 10

<h2 />

===============================================================

<h2></h2><h2></h2><h2></h2><h2></h2><h2>Explanation:</h2>

The code has been written in Java and it contains comments explaining every section of the code, please go through the comments to get a better understanding of the code.

Actual codes are written in bold face to distinguish them from the comments.

You might be interested in
Plssssssssssssss Alexi is writing a program which prompts users to enter their age. Which function should she use?
aleksandr82 [10.1K]

Answer:

int()

Explanation:

float() is using decimals, so that can't be it, like float(input( "how much does this cost?"))

print() is used to print something, not a user asking, like print("hello")

string() means like a whole, like string( I am good)

By elimination, int() is correct.

Hope this helps!

7 0
2 years ago
Fill in the blank to correctly complete the statement below.
frutty [35]

Answer:

The invention of the pendulum-driven ___<u>clocks</u>___ in the 1600s paved the way for a new industrial era.

4 0
3 years ago
¿Qué es la masonería?​
timofeeve [1]

Answer: freemasonry is Being a Mason is about a father helping his son make better decisions; a business leader striving to bring morality to the workplace; a thoughtful man learning to work through tough issues in his life.

Explanation:

3 0
2 years ago
Handsaw teeth are very sharp: to avoid being cut by the teeth, keep hands and fingers well away from the
siniylev [52]
Handsaw teeth are very sharp: to avoid being cut by the teeth, keep hands and fingers well away from the
path of the blade
6 0
2 years ago
Read 2 more answers
How many people made machines
olganol [36]

Answer:

The total number of people whom have made machines is not a recorded figure? Need to be more specific :/

Explanation:

Sorry not very helpful, your question is REALLY broad

3 0
2 years ago
Read 2 more answers
Other questions:
  • - Scrap tire management is primarily regulated at the
    14·2 answers
  • A closed, rigid tank is lled with a gas modeled as an ideal gas, initially at 27°C and a gage pressure of 300 kPa. The gas is he
    15·1 answer
  • 11. Which of the following is the brake fluid most often used?
    11·2 answers
  • 1. What are the usual symptoms of brake issues?​
    15·1 answer
  • Use the method of cylindrical shells to find the volume generated by rotating the region bounded by the given curves about the y
    7·1 answer
  • the voltage across a 5mH inductor is 5[1-exp(-0.5t)]V. Calculate the current through the inductor and the energy stored in the i
    6·1 answer
  • Ammonia in a piston–cylinder assembly undergoes two processes in series. At the initial state, p1 = 120 lbf/in.2 and the quality
    15·1 answer
  • How can you drop two eggs the feweHow can you drop two eggs the fewest amount of times, without them breaking? ...st amount of t
    13·2 answers
  • Rotating magnetic field inside a set of conducting wires is a simple description of a what
    14·1 answer
  • The first thing you should do is develop a ____________________ to determine what vehicle you can afford.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!