Question: Create a public static method named getNextWheelId ( ) that returns the value of the private static integer field nextWheelId. public class Tricycle { private

Create a public static method named getNextWheelId() that returns the value of the private static integer field nextWheelId. public class Tricycle {
private static int nextWheelId =1;
private int numTricycles;
private int startId;
private int endId;
public Tricycle(int newSize){
numTricycles = newSize;
startId = nextWheelId;
endId = startId + numTricycles *3-1;
nextWheelId += numTricycles *3;
}
public void print(){
System.out.print(numTricycles +" tricycles need ");
System.out.print(numTricycles *3+" wheels and the wheels are assigned with IDs from ");
System.out.println(startId +" to "+ endId +".");
}
/* Your code goes here */
} import java.util.Scanner;
public class NewTricycles {
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
System.out.println("Next available ID is "+ Tricycle.getNextWheelId()+".");
Tricycle tricycle1= new Tricycle(scnr.nextInt());
Tricycle tricycle2= new Tricycle(scnr.nextInt());
Tricycle tricycle3= new Tricycle(scnr.nextInt());
tricycle1.print();
tricycle2.print();
tricycle3.print();
System.out.println("Next available ID is "+ Tricycle.getNextWheelId()+".");
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!