📚 The CoCalc Library - books, templates and other resources
cocalc-examples / martinthoma-latex-examples / presentations / Programmieren-Tutorium / Tutorium-09 / SinglyLinkedList-Template / Bike.java
132948 viewsLicense: OTHER
/**1* A bike model in Java.2*3* @author Markus Iser, Martin Thoma4* @version 1.05*/67public class Bike {8private final Gears gears;9private final Wheels wheels;1011enum Material {12ALU, STEEL, TITAN13}1415private final Material material;1617private final String modelId;1819private final boolean hasBell;20private final boolean hasLights;2122/** Price of the bike in cents. */23private int price;2425Bike(String modelId) {26this.gears = null;27this.wheels = null;28this.material = Material.ALU;29this.modelId = modelId;30this.hasBell = true;31this.hasLights = true;32}3334Bike(Gears gears, Wheels wheels, Material material,35String modelId, boolean bell, boolean lights) {36this.gears = gears;37this.wheels = wheels;38this.material = material;39switch (material) {40case ALU:41price = 20000;42break;43case STEEL:44price = 30000;45break;46case TITAN:47price = 40000;48break;49}50this.modelId = modelId;51this.hasBell = bell;52this.hasLights = lights;53}5455/**56* Check if the bike is legal for usage on streets.57*58* @return {@code true} if the bike has a bell and has lights59*/60public boolean isStreetLegal() {61return hasBell && hasLights;62}6364/**65* Get the price of the bike.66*67* @return the sum of the bike's base-price and the price of the wheels and68* gears69*/70public int getPrice() {71return price + gears.getPrice() + wheels.getPrice();72}7374/**75* @return the material of this bike76*/77public Material getMaterial() {78return this.material;79}8081/**82* @return the model id of this bike83*/84public String getModelId() {85return this.modelId;86}8788/*89* (non-Javadoc)90*91* @see java.lang.Object#toString()92*/93@Override94public String toString() {95return "Bike[" + modelId + "]";96}97}9899