📚 The CoCalc Library - books, templates and other resources
cocalc-examples / martinthoma-latex-examples / presentations / Programmieren-Tutorium / Tutorium-06 / Gears.java
132930 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.26* Uses default-values if consisteny criteria are not met.27* @param sprockets28* @param rearSprockets29*/30void setSprockets(int sprockets, int rearSprockets) {31this.frontSprockets = sprockets;32this.rearSprockets = rearSprockets;3334if (!(this.frontSprockets >= 1)) { // A.135this.frontSprockets = 1;36} else if (!(this.frontSprockets < 4)) { // A.237this.frontSprockets = 3;38}3940// B.1, B.241if (this.rearSprockets < 1 || this.rearSprockets > 9) {42this.rearSprockets = this.frontSprockets * 3;43}4445if (this.rearSprockets < this.frontSprockets) { // C.146this.rearSprockets = this.frontSprockets;47} else if (this.rearSprockets > 3 * this.frontSprockets) { // C.248this.rearSprockets = 3 * this.frontSprockets;49}50}5152/**53* @return the number of gears as the number of sprocket-combinations54*/55int getNumberOfGears() {56return frontSprockets * rearSprockets;57}5859/**60* @return the price of the gears61*/62int getPrice() {63return price;64}65}66676869