Purchase Solution

Writing Programs in Java

Not what you're looking for?

Ask Custom Question

The programming assignment for this module is programming exercise #7 on pages 861 and 862, with the following modifications.

- For part 'a' the source code for class Roman is attached to this assignment. You do not have to include the method decimalToRoman as you modify this class. Also, class Roman is not used in your test program.

- In part 'b' be sure to throw exceptions for the conditions specified when subtracting and dividing. The Roman's grasp of math was very limited (why else would they have developed such an awkward system for recording numbers?) and never considered negative numbers. Basically all they did was count things.

- While your program will only use the ExtendedRoman class you must submit three files for this assignment: Roman, ExtendedRoman, and your test program.

Source code for class Roman: Roman.java (original source code attached)

Here is the assignment as written in the book:

a.) Modify the definition of the class Roman so that the data members are declared as protected. Also incluse the method decimalToRoman, which converts the decimal number (the decimal number must be a positive integer) to an equivalent Roman numeral format. Write the definition of the method decimalToRoman. Your definition of the class Roman must contain the method toString, which returns the string containing the number in Roman format. For simplicity, we assume that only the letter I can appear in front of another letter and that it appears only in front of the letters V and X. For example, 4 is represented as IV, 9 is represented as IX, 39 is represented as XXXIX, and 49 is represented as XXXXIX. Also, 40 is represented as XXXX, 190 is represented as CLXXXX, so on.

b.) Derive the class ExtendedRoman from the class Roman to do the following. In the class ExtendedRoman, include the methods add, subtract, multiply, and divide so that arithmetic operations can be performed on Roman numerals.
To add (subtract, multiply, or divide) Roman numerals, add (subtract, multiply, or divide, respectively) their decimal representations and then convert the result to the Roman numeral format. For subtraction, if the first number is smaller than the second number, throw the exception, "Because the first number is smaller than the second, the numbers cannot be subtracted." Similarly, or division, the numerator must be larger than the denominator.

c.) Write the definition of the methods add, subtract, multiply, and divide as described in part B. Also, your definition of the class ExtendedRoman must contain the method toString that returns the string containing the number in Roman format.

d.) Write a program to test various operations on your class ExtendedRoman.

Attachments
Purchase this Solution

Solution Summary

The following program helps write various programs in Java.

Purchase this Solution


Free BrainMass Quizzes
Basic Networking Questions

This quiz consists of some basic networking questions.

Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.

C# variables and classes

This quiz contains questions about C# classes and variables.

Javscript Basics

Quiz on basics of javascript programming language.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.