Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Question: 1 Firewalls are to protect against

Answered: 1 week ago