please write code in Java language I cant read hand writing

please write code in Java language . I can\'t read hand writing so please copy and past code and show the out put. Thanks for understanding and your help is appreciated

Write a program that takes as input positive integers and converts them into their Roman numeral system equivalents. Check for valid input - your program should handle runtime exceptions caused by invalid input Your program should continue running until the user indicates a desire to quit Besides checking for input validity, your program must check for data out of bounds (as described below) and deal with it in a reliable manner (i.e. don\'t crash and don\'t produce bad output) The Roman numeral system uses the following symbols to represent the numeric values listed below: I 1 V 5 X 10 L 50 C 100 D 500 M 1000 Numbers are formed according to the following rules: Only numbers greater than 0 and up to 3999 are represented (your program should check for this). As in the decimal system, the thousands, hundreds, tens and ones are expressed separately. The numbers 1 - 9 are expressed as: I 1 II 2 III 3 IV 4 V 5 VI 6 VII 7 VIII 8 IX 9 Generally, an \'I\' preceding a \'V\' or \'X\' is subtracted from the second letter\'s value, and you never have more than 3 \'I\'s in a row. Tens and hundreds are done the same way, except that the letters X, L, C and C, D, M are used instead of I, V and X respectively. A sample program run: Hail Caesar! Enter a number to be converted to Roman numerals, or 0 to quit: 1978 That number is: MCMLXXVIII Enter a number to be converted to Roman numerals, or 0 to quit: quit quit is not valid input. Enter a number to be converted to Roman numerals, or 0 to quit: -5 -5 is out of bounds. Please enter a number between 1 and 3999. Enter a number to be converted to Roman numerals, or 0 to quit: 267 That number is CCLXVII Enter a number to be converted to Roman numerals, or 0 to quit: 0 Beware the ides of March!

Solution

Okay so to satisfy all the conditions of the program, we just have to take the input twice, first to validate the input, then to find the Roman Number, if the input not Valid, if again asks to Enter a Number, and if 0 in entered the Program Exits.

Save the file name as Roman.java

Here is the Required Program, this Program satisfies the following Conditions:

import java.util.Scanner;

class Roman{

    public static String IntegerToRoman(int n){

        String roman=\"\";

        int repeat;

        repeat=n/1000;

        for(int i=1; i<=repeat;i++){

            roman=roman+\"M\";

        }

        n=n%1000;

        repeat=n/900;

        for(int i=1; i<=repeat;i++){

            roman=roman+\"CM\";

        }

        n=n%900;

        repeat=n/500;

        for(int i=1; i<=repeat;i++){

            roman=roman+\"D\";

        }

        n=n%500;

        repeat=n/400;

        for(int i=1; i<=repeat;i++){

            roman=roman+\"CD\";

        }

        n=n%400;

        repeat=n/100;

        for(int i=1; i<=repeat;i++){

            roman=roman+\"C\";

        }

        n=n%100;

        repeat=n/90;

        for(int i=1; i<=repeat;i++){

            roman=roman+\"XC\";

        }

        n=n%90;

        repeat=n/50;

        for(int i=1; i<=repeat;i++){

            roman=roman+\"L\";

        }

        n=n%50;

        repeat=n/40;

        for(int i=1; i<=repeat;i++){

            roman=roman+\"XL\";

        }

        n=n%40;

        repeat=n/10;

        for(int i=1; i<=repeat;i++){

            roman=roman+\"X\";

        }

        n=n%10;

        repeat=n/9;

        for(int i=1; i<=repeat;i++){

            roman=roman+\"IX\";

        }

        n=n%9;

        repeat=n/5;

        for(int i=1; i<=repeat;i++){

            roman=roman+\"V\";

        }

        n=n%5;

        repeat=n/4;

        for(int i=1; i<=repeat;i++){

            roman=roman+\"IV\";

        }

        n=n%4;

        repeat=n/1; // or simply repeat=n or i<=n in the condition part of the loop

        for(int i=1; i<=repeat;i++){

            roman=roman+\"I\";

        }

        return roman;

    }

    public static void main(String args[]) throws RuntimeException

    {

               Roman obj=new Roman();

               obj.basic();

              

    }

               void basic() throws RuntimeException

               {

               int a;

               Scanner sc=new Scanner(System.in);

               System.out.println(\"Enter Number to Validate it is a Number\");

               try

               {

               a=sc.nextInt();

               }

               catch(RuntimeException e)

               {

               System.out.println(\"Please Enter a Number!, You have not entered a Number\");

               Roman obj1=new Roman();

               obj1.basic();

               }

               System.out.println(\"Enter Number to convert to Roman and 0 to exit:\");

               a=sc.nextInt();

               if(a!=0)

               {

               go(a);

               }

               else

               {

               System.out.println(\"Thank You\");

               }

               }

               void go(int a)

               {

        System.out.println(\"Number: \"+a+\" in Roman is \"+IntegerToRoman(a));

               System.out.print(\"\ \");

               basic();

               }

              

}

Thank You for using Chegg...

please write code in Java language . I can\'t read hand writing so please copy and past code and show the out put. Thanks for understanding and your help is app
please write code in Java language . I can\'t read hand writing so please copy and past code and show the out put. Thanks for understanding and your help is app
please write code in Java language . I can\'t read hand writing so please copy and past code and show the out put. Thanks for understanding and your help is app
please write code in Java language . I can\'t read hand writing so please copy and past code and show the out put. Thanks for understanding and your help is app

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site