F
F
Fedor unknown2019-09-03 11:24:40
Java
Fedor unknown, 2019-09-03 11:24:40

How to write a calculator that can work with Roman numerals?

Hey!
There is a task: to write a calculator
* The calculator can work with Arabic and Roman numbers
* must accept numbers from 1 to 10 inclusive, no more than
* The calculator can only work with integers
My shit "code"

import java.util.Scanner;

public class MainClass {
    public static void main(String[] args) {
        RomeNumbers rome = new RomeNumbers();
        int value1 = 0;
        int value2 = 0;
        String operation = null;

        System.out.println("Введите 2  целых числа: ");
        Scanner scanner = new Scanner(System.in);
        if (value1 > 0 || value1 < 10) {
            value1 = scanner.nextInt();
            operation = scanner.next();
            value2 = scanner.nextInt();
        }
        if (operation.equals("+")) {
            System.out.println(value1 + value2);
        }

        if (operation.equals("-")) {
            System.out.println(value1 - value2);
        }

        if (operation.equals("*")){
            System.out.println( value1 * value2);
        }

        if (operation.equals("/")){
            System.out.println(value1 / value2);
        }
        else {
            System.out.println("error!");
        }

    }
}

public class RomeNumbers {
    int I = 1;
    int II = 2;
    int III = 3;
    int IV = 4;
    int V = 5;
    int VI = 6;
    int VII = 7;
    int VIII = 8;
    int IX = 9;
    int X = 10;


}

Question: What to do with Roman numerals and how to do it all humanly?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
irishmann, 2019-09-03
@irishmann

L, C, D, M are not taken into account in your class. You need to first translate into Arabic numerals, perform an operation, then translate the result back into Roman numerals. Look here .

B
Bonce, 2019-09-05
@Bonce

There was a similar question recently. Look on the toaster. There the ready code was thrown off.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question