Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Hi, need help with this assigment ( Interfaces and Polymorphism ) Had the Roman Empire never fallen, today we might be using Roman numerals instead

Hi, need help with this assigment

(Interfaces and Polymorphism)

Had the Roman Empire never fallen, today we might be using Roman numerals instead of the familiar Arabic ones (0..9). Naturally, there would be a great demand for Roman-Numeral-based calculators. This assignment is to design and implement object-oriented software for such a calculator. The calculator must be able to perform multiplication, division, modulus, addition, and subtraction operations on roman number operands, where a roman number is a valid sequence of Roman Numerals. Make sure you follow all the directions below, explicitly.

I. Roman Numerals

A numeral is a symbol that represents a number. Each letter used in Roman Numerals stands for a different number:

Roman Numeral

Number

I

1

V

5

X

10

L

50

C

100

D

500

M

1000

A string of numerals means that their values should be added together.

Ex. XXX = 10 + 10 + 10 = 30, and LXI = 50 + 10 + 1 = 61.

If a smaller value is placed before a larger one, we subtract instead of adding.

Ex. IV = 5 - 1 = 4

Use these rules to convert a number from Roman numerals to Arabic numerals, converting one numeral at a time, left-to-right.

FYI, here are the official rules for subtracting letters:

Subtract only powers of ten, such as I, X, or C. Writing VL for 45 is not allowed: write XLV instead.

Subtract only a single letter from a single numeral. Write VIII for 8, not IIX; 19 is XIX, not IXX.

Don't subtract a letter from another letter more than ten times greater. This means that you can only subtract I from V or X, and X from L or C, so for example 1999 is MCMXCIX, and not MIM.

Use these additional rules to convert an Arabic number to Roman numerals, again converting one digit at a time.

Ex. 982 = 900 + 80 + 2

= CM + LXXX + II

= CMLXXXII

The RomanNumeral Interface

Begin by creating a Java interface to represent a Roman Numeral. Your interface will specify two methods one to return the value of a Roman Numeral and another that returns a String representation of a numeral

The I, V, X, L, C, D, and M Classes

Create a class for each of the above numerals. These classes must all implement your RomanNumeral interface.

The RomanNumber Class

Create a class to model a RomanNumber, which is a valid series of Roman numerals.

You may implement the RomanNumber as either an array-of-RomanNumerals or an arraylist-of-RomanNumerals, your choice. Either one. If you choose an array, assume a maximum size of 20

Your class will have these methods:

A constructor

A method that adds a RomanNumeral to this RomanNumber (optional)

A method that converts a Roman Number to Arabic and returns it as an int

A method that converts an Arabic Number to Roman and returns it as a String

An overridden toString() method that returns a string representation of a Roman Number

The RomanNumeralCalculator Class

This class has a default constructor, and a compute method that performs an arithmetic operation (*,/,%,+,-) on two Roman Numbers and returns the result as a String in this general form:

XCIII XXXIX = LIV

93 39 = 54

Make sure your calculator class depends on the RomanNumber class only and not on any of the individual RomanNumeral classes

If you are doing this right, your calculator class should not have to be modified in any way if new Roman Numerals were to be invented in the future (e.g., maybe a symbol for 5000 or 10000). That is main benefit of using Java interfaces and precisely why they were invented.

The Test Class

Your test class will read and process arithmetic operations from a data file which I will supply. Each operation will have the left-hand Roman Number operand, an operator, and the right-hand Roman Number operand (separated by spaces)

Example: XCIII XXXIX

Additional Project Specifications

Assume correct input

All Roman Number inputs will be positive integers

All operations produce integer results

Although the result of an operation will never be 0 (the Romans did not have a zero numeral), it may be a negative integer

All output must include the input operation and the result in both Roman and Arabic Numerals, as returned by the calculator

E.g. XCIII XXXIX = LIV

93 39 = 54

The largest number we can represent using Roman Numerals is MMMCMXCIX (3999). If the result of a calculation is greater than 3999 (or less than -3999), simply print the message Roman Numeral Overflow

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions