Help with Roman Numeral Converter

Program intended to convert roman numerals to arabic and arabic to ro

Page 1 of 1

10 Replies - 7480 Views - Last Post: 11 January 2010 - 08:29 PM Rate Topic: -----

#1 kidwithaneedforspeed  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 08-January 10

Help with Roman Numeral Converter

Posted 08 January 2010 - 08:48 PM

import java.util.Scanner;
 public class RGRomanNumerals{
	static Scanner sc=new Scanner(System.in);
	static int I = 1;
	static int V = 5;
	static int X = 10;
	static int L = 50;
	static int C = 100;
	static int D = 500;
	static int M = 1000;  
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	public static void main(String[] args){
		System.out.println("Please choose and option:\n Press 1 to convert Roman numerals to Arabic\n Press 2 to convert Arabic to Roman numerals");
		int a = sc.nextInt();
		if (a == 1){
			RTA();	
		}if (a == 2){
			ATR();
		}}
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////   
	public static void RTA(){
		System.out.println("Please enter the Roman Numeral.");
		String b = sc.nextLine();
	}
////////////////////////////////////////////////////////////////////////////////////////////EXPERIMENT AREA!!!!!!!!!!!!!!!!!!!!>>>>>>>>>>>>>>>>>>


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
	public static void ATR(){	
		System.out.println("Please enter an Arabic Numeral between 1 - 3999.");
		for (int a=0; a<1000; a++){
		int b = sc.nextInt();
		if (b >= 1000 || b<=3000)
		{
		int e = b/1000;
		if (e == 1){
			System.out.print("M");
			b = b - 1000;
		}if (e == 2){
			System.out.print("MM");
			b = b - 2000;
		}if (e == 3){
			System.out.print("MMM");
			b = b - 3000;
		}if (e == 4){
			System.out.println("\nProcess completed.");

			a = 1337;
		}}
			if (b >= 100 || b<=999)
			{
			int e = b/100;
		   if (e == 1){
				System.out.print("C");
				b = b - 100;
			}if (e == 2){
				System.out.print("CC");
				b = b - 200;
			}if (e == 3){
				System.out.print("CCC");
				b = b - 300;
			}if (e == 4){
				System.out.print("CD");
				b = b - 400;
			}if (e == 5){
				System.out.print("D");
				b = b - 500;
			}if (e == 6){
				System.out.print("DC");
				b = b - 600;
			}if (e == 7){
				System.out.print("DCC");
				b = b - 700;
			}if (e == 8){
				System.out.print("DCCC");
				b = b - 800;
			}if (e== 9){
				System.out.print("CM");
				b = b - 900;
			}}
			if (b >= 10 || b <= 90)
			{
				int e = b/10;
				if (e == 1){
					System.out.print("X");
					b = b - 10;
				}if (e == 2){
					System.out.print("XX");
					b = b - 20;
				}if (e == 3){
					System.out.print("XXX");
					b = b - 30;
				}if (e == 4){
					System.out.print("XL");
					b = b - 40;
				}if (e == 5){
					System.out.print("L");
					b = b - 50;
				}if (e == 6){
					System.out.print("LX");
					b = b - 60;
				}if (e == 7){
					System.out.print("LXX");
					b = b - 70;
				}if (e == 8){
					System.out.print("XXC");
					b = b - 80;
				}if (e == 9){
					System.out.print("XC");
					b = b - 90;
				}}
			if (b >= 1 || b<=9)
				{if (b == 1){
				System.out.print("I");b = b - 1;
				}if (b == 2){
				System.out.print("II");b = b - 2;
				}if (b == 3){
				System.out.print("III");b = b - 3;
				}if (b == 4){
				System.out.print("IV");b = b - 4;
				}if (b == 5){
				System.out.print("V");b = b - 5;
				}if (b == 6){
				System.out.print("VI");b = b - 6;
				}if (b == 7){
				System.out.print("VII");b = b - 7;
				}if (b == 8){
				System.out.print("VIII");b = b - 8;
				}if (b == 9){
				System.out.print("IX");b = b - 9;
				}}if (b == 0){
					System.out.println("\n");
					
				}
		}
	}
}
///////////////////////////////////////////////////////////
/////i can't get the roman numeral to arabic code at all.////////
///// i know use if statements but i always doesn't work./////////////////////
////// Please help.//////////////////////////////////////////////////
//////////thank you. thank you. thank you. thank you. thank you./


