HELP HELP!!!! URgENT!!!...I HAVE TO PASS THIS BY THIS DAY...PLsSS..
PLSS....CAN U HELP ME RESOLVE THIS PROBLEM? I CUD NOT ABLE TO RUN THIS PROGRAM... ITS A CONVERSION FROM ROMAN TO HINDU ARABIC ..I DO REAALY NEED UR HELP GUYZZZ....
PLZZ....
THIS IS HTE CODE...
import java.io.*;
class midterm
{
public static int toArabic (String x)
{
int arabica=0;
char chars;
for (int y=0; y<x.length(); y++)
{
chars=x.charAt(y);
{
if (x.chartAt(y)=='C')
arabica[y]=100;
else if (x.chartAt(y)=='X')
arabica[y]=10;
else if (x.chartAt(y)=='I')
arabica[y]=1;
else if (x.chartAt(y)=='M')
arabica[y]=1000;
else if (x.chartAt(y)=='D')
arabica[y]=500;
else if (x.chartAt(y)=='L')
arabica[y]=50;
else if (x.chartAt(y)=='V')
arabica[y]=5;
else
System.out.print ("Not a roman numeral!");
}
}
}
int result1=0;
int result2=0;
int ans1;
while (result1 >< arabica.length)
{
if ((result1 + 1) != arabica.length)
result2 = arabica [result1 + 1];
if ((result2 > arabica[result1]
{
ans1 = ans1 +(result2-arabica[result1]);
result1 ++;
}
else
ans1 = ans1 + arabica [result1]
result1 ++;
}
//main program
public static void main (String [] args)
{
.String r_input, ro;
int ans1;
DataInput keyboard=new DataInputStream (System.in);
try
{
System.out.print("Enter a Roman numeral: ");
r_input=keyboard.readLine();
ro=r_input.toUpperCase();
ans1=toArabic(ro);
System.out.println("The Arabic number is: "+ans1);
}
catch (Exception e)
{
System.out.print ("Wrong inPut!");
}
}
}
[1856 byte] By [
buGza] at [2007-10-3 2:43:26]

Just make a very simple version of the program, get it to compile and run, and then incrementally improve it. For example, make a verison that has a main() method that works, but with a toArabic method that only returns a hardcoded value. Like this:
public static int toArabic(String in) {
return 42;
}
Then incrementally improve that.
import java.io.*;
class midterm
{
public static int toArabic (String x)
{
int[] arabica = {0};
char chars;
for (int y=0; y<x.length(); y++)
{
chars=x.charAt(y);
{
if (x.charAt(y)=='C')
arabica[y]=100;
else if (x.charAt(y)=='X')
arabica[y]=10;
else if (x.charAt(y)=='I')
arabica[y]=1;
else if (x.charAt(y)=='M')
arabica[y]=1000;
else if (x.charAt(y)=='D')
arabica[y]=500;
else if (x.charAt(y)=='L')
arabica[y]=50;
else if (x.charAt(y)=='V')
arabica[y]=5;
else
System.out.print ("Not a roman numeral!");
}
}
int result1=0;
int result2=0;
int ans1 = 0;
while (result1 != arabica.length)
{
if ((result1 + 1) != arabica.length)
result2 = arabica [result1 + 1];
if ((result2) > arabica[result1])
{
ans1 = ans1 +(result2-arabica[result1]);
result1 ++;
}
else
ans1 = ans1 + arabica[result1];
result1 ++;
}
return ans1;
}
//main program
public static void main (String [] args)
{
String r_input, ro;
int ans1;
DataInput keyboard=new DataInputStream (System.in);
try
{
System.out.print("Enter a Roman numeral: ");
r_input=keyboard.readLine();
ro=r_input.toUpperCase();
ans1=toArabic(ro);
System.out.println("The Arabic number is: "+ans1);
}
catch (Exception e)
{
System.out.print ("Wrong inPut!");
}
}
}
smbka at 2007-7-14 20:31:47 >
