📚 The CoCalc Library - books, templates and other resources
cocalc-examples / martinthoma-latex-examples / presentations / Programmieren-Tutorium / Tutorium-09 / SinglyLinkedList-Template / Gears.java
132948 viewsLicense: OTHER
/**1* This class models the gears. It is restricted to derailleur gears.2*3* @author Markus Iser, Martin Thoma4* @version 1.05*/67public class Gears {8public static final int MIN_FRONT_SPROCKETS = 1;9public static final int MAX_FRONT_SPROCKETS = 3;10public static final int MIN_REAR_SPROCKETS = 1;11public static final int MAX_REAR_SPROCKETS = 10;1213private int frontSprockets;14private int rearSprockets;1516/** Price in cents. */17private final int price;1819Gears(int frontSprockets, int rearSprockets, int price) {20setSprockets(frontSprockets, rearSprockets);21this.price = price;22}2324/**25* Sets the sprocket numbers. Uses default-values if consisteny criteria are26* not met.27*28* @param sprockets29* @param rearSprockets30*/31void setSprockets(int sprockets, int rearSprockets) {32this.frontSprockets = sprockets;33this.rearSprockets = rearSprockets;3435if (!(this.frontSprockets >= 1)) { // A.136this.frontSprockets = 1;37} else if (!(this.frontSprockets < 4)) { // A.238this.frontSprockets = 3;39}4041if (this.rearSprockets < 1) { // B.142this.rearSprockets = this.frontSprockets;43}44if (this.rearSprockets > 9) { // B.245this.rearSprockets = this.frontSprockets * 3;46}4748if (this.rearSprockets < this.frontSprockets) { // C.149this.rearSprockets = this.frontSprockets;50} else if (this.rearSprockets > 3 * this.frontSprockets) { // C.251this.rearSprockets = 3 * this.frontSprockets;52}53}5455/**56* @return the number of gears as the number of sprocket-combinations57*/58int getNumberOfGears() {59return frontSprockets * rearSprockets;60}6162/**63* @return the price of the gears64*/65int getPrice() {66return price;67}68}697071