Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The programming language is Java! Sorry the pic is blurry . Here is the program

ID: 3836702 • Letter: T

Question

The programming language is Java!

Sorry the pic is blurry . Here is the program I wrote , it has errors.

The instructions gives speed to the bike eventhough the bike only has geers parameter . Please fix my program.

public class Vehicle {

   double maxSpeed;
   int numOfWheels;

public Vehicle()
{
   this (0,0);
   System.out.println("Default constructor - Vehicle calss");

}

public Vehicle (double maxSpeed, int numOfWheels)
{
   this.maxSpeed = maxSpeed;
   this.numOfWheels = numOfWheels;

}

public double getMaxSpeed()
{
   return maxSpeed;
}

public void setMaxSpeed()
{
   this.maxSpeed = maxSpeed;
}

public int getNumOfWheels()
{
   return numOfWheels;
}

public void setNumOfWheels(int numOfWheels)
{
   this.numOfWheels = numOfWheels;
}

public String toString()
{
   return "MaxSpeed : " + maxSpeed + " numOfWheels : " + numOfWheels;
}
}

public class Bicycle extends Vehicle {

   int numOfGears;

public Bicycle()
{
   this.numOfGears = 0 ;
   System.out.println("Default constructor - Bicycle class");
}

public Bicycle(int numOfGears )
{
   this.numOfGears = numOfGears ;
}

public int getNumOfGearts()
{
   return numOfGears;
}

public void setNumOfGears (int numOfGears)
{
   this.numOfGears = numOfGears ;
}

}
public String toString()
{
   return super.toString();
}

}

public class VehicleTest {

   public static void main(String[] args) {

       Vehicle v1 = new Vehicle (45.0,3) ;
       Bicycle b1 = new Bicycle (30.0,10);

       System.out.println(v1);
       System.out.println(b1);

       Bicycle b2 = new Bicycle(10.0,2);
       Bicycle b3 = new Bicycle(3.0,2);
       Vehicle v2 = new Vehicle();


       Vehicle vehicles[] = {b2, b3, v2};

       for (Vehicle v : vehicles)
       {
           v.toString()

       }


}}

rise Lab Exercise: contains a top maximum 30 MPH. of 45 methods top speed tostring and for speed the a 2 of field number a (set) a wheels mu the constructor and vehicle's Bicycle's (Solution: and the following Vehicle int ng a class called vehicle that contains fields for speed and number of wheels. Provide both a default argument constructor. Provide accessor (get) and the fields. (Solution: Vehicle. java a subclass of vehicle called Bicycle that gears on the bike. All bikes should have 2 wheels. Bicycle, java) .tostring o method to both classes. Have vehicle's tostring an application that creates a vehicle with 3 oike an ATV) and a Bicycle with 10 gears Bicycle java, Display both objects, (Solutions: Vehicle.java Vehicle Test, java) an array of 3 vehicles. Make the first two elements Bicycle objects: a dospeed and a 3-speed. Make the third element just a vehicle object. a loop that runs through the array, printing each object. Which tostring method is called each time? (Solution: VehicleArray. java)

Explanation / Answer

I have updated your code as per the specification given in the image. Bicycle will also have maxSpeed as it is inheriting from Vehicle. That is the basic concept of inheritence that child class will get all the properties of parent class.

Below is your updated code: -

Vehicle.java


public class Vehicle {
   double maxSpeed;
   int numOfWheels;

   public Vehicle() {
       this(0, 0);
       System.out.println("Default constructor - Vehicle calss");
   }

   public Vehicle(double maxSpeed, int numOfWheels) {
       this.maxSpeed = maxSpeed;
       this.numOfWheels = numOfWheels;
   }

   public double getMaxSpeed() {
       return maxSpeed;
   }

   public void setMaxSpeed(double maxSpeed) {
       this.maxSpeed = maxSpeed;
   }

   public int getNumOfWheels() {
       return numOfWheels;
   }

   public void setNumOfWheels(int numOfWheels) {
       this.numOfWheels = numOfWheels;
   }

   public String toString() {
       return "MaxSpeed : " + maxSpeed + " numOfWheels : " + numOfWheels;
   }
}

Bicycle.java


public class Bicycle extends Vehicle {
   int numOfGears;

   public Bicycle() {
       this.numOfGears = 0;
       System.out.println("Default constructor - Bicycle class");
       this.numOfWheels = 2;
   }

   public Bicycle(int numOfGears) {
       this.numOfGears = numOfGears;
       this.numOfWheels =2;
   }

   public int getNumOfGearts() {
       return numOfGears;
   }

   public void setNumOfGears(int numOfGears) {
       this.numOfGears = numOfGears;
   }

   public String toString() {
       return super.toString() + " numOfGears:"+this.numOfGears;
   }
}

VehicleTest.java


public class VehicleTest {
   public static void main(String[] args) {
       Vehicle v1 = new Vehicle(45.0, 3);
       Bicycle b1 = new Bicycle(10);
       b1.setMaxSpeed(30.0);
       System.out.println(v1);
       System.out.println(b1);
       Bicycle b2 = new Bicycle(2);
       b2.setMaxSpeed(10.0);
       Bicycle b3 = new Bicycle(2);
       b3.setMaxSpeed(3.0);
       Vehicle v2 = new Vehicle(35.0,4);

       Vehicle vehicles[] = { b2, b3, v2 };
       for (Vehicle v : vehicles) {
           System.out.println(v);
       }

   }
}

Sample run: -

Default constructor - Vehicle calss
MaxSpeed : 45.0 numOfWheels : 3
MaxSpeed : 30.0 numOfWheels : 2 numOfGears:10
Default constructor - Vehicle calss
Default constructor - Vehicle calss
MaxSpeed : 10.0 numOfWheels : 2 numOfGears:2
MaxSpeed : 3.0 numOfWheels : 2 numOfGears:2
MaxSpeed : 35.0 numOfWheels : 4

Note that this is correct as per the specification in the image.