Question
You will be implementing the Factory Design Pattern to create Bikes Your Bike Store will be your factory. It will aid in creating Tricycles, Striders,
You will be implementing the Factory Design Pattern to create Bikes
Your Bike Store will be your factory. It will aid in creating Tricycles, Striders, and Kids Bikes
Bike class:
It will hold variables to keep track of the bike name, price, number of wheels, and whether or not it has pedals or training wheels
createBike -> calls createFrame, addWheels, and addPedals
CreateFrame -> displays "Assembling (name of bike) frame
addWheels -> displays nothing if there are no wheels, Adding x wheel(s), and if applicable, Adding Training Wheels
addPedals -> displays adding Pedals if there are pedals
getPrice -> returns the price of the bike
Tricycle
Here you simply need to set the attributes for a Tricycle.
Tricycles, have 3 wheels, and pedals. They cost 54.95
Strider
Here you simply need to set the attributes for a Strider.
Struders, have 2 wheels, and no pedals. They cost 65.99
KidsBike
Here you simply need to set the attributes for a KidsBike.
KidsBikes, have 2 wheels, pedals, and training wheels. They cost 80.99
UML:
Driver:
public class BikeStoreDriver {
public void runBikeStore() { BikeStore bikeStore = new BikeStore(); Bike tricycle = bikeStore.orderBike("tricycle"); System.out.println(" ----------------------------------- "); Bike strider = bikeStore.orderBike("strider"); System.out.println(" ----------------------------------- "); Bike kidsBike = bikeStore.orderBike("kids bike"); System.out.println(" ----------------------------------- "); } public static void main(String[] args) { BikeStoreDriver driver = new BikeStoreDriver(); driver.runBikeStore(); }
}
Output:
Assembling Tricycle frame Adding 3 wheel(s) Adding pedals Price: $54.95
-----------------------------------
Assembling Strider frame Adding 2 wheel(s) Price: $65.99
-----------------------------------
Assembling Kids Bike frame Adding 2 wheel(s) Adding training wheels Adding pedals Price: $80.99
-----------------------------------
Bike # name: String #price: Double #numWheels: int #hasPeddals: boolean #has Training Wheels: boolean BikeStore + orderBike(String type): Bike - createBike(String type): Bike + createBike(): void - CreateFrame(); void - addWheels(): void - addPedals: void + getPrice(): double Tricycle Strider Kids Bike + Tricycle + Strider + KidsBike Bike # name: String #price: Double #numWheels: int #hasPeddals: boolean #has Training Wheels: boolean BikeStore + orderBike(String type): Bike - createBike(String type): Bike + createBike(): void - CreateFrame(); void - addWheels(): void - addPedals: void + getPrice(): double Tricycle Strider Kids Bike + Tricycle + Strider + KidsBike
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started