*Mod Edit: Added code tags*

This post has been edited by OliveOyl3471: 09 January 2010 - 09:20 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Help with Roman Numeral Converter

#2 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: Help with Roman Numeral Converter

Posted 08 January 2010 - 09:14 PM

Welcome to DIC!

Please edit you post and add the :code: tags around your code.

Thanks!
Was This Post Helpful? 0
  • +
  • -

#3 OliveOyl3471  Icon User is offline

  • Everybody's crazy but me!
  • member icon

Reputation: 135
  • View blog
  • Posts: 6,581
  • Joined: 11-July 07

Re: Help with Roman Numeral Converter

Posted 09 January 2010 - 09:24 PM

*Moved to Java*
Was This Post Helpful? 0
  • +
  • -

#4 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon

Reputation: 2965
  • View blog
  • Posts: 11,222
  • Joined: 15-July 08

Re: Help with Roman Numeral Converter

Posted 09 January 2010 - 09:26 PM

What seems to be the problem?
Was This Post Helpful? 0
  • +
  • -

#5 OliveOyl3471  Icon User is offline

  • Everybody's crazy but me!
  • member icon

Reputation: 135
  • View blog
  • Posts: 6,581
  • Joined: 11-July 07

Re: Help with Roman Numeral Converter

Posted 09 January 2010 - 09:47 PM

Quote

//i can't get the roman numeral to arabic code at all.


If you do a search of the site, I'm sure you can find a solution for this problem. Here's one in C++
http://www.dreaminco...h...st&p=580208

Though I'm not sure it works properly 100% of the time, it will at least give you an idea of how this might be done. :)
Was This Post Helpful? 0
  • +
  • -

#6 erik.price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 486
  • View blog
  • Posts: 2,690
  • Joined: 18-December 08

Re: Help with Roman Numeral Converter

Posted 09 January 2010 - 11:20 PM

Please explain your question in the body of the post, not the title. If you put the question in the title only, it'll get cut off.
Was This Post Helpful? 1
  • +
  • -

#7 kidwithaneedforspeed  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 08-January 10

Re: Help with Roman Numeral Converter

Post icon  Posted 11 January 2010 - 07:44 PM

