Question: Use the attached starter code to design and implement a Roman numeral calculator. Your program should ignore the subtractive Roman numeral notation and only use

Use the attached starter code to design and implement a Roman numeral calculator. Your program should ignore the subtractive Roman numeral notation and only use a purely additive notation in which a number was simply the sum of its digits (4 equals IIII in this notation, not IV). Each number starts with the digit of highest value and ends with the digit of smallest value. The values of the Roman digits are as follows: I 1 V 5 X 10 L 50 C 100 D 500 M 1000 Thus, the number MDCCCCLXXXXVI represents 1996, because 1996 really consists of: 1000+500+100+100+100+100+50+10+10+10+10+5+1. M + D + C + C + C + C + L + X + X + X + X + V + I Your class inputs two Roman numbers as the operands and an arithmetic operator and prints out the result of the operation, also as a Roman number. The arithmetic operators that your program should recognize in the input are +,-,*, and /. These should perform the operations of integer addition, subtraction, multiplication, and division. As shown in the starter code the approach is to convert the Roman numbers into integers, perform the required operation, and then convert the result back into a Roman number for printing. The following might be a sample run of the class:
Enter Operator: +-*/: + Enter operand: MCCXXVI Enter operand: LXVIIII Answer =MCCLXXXXV **You must use the structure provided in the starter code **Your code should accept both lowercase and uppercase letters for Roman numerals. MDCLXVI is the same as mdclxvi Your Roman Calculator should be tested with the following inputs (note your program will fill in the answers): Operator: +-*/: + Enter operand: M Enter operand: mCxV Answer =_________ Operator: +-*/: - Enter operand: XX Enter operand: v Answer =_________ Operator: +-*/ : * Enter operand: x Enter operand: lx Answer =_________ Operator: +-*/: / Enter operand1: dc Enter operand2: x Answer =_________ Operator: +-*/: + Enter operand: mmc Enter operand: lxvii Answer =_________ Operator: +-*/ : - Enter operand: m Enter operand: cxi Answer =_________ Operator: +-*/ : ^ Your operand is bad ... try again:
Operator: +-*/ : + Enter operand: axi bad character Enter operand: xi Enter operand: xi8i bad character Enter operand: xii
COMPLETE THIS CODE!!!
import java.util.Scanner;
public class RomanCalculator {
public static Scanner kbInput = new Scanner(System.in);
public static String doMath(char operator, int firstNum, int secondNum){
/** This method will perform the arithmetic
* indicated by the operator (+-*/),
* invoke convertToRoman to convert answer to Roman number,
* then return answer **/}
public static char getOperator(){
/** Modify this method so when the user enters an invalid operator the
* program will complain and ask the user to enter again
*/ System.out.println("please choose an operator: +,-,*, or /");
return kbInput.nextLine().charAt(0); } public static int getOperands(){
/*This routine should prompt the user to enter Roman number. convertFromRoman needs to be invoked to convert the Roman number to an integer. If the input is invalid (-1 returned from convertFromRoman) then complain and prompt the user again. */}
public static int convertFromRoman(String romanNum){
/** This method will convert Roman number to integer * return -1 when input is invalid ***/}
public static String convertToRoman(int num){
/** This method will convert integer to Roman number **/}
public static void main(String[] args){
// TODO Auto-generated method stub
String result;
do { result = doMath(getOperator(), getOperands(), getOperands()); System.out.println(result); System.out.println("do you want to continue? y/n"); }
while (kbInput.nextLine().charAt(0)=='y');
System.out.println("Have a nice day!"); }}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!