IN JAVA LANGUAGE PLEAE! i have the code to this required project and it wont com
ID: 3590014 • Letter: I
Question
IN JAVA LANGUAGE PLEAE!
i have the code to this required project and it wont compile, can someone run it and tell me what my error is? thanks
Write a program to convert an integer value (positive or negative number to a roman number. Study the following document by your next lab activity. You must use methods and conditional statements to do the conversion. At the begging of the next week lab you will be give some integer values to convert to roman numbers as the part of the grade for the lab activity.
You will be asked to show the algorithm that you have created. .
Requirements:
Yourprogrammustoutputthedescriptionoftheprogram.Youmustcreatea method called description.
Createamethodcalledromanthatacceptsanintegervalueasitsparameter and returns its roman equivalent
Youmustasktheuserhowmanytimeshe/shewantstousetheapp
Youmusthaveamethodcalledromanthatacceptsanintegervalueasits
parameter and returns a string representing the given number
Youmusthaveamethodcalledstart
Yourmainmethodcanonlyhavetwolinesofcode.
CreateamethodcalledbirthdaythatacceptsaScannerobjectasitsparameter,
this method should ask the user for the month, day and the year of the person birthday, convert it to roman numbers and display it on the screen. You must prompt the user for the month, day and year.
You must generate the exact same output as the following. Sample output:
******** This program converts your birthday to its equivalent roman numbers *******
How many times do you want to repeat this program: 3
Enter your name: Mary
Hi Mary let’s start
Enter the month of your birthday: 12
Enter the day of your birthday: 12
Enter the year of your birthday: 2012
Your birthday in Roman is: XII /XII / MMXII
Enter your name: Alex
Hi Alex let’s start
Enter the month of your birthday: 8
Enter the day of your birthday: 28
Enter the year of your birthday: 1996
Your birthday in Roman is: VIII /XXVIII / MCMXCVI Enter your name: Jack
Hi Jack let’s start
Enter the month of your birthday: 5
Enter the day of your birthday: 18
Enter the year of your birthday: 2004
Your birthday in Roman is: V /XVIII / MMIV
THIS IS WHAT I HAVE:
import java.util.Scanner;
public class convert2Roman
{
public static void main (String[] args)
{
Scanner kb = new Scanner(System.in);
description();
start(kb);
}
public static void description()
{
System.out.println("******** This program converts your birhtday to its");
System.out.println("equivalent roman numbers ********");
}
//will accept an integer value as its parameter
//returns its roman equivilance
public static void Roman(int num,int count)
{
//if statements go here for all 13 conditions
//if statements go here for all 13 conditions
if (num <1 || num>3999)
{
System.out.println("Invalid number");
}
String s = " ";
if (num >= 1000)
{
count = num/1000;
for (int a = 1; a <= count; a++)
{
s += "M";
}
num = num%1000;
}
else if (num >= 900)
{
count = num/900;
for (int b = 1 ;b >= count; b++)
{
s += "CM";
}
num =num% 900;
}
else if (num >= 500)
{
count = num/500;
for (int c = 1; c >= count ; c++)
{
s += "D";
}
num =num% 500;
}
else if (num >= 400)
{
count = num/400;
for (int d = 1; d >= count; d++)
{
s += "CD";
}
num =num% 400;
}
else if (num >= 100)
{
count = num/100;
for (int e = 1; e >=count; e++)
{
s += "C";
}
num =num%100;
}
else if (num >= 90)
{
count = num/90;
for (int f = 1; f >= count; f++)
{
s += "XC";
}
num =num%90;
}
else if (num >= 50)
{
count = num/50;
for (int g = 1; g >= count; g ++)
{
s += "L";
}
num =num% 50;
}
else if (num >= 40)
{
count = num/40;
for (int h = 1; h >= count; h++)
{
s += "XL";
}
num=num%40;
}
else if (num >= 10)
{
count = num/10;
for (int i = 1; i>= count; i++)
{
s += "X";
}
num =num%10;
}
else if (num >= 9)
{
count = num/9;
for (int j = 1; j>=count; j++)
{
s += "IX";
}
num=num%9;
}
else if (num >= 5)
{
count = num/5;
for (int k = 1; k >= count; k++)
{
s += "V";
}
num =num%5;
}
else if (num >= 4)
{
count = num/4;
for (int l = 1 ; l >= count; l++)
{
s += "IV";
}
num =num%4;
}
else if (num >= 1)
{
count = num/1;
for (int m = 1; m >= count; m++)
{
s += "I";
}
num =num%1;
}
}
//you need to ask user how many times he/she wants to use the app
public static void start(Scanner kb)
{
System.out.print("How many times do you wish to use this app: ");
int times = kb.nextInt();
for (int i = 1; i<= times; i++)
{
//Roman(i);
getInfo(kb);
}
}
//Ask user for name
//ask for birthday
//get roman in this
public static void getInfo(Scanner kb)
{
//ask user for the month of birthday
System.out.println("Enter your name: ");
String name = kb.nextLine();
System.out.println("Hi "+name+" let's start");
System.out.println("Enter the month of your birthday: ");
int month = kb.nextInt();
//String bday1 = Roman(month);
System.out.print("Enter the day of your birthday: ");
int day = kb.nextInt();
//String bday2 = Roman(day);
System.out.print("Enter the year of your birthday: ");
int year =kb.nextInt();
//String bday3 = Roman(year);
System.out.print("Your birthday in roman is: ");
//System.out.println(bday1+"/" + bday2 + "/" + bday3);
System.out.println(Roman(month)+"/"+ Roman(day)+"/"+ Roman(year));
}
}
Explanation / Answer
import java.util.Scanner;
public class Main //convert2Roman
{
public static void main (String[] args)
{
Scanner kb = new Scanner(System.in);
description();
start(kb);
}
public static void description()
{
System.out.println("******** This program converts your birhtday to its");
System.out.println("equivalent roman numbers ********");
}
//will accept an integer value as its parameter
//returns its roman equivilance
public static String Roman(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;
}
//you need to ask user how many times he/she wants to use the app
public static void start(Scanner kb)
{
System.out.print("How many times do you wish to use this app: ");
int times = kb.nextInt();
for (int i = 1; i<= times; i++)
{
//Roman(i);
getInfo();
}
}
//Ask user for name
//ask for birthday
//get roman in this
public static void getInfo()
{
Scanner kb = new Scanner(System.in);
//ask user for the month of birthday
System.out.print("Enter your name: ");
String name = kb.nextLine();
System.out.println("Hi "+ name +" let's start");
System.out.print("Enter the month of your birthday: ");
int month = kb.nextInt();
//String bday1 = Roman(month);
System.out.print("Enter the day of your birthday: ");
int day = kb.nextInt();
//String bday2 = Roman(day);
System.out.print("Enter the year of your birthday: ");
int year =kb.nextInt();
//String bday3 = Roman(year);
System.out.print("Your birthday in roman is: ");
//System.out.println(bday1+"/" + bday2 + "/" + bday3);
System.out.println(Roman(month)+"/"+ Roman(day)+"/"+ Roman(year));
}
}