View Single Post
Old 07-27-2012, 02:48 AM   PM User | #1
dannyboi
New Coder

 
Join Date: Jul 2012
Location: NYC
Posts: 23
Thanks: 1
Thanked 0 Times in 0 Posts
dannyboi is an unknown quantity at this point
Problems with the code

Here is my code ( or rather, the code that I ran from oracle)
public class Main{
class Bicycle {
}
int cadence = 0;
int speed = 0;
int gear = 1;

void changeCadence(int newValue) {
cadence = newValue;
}

void changeGear(int newValue) {
gear = newValue;
}

void speedUp(int increment) {
speed = speed + increment;
}

void applyBrakes(int decrement) {
speed = speed - decrement;
}

void printStates() {
System.out.println("cadence:" +
cadence + " speed:" +
speed + " gear:" + gear);
}



class BicycleDemo {
public static void main(String[] args)
{
// Create two different
// Bicycle objects
Bicycle bike1 = new Bicycle();
Bicycle bike2 = new Bicycle();
}
{
// Invoke methods on
// those objects
bike1.changeCadence(50);
bike1.speedUp(10);
bike1.changeGear(2);
bike1.printStates();
}
{
bike2.changeCadence(50);
bike2.speedUp(10);
bike2.changeGear(2);
bike2.changeCadence(40);
bike2.speedUp(10);
bike2.changeGear(3);
bike2.printStates();
}
}



Now it wouldn't run through, and I assumed that it was the curly braces that didn't match up. I checked, but the code still would not run. Does anybody have any suggestion?
dannyboi is offline   Reply With Quote