Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package car;
- /**
- * Car: small four wheeled vehicles and version details
- *
- * @author Richard William Thomas Cooper
- * @version v5.0, February 2011
- */
- public class Car {
- // Attributes
- /**
- * make: the company that built the car
- */
- private String make;
- /**
- * mileage: number of miles the car has travelled
- */
- private int mileage;
- /**
- * isTaxExempt: true if the car is exempt from road tax
- */
- private boolean isTaxExempt;
- /**
- * hasLights: true if the car has headlights
- */
- private boolean hasLights;
- /**
- * numberOfSeats: the number of seats
- */
- private int numberOfSeats;
- /**
- * model: the model of the car
- */
- private String model;
- /**
- * length: length of the car in metres
- */
- private double length;
- /**
- * isOnDisplay: true if the artifact is on display
- */
- private boolean isOnDisplay;
- // Default Constructor
- public Car() {
- // eg:
- isOnDisplay = false;
- make = "unknown make";
- mileage = 0;
- isTaxExempt = false;
- hasLights = false;
- numberOfSeats = 0;
- model = "unknown model";
- length = 0;
- isOnDisplay = false;
- }
- /**
- * @param make
- * @param mileage
- * @param isTaxExempt
- * @param hasLights
- * @param numberOfSeats
- * @param model
- * @param length
- * @param isOnDisplay
- */
- public Car(String make, int mileage, boolean isTaxExempt,
- boolean hasLights, int numberOfSeats, String model, double length,
- boolean isOnDisplay) {
- this.make = make;
- this.mileage = mileage;
- this.isTaxExempt = isTaxExempt;
- this.hasLights = hasLights;
- this.numberOfSeats = numberOfSeats;
- this.model = model;
- this.length = length;
- this.isOnDisplay = isOnDisplay;
- }
- /**
- * Gets the car Make.
- *
- * @return the make
- */
- public String getMake() {
- return make;
- }
- /**
- * Sets the car Make.
- *
- * @param make
- * the make to set
- */
- public void setMake(String make) {
- this.make = make;
- }
- /**
- * Gets the car Mileage.
- *
- * @return the mileage
- */
- public int getMileage() {
- return mileage;
- }
- /**
- * Sets the car Mileage
- *
- * @param mileage
- * the mileage to set
- */
- public void setMileage(int mileage) {
- this.mileage = mileage;
- }
- /**
- * Gets if the car is tax exempt.
- *
- * @return the isTaxExempt
- */
- public boolean isTaxExempt() {
- return isTaxExempt;
- }
- /**
- * Sets the car tax exemption status.
- *
- * @param isTaxExempt
- * the isTaxExempt to set
- */
- public void setTaxExempt(boolean isTaxExempt) {
- this.isTaxExempt = isTaxExempt;
- }
- /**
- * Gets if the car has lights
- *
- * @return the hasLights
- */
- public boolean isHasLights() {
- return hasLights;
- }
- /**
- * Sets whether the car has lights.
- *
- * @param hasLights
- * the hasLights to set
- */
- public void setHasLights(boolean hasLights) {
- this.hasLights = hasLights;
- }
- /**
- * Gets the car number of seats.
- *
- * @return the numberOfSeats
- */
- public int getNumberOfSeats() {
- return numberOfSeats;
- }
- /**
- * Sets the car number of seats.
- *
- * @param numberOfSeats
- * the numberOfSeats to set
- */
- public void setNumberOfSeats(int numberOfSeats) {
- this.numberOfSeats = numberOfSeats;
- }
- /**
- * Gets the car model.
- *
- * @return the model
- */
- public String getModel() {
- return model;
- }
- /**
- * Sets the car model.
- *
- * @param model
- * the model to set
- */
- public void setModel(String model) {
- this.model = model;
- }
- /**
- * Gets the car length.
- *
- * @return the length
- */
- public double getLength() {
- return length;
- }
- /**
- * Sets the car length.
- *
- * @param length
- * the length to set
- */
- public void setLength(double length) {
- this.length = length;
- }
- /**
- * Gets whether the car is on display.
- *
- * @return the isOnDisplay
- */
- public boolean isOnDisplay() {
- return isOnDisplay;
- }
- /**
- * Sets whether the car is on display.
- *
- * @param isOnDisplay
- * the isOnDisplay to set
- */
- public void setOnDisplay(boolean isOnDisplay) {
- this.isOnDisplay = isOnDisplay;
- }
- /**
- * Overrides the Object.toString method
- *
- * @return a String representation of the object
- */
- public String toString() {
- return "Car make=" + make + ", model=" + model
- + ", tax exemption status=" + isTaxExempt + ", has lights="
- + hasLights + ", mileage=" + mileage + ", length=" + length
- + "m " + ", is on display=" + isOnDisplay;
- }
- /**
- * Overrides the Object.equals method
- *
- * @return a boolean indicating whether the two strings are equal
- */
- public boolean equals(Object obj) {
- if (obj instanceof Car) {
- Car car = (Car) obj;
- if ((make.equals(car.getMake())) && (mileage == car.getMileage())
- && (isTaxExempt == car.isTaxExempt())
- && (hasLights == car.isHasLights())
- && (numberOfSeats == car.getNumberOfSeats())
- && (model == car.getModel()) && (length == car.getLength())
- && (isOnDisplay == car.isOnDisplay()))
- return true;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement