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
pantera1 [17]
3 years ago
14

Write a program that converts a number entered in Roman numerals to decimal. your program should consist of a class, say, Roman.

An object of type Roman should do the following:a. Store the number as a Roman numeral.b. convert and store the number into decimal.c. print the number as a Roman numeral or decimal number as requested by the user.the decimal number values of the Roman numerals are:M 1000D 500C 100L 50X 10V 5I 1d. Your class must contain the method romanToDecimal to convert a Roman numeral into its equivalent decimal numbere. Test your program using the following Roman numerals: CXIV, CCCLIX, and MDCLXVI.
Computers and Technology
1 answer:
arlik [135]3 years ago
3 0

Answer:

The code is given below in Java with appropriate comments

Explanation:

import java.util.*;

public class RomantoDecimal {

    public static void main(String[] args)

    {

         Scanner SC = new Scanner(System.in);

         RomantoDecimal r = new RomantoDecimal();

         System.out.println("Enter a Roman number :");

         // INPUT A ROMAN NUMBER

         String rNum = SC.next();

         // CALL convertToDecimal FOR CONVERSION OF ROMAN TO DECIMAL

         r.convertToDecimal(rNum);

    }

    // M=1000, D=500, C=100, L=50, X=10, V=5, I=1

    public void convertToDecimal(String roamNo)

    {

         int number = 0;

         // TEACK EACH DIGIT IN THE GIVEN NUMBER IN REVERSE ORDER

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

         {

             // FIND OUT WHETHER IT IS 'M' OR NOT

             if (roamNo.charAt(i) == 'M')

             {

                  if (i != 0)

                  { // CHECK WHETHER THERE IS C BEFORE M

                       if (roamNo.charAt(i - 1) == 'C')

                       {

                            number = number + 900;

                            i--;

                            continue;

                       }

                  }

                  number = number + 1000;

             }

             // FIND OUT WHETHER IT IS 'D' OR NOT

             else if (roamNo.charAt(i) == 'D')

             {

                  if (i != 0)

                  {

                  // CHECK WHETHER THERE IS C BEFORE D

                       if (roamNo.charAt(i - 1) == 'C')

                       {

                            number = number + 400;

                            i--;

                            continue;

                       }

                 }

                  number = number + 500;

             }

            // FIND OUT WHETHER IT IS 'C' OR NOT

             else if (roamNo.charAt(i) == 'C')

             {

                  if (i != 0)

                  {

                       if (roamNo.charAt(i - 1) == 'X')

                       {

                            number = number + 90;

                            i--;

                            continue;

                      }

                  }

                  number = number + 100;

             }

             else if (roamNo.charAt(i) == 'L')

             {

                  if (i != 0)

                  {

                       if (roamNo.charAt(i) == 'X')

                       {

                            number = number + 40;

                            i--;

                            continue;

                       }

                  }

                  number = number + 50;

             }

             // FIND OUT WHETHER IT IS 'X' OR NOT

             else if (roamNo.charAt(i) == 'X')

             {

                  if (i != 0)

                  {

                       if (roamNo.charAt(i - 1) == 'I')

                       {

                            number = number + 9;

                            i--;

                            continue;

                       }

                  }

                  number = number + 10;

             }

             // FIND OUT WHETHER IT IS 'V' OR NOT

             else if (roamNo.charAt(i) == 'V')

             {

                  if (i != 0)

                  {

                       if (roamNo.charAt(i - 1) == 'I')

                       {

                            number = number + 4;

                            i--;

                            continue;

                       }

                  }

                  number = number + 5;

             }

            else // FIND OUT WHETHER IT IS 'I' OR NOT

             {

                  number = number + 1;

             }

         }// end for loop

         System.out.println("Roman number: " + roamNo + "\nIts Decimal Equivalent: " + number);

    }

}

You might be interested in
6. At age 17, what was Minhaj's definition of the American Dream?
marta [7]
“To me being American means having the opportunity to reach for our goals. It’s accepting where we come from while embracing our dreams and where we’re headed. It’s what makes America great.”
3 0
3 years ago
Big data refers to huge collections of data that are difficult to process, analyze, and manage using conventional data tools. It
Helga [31]

Answer:

3rd;mobile;velocity;NoSQL;out;shards;dynamic;schema-less;value;column;Hadoop;MapReduce.

Explanation:

Big data refers to huge collections of data that are difficult to process, analyze, and manage using conventional data tools. It is a core component of the 3rd platform, which also includes cloud computing, mobile devices, and social networking. The five Vs of big data are high volume, high velocity, diversified variety, unknown veracity, and low-density value. Although SQL and relational databases can be used for big datasets, a collection of alternative tools referred to as NoSQL has become popular. These tools work well when databases scale out (horizontally) and when databases are broken into subsets called shards. Modern database tools also handle dynamic scaling as devices are added when additional capacity is required. NoSQL tools are sometimes said to create schema-less databases, but they usually have some type of structure, though it may be more flexible than the relational model. A key-value data model provides each data element with a key. A column-oriented data model makes it easy to access data stored in similar fields, rather than in individual records. Two very popular NoSQL tools include Hadoop, which is a big data file system, and MapReduce which sends processing logic to the data, rather than bringing the data to the computer that performs the processing.

4 0
2 years ago
What is the most efficient way to include a space after each paragraph
3241004551 [841]

To skip a line, then write the rest like this!


See? Good spacing, right?

4 0
2 years ago
How do you do 3.4.5 Add parentheses for code hs? I need answers please
stich3 [128]
I don’t know but i hope someone gives u the answer
7 0
2 years ago
Read 2 more answers
You are reviewing the style sheet code written by a colleague and notice several rules that are enclosed between the /* and */ c
Flauer [41]

Answer:

Nothing will happen.

Explanation:

The rules written between /* and */ will be ignored because /* and */ are the standard way of writing comment in a style sheet code. So, whatever fall in between them will be ignored during rendering of the page.

7 0
3 years ago
Other questions:
  • What is the order of arrangement of files and folders on a computer?
    15·1 answer
  • How might writing an online journal be different than writing in a paper one ​
    15·2 answers
  • WILL GIVE BRAINLIEST TO FIRST AND BEST ANSWER!
    10·1 answer
  • Describe one example of how technology assits people with data and sample collection
    14·2 answers
  • Write syntactically correct Javascript code to sort an array of sub-arrays containing integers using the sort and reduce array f
    11·1 answer
  • A score of 3 or better on the exam administered at the end of which type of course usually means that you will earn college cred
    6·1 answer
  • Which of the following does not use a Graphic User Interface?
    14·1 answer
  • How to create an app on app store please its not a joke, if someone knows tell me how
    15·1 answer
  • Explains why we use tables in documents; and is at least three sentences long in word office 360​
    15·1 answer
  • Your friend Cameron’s little sister is visually impaired. Cameron is worried that his sister will not be able to use technology
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!