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
What is a BUG in terms of computer programming?
diamong [38]

Answer:

C

Explanation:

4 0
3 years ago
8. SQL, Oracle Report, and Visual Basic are all examples under the
Marat540 [252]
I am pretty sure the answer is the second gen
3 0
2 years ago
How can you check data on devices connected through an iot network?
vampirchik [111]

<em>Internet of Things(IoT)</em> which could be described as a group of interconnected systems or objects which are able to communicate, transmit and exchange data using <em>smart technology</em> and sensors. Data can be checked and monitored on these devices using Dashboards.

  • Dashboards provides a graphical representation of information about interconnected IoT objects or devices. They are produced using data collected from interconnected objects.

  • Since all objects are interconnected, devices use data which are are stored in storage or memory locations. These data are then used to prepare information displayed on dashboards.

Therefore, dashboards provides an interface to view data information about IoT connected devices.

Learn more :brainly.com/question/24958568

6 0
3 years ago
Read 2 more answers
43
pshichka [43]

Answer:

c

Explanation:

5 0
2 years ago
Read 2 more answers
What is the binary number system? ​
Scilla [17]
DescriptionIn mathematics and digital electronics, a binary number is a number expressed in the base-2 numeral system or binary numeral system, which uses only two symbols: typically "0" and "1". The base-2 numeral system is a positional notation with a radix of 2. Each digit is referred to as a bit.
6 0
3 years ago
Other questions:
  • Hey so if an instagram account has an email attached to it but a person no longer has access to that email, how do they get back
    10·1 answer
  • When solving for K, when cell potential is known, what is one of the first steps to follow?
    8·1 answer
  • A program executes 100 billion instructions. It executes on an IBM processor that has an average CPI of 1.2 and a clock frequenc
    15·1 answer
  • 7x+ 2x = 14<br>want is (x)?​
    15·1 answer
  • How can netiquette help you communicate when texting or instant messaging?
    6·1 answer
  • What is the purpose of the 5 Whys Strategy? How could you use the 5 Whys strategy in your day-to-day life? (Site 2)
    5·1 answer
  • The "great big secret" Ohanian talks about is the idea that:
    15·1 answer
  • 1. What was the very first “photo-realistic CGI character” to appear on-screen in a movie (released in 1985)?
    8·2 answers
  • IN WHICH COUNTRY DO THEY LET YOU PLAY MINECRAFT IN SCHOOL?
    8·2 answers
  • I have put the question in twice and I cannot get a answer for it .. this site isn’t great in my view..
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!