Question

Program Info: Write a program that accepts a year written as a four-digit Arabic (ordinary) numeral...

Program Info: Write a program that accepts a year written as a four-digit Arabic (ordinary) numeral and outputs the year written in Roman numerals. Important Roman numerals are V for 5, X for 10, L for 50, C for 100, D for 500, and M for 1,000. Recall that some numbers are formed by using a kind of subtraction of one Roman “digit”; for example, IV is 4 produced as V minus I, XL is 40, CM is 900, and so on. A few sample years: MCM is 1900, MCML is 1950, MCMLX is 1960, MCMXL is 1940, MCMLXXXIX is 1989. Assume the year is between 1000 and 3000. Your program should include a loop that lets the user repeat this calculation until the user says she or he is done.

DO not simply copy and paste other solutions from chegg or look for the solution within the textbook, don't use any advanced terminology to code this program. Use only basic sytax, loops and if else statements are allowed. Use the switch statement if possible.

Do this and automatically receive a thumbs up!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

class Main

{

String Roman_Conversion(int num)

{

String res=""; //varaible declaration

int i,j,tp;

int arr[]={1000,900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};

String romsys[]={"M","CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};

for(j=0; j<arr.length; j++)

{

tp=num/arr[j]; //converting it to Roman

for(i=1; i<=tp; i++)

{

res=res + romsys[j];

}

num=num%arr[j];

}

return res; //returning the roman year value

}

public static void main(String args[])

{

Main obj=new Main(); //object of the class

Scanner sc=new Scanner(System.in);

String s; //variable declaration

int ch,yr;

do

{

System.out.println();

System.out.println("Roman_Conversion");

System.out.println("Enter the year");

yr=sc.nextInt(); //accepting input from user

s=obj.Roman_Conversion(yr);

System.out.println("Roman Year : "+s);

System.out.println("Do you want to continue?");

System.out.println("1.Yes");

System.out.println("2.No");

System.out.println("Enter your choice");

ch=sc.nextInt();

}while(ch!=2);

}

}


OUTPUT

Roman Conversion nter the year 1950 Roman Year : MCML Do vou want to continue? 1 . Yes 2.No Enter vour choice Roman Conversio

Add a comment
Know the answer?
Add Answer to:
Program Info: Write a program that accepts a year written as a four-digit Arabic (ordinary) numeral...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write up a detailed solution to the problem: Design a program to convert a Roman numeral...

    Write up a detailed solution to the problem: Design a program to convert a Roman numeral to a decimal number. The program should read a Roman numeral. You may read it as a string or one character at a time. Do the conversion and then output the decimal number. Here are the “letters” you need to know: Symbol =   Value I   = 1 V =   5 X =   10 L =   50 C =   100 D =   500 M   =...

  • Write a program that will accept from the user a text file containing hurricane data along...

    Write a program that will accept from the user a text file containing hurricane data along with an output filename. The data consists of the year, the number of storms, the number of hurricanes, and the damage in millions of US Dollars. The first line contains the word “Years” followed by the first year listed and the last year listed separated by tabs. The following lines contain the data separated by tabs. A sample text file is available in this...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT