8.2 (25 points) There are many different types of cycle. For this question, we w
ID: 3755050 • Letter: 8
Question
8.2 (25 points) There are many different types of cycle. For this question, we will only consider 3 different types based on the number of wheels and its description. For example, Unicycle, Bicycle, and Tricycle has 1, 2, and 3 wheels respectively. The corresponding descriptions are listed in the following table. Use the polymorphic approach as we program to display the number of wheels and the cycle description as you ride method to display them polymorphically from your main (. Draw an UML diagram to show your design or code layout (5 points). (do not use if-then-else or switch case) discussed in class to write a it. write a static Cycle Type Unicycle Bicycle Tricycle Number of wheels Descriptions Requires skill to ride it Post Tricycle Kids training bike Your results should be similar to the following Cycle is the base for all cycle Unicycle1 has 1 wheel: Requires skill to ride it Bicycle has 2 wheels: Post tricycle Tricycle has 3 wheels: kid's training bikeExplanation / Answer
public class Cycle {
public int getNumWheels(){
return 0;
}
public void display(){
}
}
public class UniCycle extends Cycle {
@Override
public int getNumWheels() {
return 1;
}
@Override
public void display() {
System.out.println("Unicycle has " + getNumWheels() + " wheels: Requires skill to rid it");
}
}
public class BiCycle extends Cycle{
@Override
public int getNumWheels() {
return 2;
}
@Override
public void display() {
System.out.println("Bicycle has " + getNumWheels() + " wheels: post tricycle");
}
}
public class Tricycle extends Cycle {
@Override
public int getNumWheels() {
return 3;
}
@Override
public void display() {
System.out.println("Tricycle has " + getNumWheels() + " wheels: kids's training bike");
}
}
public class TestCycle {
public static void main(String[] args) {
Cycle[] cycles = new Cycle[3];
cycles[0] = new UniCycle();
cycles[1] = new BiCycle();
cycles[2] = new Tricycle();
for(Cycle c : cycles)
c.display();
}
}
output
-----
Unicycle has 1 wheels: Requires skill to rid it
Bicycle has 2 wheels: post tricycle
Tricycle has 3 wheels: kids's training bike
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.