import java.util.Scanner;
public class RGRomanNumerals{
	static Scanner sc=new Scanner(System.in);
	static int I = 1;
	static int V = 5;
	static int X = 10;
	static int L = 50;
	static int C = 100;
	static int D = 500;
	static int M = 1000;  
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	public static void main(String[] args){
		System.out.println("Please choose and option:\n Press 1 to convert Roman numerals to Arabic\n Press 2 to convert Arabic to Roman numerals");
		int a = sc.nextInt();
		if (a == 1){
			RTA();	
		}if (a == 2){
			ATR();
		}}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////   
	public static void RTA(){
		System.out.println("Please enter the Roman Numeral.");
		String b = sc.nextLine();
	}
////////////////////////////////////////////////////////////////////////////////////////////EXPERIMENT AREA!!!!!!!!!!!!!!!!!!!!>>>>>>>>>>>>>>>>>>


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
	public static void ATR(){	
		System.out.println("Please enter an Arabic Numeral between 1 - 3999.");
		for (int a=0; a<1000; a++){
		int b = sc.nextInt();
		if (b >= 1000 || b<=3000)
		{
		int e = b/1000;
		if (e == 1){
			System.out.print("M");
			b = b - 1000;
		}if (e == 2){
			System.out.print("MM");
			b = b - 2000;
		}if (e == 3){
			System.out.print("MMM");
			b = b - 3000;
		}if (e == 4){
			System.out.println("\nProcess completed.");

			a = 1337;
		}}
			if (b >= 100 || b<=999)
			{
			int e = b/100;
		   if (e == 1){
				System.out.print("C");
				b = b - 100;
			}if (e == 2){
				System.out.print("CC");
				b = b - 200;
			}if (e == 3){
				System.out.print("CCC");
				b = b - 300;
			}if (e == 4){
				System.out.print("CD");
				b = b - 400;
			}if (e == 5){
				System.out.print("D");
				b = b - 500;
			}if (e == 6){
				System.out.print("DC");
				b = b - 600;
			}if (e == 7){
				System.out.print("DCC");
				b = b - 700;
			}if (e == 8){
				System.out.print("DCCC");
				b = b - 800;
			}if (e== 9){
				System.out.print("CM");
				b = b - 900;
			}}
			if (b >= 10 || b <= 90)
			{
				int e = b/10;
				if (e == 1){
					System.out.print("X");
					b = b - 10;
				}if (e == 2){
					System.out.print("XX");
					b = b - 20;
				}if (e == 3){
					System.out.print("XXX");
					b = b - 30;
				}if (e == 4){
					System.out.print("XL");
					b = b - 40;
				}if (e == 5){
					System.out.print("L");
					b = b - 50;
				}if (e == 6){
					System.out.print("LX");
					b = b - 60;
				}if (e == 7){
					System.out.print("LXX");
					b = b - 70;
				}if (e == 8){
					System.out.print("XXC");
					b = b - 80;
				}if (e == 9){
					System.out.print("XC");
					b = b - 90;
				}}
			if (b >= 1 || b<=9)
				{if (b == 1){
				System.out.print("I");b = b - 1;
				}if (b == 2){
				System.out.print("II");b = b - 2;
				}if (b == 3){
				System.out.print("III");b = b - 3;
				}if (b == 4){
				System.out.print("IV");b = b - 4;
				}if (b == 5){
				System.out.print("V");b = b - 5;
				}if (b == 6){
				System.out.print("VI");b = b - 6;
				}if (b == 7){
				System.out.print("VII");b = b - 7;
				}if (b == 8){
				System.out.print("VIII");b = b - 8;
				}if (b == 9){
				System.out.print("IX");b = b - 9;
				}}if (b == 0){
					System.out.println("\n");
					
				}
		}
	}
}
///////////////////////////////////////////////////////////
/////i can't get the roman numeral to arabic code at all.////////
///// i know use if statements but i always doesn't work./////////////////////
////// Please help.//////////////////////////////////////////////////
//////////thank you. thank you. thank you. thank you. thank 


Was This Post Helpful? 0
  • +
  • -

#8 erik.price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 486
  • View blog
  • Posts: 2,690
  • Joined: 18-December 08

Re: Help with Roman Numeral Converter

Posted 11 January 2010 - 07:46 PM

Could you please post your question in the body of your post instead of the title? This is what happens when you post it there:

Quote

Arabic To Roman Works But I Have No Clue How To Do It..... Could Someo

Was This Post Helpful? 0
  • +
  • -

#9 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon

Reputation: 2965
  • View blog
  • Posts: 11,222
  • Joined: 15-July 08

Re: Help with Roman Numeral Converter

Posted 11 January 2010 - 07:47 PM

I believe you posted this exact problem here a while ago, and we told you then, "if you have a problem with the code, let us know", but we do not do chunks of code at a time for you, just how to make it better, so give it a good, honest stab, and when you do, then ask us!

Edit: fixed.

This post has been edited by Dogstopper: 11 January 2010 - 08:33 PM

Was This Post Helpful? 1
  • +
  • -

#10 erik.price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 486
  • View blog
  • Posts: 2,690
  • Joined: 18-December 08

Re: Help with Roman Numeral Converter

Posted 11 January 2010 - 07:57 PM

@dogstopper yep, here: http://www.dreaminco...h...=148949&hl= Notice how I say the same thing in both threads.
Was This Post Helpful? 0
  • +
  • -

#11 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Help with Roman Numeral Converter

Posted 11 January 2010 - 08:29 PM

Topics merged
Avoid duplicated topics :angry:
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1