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
Engineered lumber should not be used for
Dimas [21]

Answer:

Composite panel garage doors

Explanation:

8 0
2 years ago
Which Finance jobs can someone pursue with only a high school diploma? Check all that apply.
Zolol [24]

Answer:

Teller, Loan Officer, and Tax Preparer

Explanation:

3 0
3 years ago
Read 2 more answers
Discuss three objectives of Tariff and elaborate on three characteristics of it
Margaret [11]

Answer:

Three objectives of a tariff are

1) To control trade between countries

2) To protect domestic industries

3) To provide a source of income

Three characteristics of a tariff are;

1) Adequate return

2) Attractive

3) Fairness

Explanation:

A tariff is an import or export tax placed on goods traded between countries, it serves to control the foreign trade between the two countries and to protect or develop local industry

A Tariff is an important source of income to countries

Three characteristics of a tariff are;

1) Adequate return

Proper return from the consumer should be factored in a tariff to account for the alternatives or normal expense pattern

2) Attractive

The tariff should be attractive to encourage consumption of electricity or complimentary goods

3) Fairness

Based on the consumption of related resources brought about by large scale utilization, large consumer tariff should be lower than those that consume less complementary resources.

5 0
3 years ago
Which of the following might be a job or task of an IT worker who manages
-Dominant- [34]

Answer:

I'm pretty sure it's letter d

7 0
3 years ago
An insulated piston-cylinder device initially contains 0.16 m2 of CO2 at 150 kPa and 41 °C. Electric resistance heater supplied
lyudmila [28]

Answer:

I=0.3636

Explanation:

See the attached picture for explanation.

4 0
3 years ago
Other questions:
  • A rubber wheel on a steel rim spins freely on a horizontal axle that is suspended by a fixed pivot at point P. When the wheel sp
    11·1 answer
  • A shrinkage limit test is performed on a soil. The initial mass and volume of the soil are: V1=20.2cm^3 , while the final mass a
    15·1 answer
  • Calculate the resistance using Voltage and current, again using voltage and power, again using current and power, and again usin
    12·1 answer
  • Module 42 Review and Assessment
    7·1 answer
  • 7. A single-pole GFCI breaker is rated at
    9·1 answer
  • What type of fuel does a 2 cycle engine use
    5·1 answer
  • 6. Question
    13·1 answer
  • C programming fundamentals for everyone​
    13·1 answer
  • Employees cannot be held legally responsible for an environmental violation.
    14·1 answer
  • 3. A steel pipe of outside diameter 20 mm and thickness 3 mm is
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!