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

JAVA CLASSES HELP import java.util.Scanner; class Bicycle { //YOUR CODE GOES HER

ID: 3912050 • Letter: J

Question

JAVA CLASSES HELP

import java.util.Scanner;

class Bicycle
{
//YOUR CODE GOES HERE

}


// driver class
public class main
{
public static void main(String args[])
{
//YOUR CODE GOES HERE
}
}

You have to design Bicycle class in Java You need to have two classes: o Bicycle class main,java which acts as a driver class andcontains your public static void main(String args) Bicycle class Attributes o gear->int variable. Private attribute o speed -> int variable. Private attribute . Default Constructor o accepts no parameters o sets value for gear to be 0 o sets value for speed to be 0 Functions ovoid setGear(int) - > public-> sets the gear o int getGear0>public->returns the gear o void setSpeed(int) -> public-> sets the speed o int getSpeed(int) -> public->returns the speed ovoid print0->prints the gear and speed of a Bicycle Driver class Functionality Flow o create a array of size 3 of type Bicycle class o instantiate all three elements in the Bicycle array with Bicycle objects. o take an input for gear value. then enter an input for speed value. Repeat two more times ocall setGearO method for all 3 Bicycle objects contained in the Bicycle array to set the gear value o calls setSpeed0 method for all 3 Bicycle objects contained in the Bicycle array to set the speed value o calls the print0 method for all 3 Bicycle objects contained in the Bicycle array

Explanation / Answer

import java.util.Scanner;

class Main {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

Bicycle[] bc = new Bicycle[3];

int g, s;

// taking input

for(int i=0; i<3; i++)

{

bc[i] = new Bicycle();

System.out.printf("Enter gear of bicycle%d: ",i+1);

g = sc.nextInt();

bc[i].setGear(g);

System.out.printf("Enter speed of bicycle%d: ",i+1);

s = sc.nextInt();

bc[i].setSpeed(s);

}

// printing output

System.out.println();

for(int i=0; i<3; i++)

{

bc[i].print();

}

}

}

class Bicycle

{

private int gear, speed;

Bicycle()

{

gear = 0;

speed = 0;

}

void setGear(int gear)

{

this.gear = gear;

}

int getGear()

{

return gear;

}

void setSpeed(int speed)

{

this.speed = speed;

}

int getSpeed()

{

return speed;

}

void print()

{

System.out.printf("Gear is %d and Speed is %d ",gear, speed);

}

}

/*sample output

Enter gear of bicycle1: 3

Enter speed of bicycle1: 4

Enter gear of bicycle2: 5

Enter speed of bicycle2: 6

Enter gear of bicycle3: 7

Enter speed of bicycle3: 8

Gear is 3 and Speed is 4

Gear is 5 and Speed is 6

Gear is 7 and Speed is 8

*/