I'm trying to write this program, involving loops, but for soem reason, it will not work out. here is what I have so far
import javabook.*;
class Project1
{
public static void main (String [] args)
{
MainWindow mainWindow = new MainWindow ("Project 2");
InputBox inputBox = new InputBox( mainWindow );
OutputBox outputBox = new OutputBox(mainWindow);
mainWindow.setVisible (true);
outputBox.setVisible (true);
final int M = 1000;
final int D = 500;
final int C = 100;
final int L = 50;
final int X = 10;
final int I = 1;
int y = 0;
int x = 0;
int totalValue = 0;
int index = 0;
String str = new String();
int numberOfLetters = str.length();
for(index = 0; index < str.length(); index++){
str = inputBox.getString("Enter a string");
y = str.charAt(index);
x = str.charAt(index + 1);
if (y > x)
{
totalValue = y + x;
}
else
{
totalValue = y - x;
y++;
}
outputBox.printLine ("blah");
}
}
}
yup yup. I need to write a program that basically asks you to enter roman numberals, and then, convert it to numbers. I tink I got the loop right....right?? but for soem reason, my inputbox to ask for a string wont appear.....any ideas?? according to me, this should work out, but I dont know.
In my head, this is what should happen: it will ask for a string. I enter a string. It will then check the string, starting at index 0, and assign it to y. then, it will check the next index(index + 1), and assign that to x. AFter that, if y > x, it will add. else, y<x, it will subtract( i.e VI = 6, but IV = 4). then, it will increment index++, and go through the loop all over, until index < stringlenght.So that is what's gonig on in my head.........am I even right?? close?
import javabook.*;
class Project1
{
public static void main (String [] args)
{
MainWindow mainWindow = new MainWindow ("Project 2");
InputBox inputBox = new InputBox( mainWindow );
OutputBox outputBox = new OutputBox(mainWindow);
mainWindow.setVisible (true);
outputBox.setVisible (true);
final int M = 1000;
final int D = 500;
final int C = 100;
final int L = 50;
final int X = 10;
final int I = 1;
int y = 0;
int x = 0;
int totalValue = 0;
int index = 0;
String str = new String();
int numberOfLetters = str.length();
for(index = 0; index < str.length(); index++){
str = inputBox.getString("Enter a string");
y = str.charAt(index);
x = str.charAt(index + 1);
if (y > x)
{
totalValue = y + x;
}
else
{
totalValue = y - x;
y++;
}
outputBox.printLine ("blah");
}
}
}
yup yup. I need to write a program that basically asks you to enter roman numberals, and then, convert it to numbers. I tink I got the loop right....right?? but for soem reason, my inputbox to ask for a string wont appear.....any ideas?? according to me, this should work out, but I dont know.
In my head, this is what should happen: it will ask for a string. I enter a string. It will then check the string, starting at index 0, and assign it to y. then, it will check the next index(index + 1), and assign that to x. AFter that, if y > x, it will add. else, y<x, it will subtract( i.e VI = 6, but IV = 4). then, it will increment index++, and go through the loop all over, until index < stringlenght.So that is what's gonig on in my head.........am I even right?? close?