custom java program aint workin, help plz

Status
Not open for further replies.

St4nley

Member
Apr 13, 2013
469
76
made a method called race
Code:
          public static void race()  {
            Random random = new Random();
              Bicycle RaceBike1 = new Bicycle("Racer 1");
              Bicycle RaceBike2 = new Bicycle("Racer 2");
              RaceBike1.speedUp(25);
              RaceBike2.speedUp(30);
              for(int r = 1; r < 3; r++)    {
              System.out.println("Race" + r);
              for(int h = 1; h < 4; h++)    {
    do {
                int random1 = random.nextInt(7-3) + 3;
                int random2 = random.nextInt(6-3) + 3;
                RaceBike1.pedalBike(+random1);
                RaceBike2.pedalBike(+random2);
              }while (RaceBike1.distance < 1000 && RaceBike2.distance < 1000);
    if (RaceBike1.distance < RaceBike2.distance)    {
        System.out.println("Race Bike 1 Has Won Heat # " + h);
    }else{ if (RaceBike2.distance > RaceBike1.distance) {
        System.out.println("Race Bike 2 Has Won Heat # " + h);
    }else{
        System.out.println("Draw In Heat # " + h);
    }
    }
  }
  }
}
}

another class with my methods that are the subclass of that^
Code:
public class Bicycle {
   
      int cadence = 0;
      float speed = 0;
      int gear = 1;
      float distance = 0;
      String nameBike;
     
      void changeCadence(int newValue) {
            cadence = newValue;
      }

      void changeGear(int newValue) {
            gear = newValue;
            if (gear < 1 || gear > 18)  {
              System.err.println("Not In Correct Gear");

            }
      }

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

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

     
      void distancePeddled(float peddling)  {
          distance = distance + peddling;
         
      }
     
        void printStates() {
            System.out.println("speed:"+speed+" Name:"+nameBike+ " Distance Travelled  "+distance);
      }
     
        public Bicycle(String bName)  {
            nameBike = bName;
       
    }
        void pedalBike(float howLong)  {
            distance = speed * howLong;
        }
       
       
}

btw first code block is my main and it only prints race #, all code is correct to my understanding. ITs suppose to generate random numbers for 2 bikes and see who wins before they hit 1000meters.
If you wanna run this yourself and want full code just ask ill happily provide
 

St4nley

Member
Apr 13, 2013
469
76
Close thread my issue was in my method i made
Code:
  void pedalBike(float howLong)  {
            distance = speed * howLong;
        }

that needed to be
Code:
  void pedalBike(float howLong)  {
            distance = distance+ (speed * howLong;)
        }
CLOSE THREAD PLEASE
 
Status
Not open for further replies.

Users who are viewing this thread

Top