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
Gre4nikov [31]
4 years ago
12

Write a program that converts a number entered in Roman numerals to decimal.

Computers and Technology
1 answer:
Montano1993 [528]4 years ago
5 0

Answer:

Here is the JAVA program:

import java.util.Scanner;   // for importing scanner class

public class RomanToDecimal{  //class to convert roman numeral to decimal

       static String romNum;  // variable that stores roman numeral

       static int decNum;  //variable that stores decimal number

       public static void main(String args[]) {  //start of the program

              //romtodec object created

              RomanToDecimal romtodec = new RomanToDecimal();  

//call function decimalConversion() that converts roman numeral to decimal

              romtodec. decimalConversion();  

//call function displayRomanNumeral to display the results of conversion

               romtodec. displayRomanNumeral(romNum);

//call function to display the decimal no. of roman numeral

               romtodec . displayDecimalNumber(decNum);   }

//method decimalConversion to convert Roman numeral to decimal

     public void decimalConversion () {

     Scanner scan = new Scanner(System.in);  //to get input

       //prompts user to enter a Roman numeral

     System.out.print("enter a Roman numeral: ");

               romNum = scan.nextLine();  //reads input    

               //stores the length of the entered Roman numeral                                            

                int length=  romNum.length();  

               int number=0;  //initializes number to 0

               int prevNum = 0;  //initializes previous number to 0

          //loops through the length of the input Roman numeral

               for (int i=length-1;i>=0;i--)  

//charAt() method returns the roman numeral symbol at the index i

               { char symbol =  romNum.charAt(i);

       //every symbol will be converted to upper case

                       symbol = Character.toUpperCase(symbol);

//switch statement tests the symbol variable for equality against a list of //numerals given and each numeral is assigned its equal decimal value.

                         switch(symbol)

                       {   case 'I':

                               prevNum = number;

                               number = 1;

                               break;

                            case 'V':

                                    prevNum = number;

                               number = 5;

                               break;

                               case 'X':

                                       prevNum = number;

                               number = 10;

                                break;

                               case 'L':

                                       prevNum = number;

                               number = 50;

                               break;

                               case 'C':

                                        prevNum = number;

                               number = 100;

                               break;

                               case 'D':

                                        prevNum = number;

                               number = 500;

                               break;

                               case 'M':

                                        prevNum = number;

                               number = 1000;

                               break; }          

/*checks if the number is greater than previous number

if the value of current roman symbol (character) is greater than the next

symbol's value. then add value of current roman symbol to the decNum

else subtract the value of current roman symbol from the value of its next symbol. */              

                       if (number>prevNum)

                           { decNum= decNum+number;  }

                       else

                          decNum= decNum-number;  }

//displays the decimal value of the roman numeral

       public static void displayRomanNumeral (String romNum){

               System.out.println ("The Roman numeral "+romNum+" is equal to decimal number"+decNum); }

//displays the number as decimal

           public static void displayDecimalNumber (int decNum){

       System.out.println ("The decimal number is: " + decNum);  } }      

Output:

enter a Roman numeral: MCXIV

The Roman numeral MCXIV is equal to decimal number 1114

Output:

enter a Roman numeral: CCCLIX

The Roman numeral CCCLIX is equal to decimal number 359

Output:

enter a Roman numeral: MDCLXVI

The Roman numeral MDCLXVI is equal to decimal number 1666

You might be interested in
This is tech question related to mobile and PC.
love history [14]

I am guessing the bluetooth process is same as usb proccess. So when i transfered a video via usb and took out the usb (for apple phone), there <u>was</u> a file but when i clicked it it said that the phone isn't plugged in

4 0
3 years ago
Sanford is creating an excel spreadsheet and needs to insert many worksheets to organize his data. What is the limit of the numb
Varvara68 [4.7K]

Answer:

The answer is given below in explanation section.

Explanation:

As asked in the question Sanford is creating an excel spreadsheet and needs to insert many workbooks sheets to organize his data, then what is the limit of the number of worksheets excel con contain.

The excel spreadsheet contains as many worksheets as you want but it is limited by the available memory of your computer and system resources. If you have very little memory then you cannot create many worksheets. If you have memory in GBs then you can create thousands of worksheets.

However, it is noted that to create the worksheet is not limited by Excel but it is limited by avilabe memory and system resources. If you have enough computer memory and resources like CPU power etc, then you can create worksheet as many as you want.

It is also noted that the excel worksheet is limited by its number of rows and number of columns it contains e.g. the total number of rows and columns on a worksheet are 1,048,576 rows by 16,384 columns.

If you want to study more about Excel limitation and specifications, the following link may help you

https://support.office.com/en-us/article/excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3

5 0
3 years ago
Read 2 more answers
For successful completion of an 8-Week course, how often should I visit the course web site to check for new e-mail and any inst
Brilliant_brown [7]

Answer: The course web should be visited daily to check for new e-mail and any instructor announcement.

Explanation:

For any serious-minded and Intellectually inclined individual, who aimed for a successful completion of an 8-Week course, it's imperative for him/her to visit the course web site daily to check for new e-mail and any instructor announcements.

8 0
3 years ago
Using PowerPoint or impress guarantees that your presentation will do which of the following
Molodets [167]
It will show a power point on the files or what u make depending on what u are doing.
4 0
3 years ago
Read 2 more answers
If a fire should break out in your building, which of the following actions is NOT recommended?
pashok25 [27]

The answer would be C) Scream and run

The last thing you want to do during a fire is panic and freak out. Once you start doing that you will usually make rational decisions. If you remain calm and follow procedure you should be fine, in most cases.

7 0
3 years ago
Read 2 more answers
Other questions:
  • How is steering different from turning ? Need help //:
    13·1 answer
  • A server-side extension ________________. provides its services to the web server in a way that is totally transparent to the cl
    13·1 answer
  • Yolanda is writing a document that will provide configuration information regarding the minimum level of security that every sys
    5·1 answer
  • What does a codec do? Choose all that apply.
    5·2 answers
  • The rules on the Internet for how messages are addressed and passed on are called ____ .
    15·1 answer
  • Cómo surge y cuál es el objetivo del observatorio de radio y televisión
    11·1 answer
  • What are the advantages of mine shaft gear and the disadvantaged​
    9·1 answer
  • Which is not and input device , keyboard , joystick, Monitor, Microphone​
    10·2 answers
  • I NEED HEP QUICK
    9·1 answer
  • What is the average value of a loyal customer (VLC) in a target market segment if the average purchase price is $75 per visit, t
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!