Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.13 KB | None | 0 0
  1. package car;
  2.  
  3. /**
  4.  * Car: small four wheeled vehicles and version details
  5.  *
  6.  * @author Richard William Thomas Cooper
  7.  * @version v5.0, February 2011
  8.  */
  9. public class Car {
  10.     // Attributes
  11.  
  12.     /**
  13.      * make: the company that built the car
  14.      */
  15.     private String make;
  16.  
  17.     /**
  18.      * mileage: number of miles the car has travelled
  19.      */
  20.     private int mileage;
  21.  
  22.     /**
  23.      * isTaxExempt: true if the car is exempt from road tax
  24.      */
  25.     private boolean isTaxExempt;
  26.  
  27.     /**
  28.      * hasLights: true if the car has headlights
  29.      */
  30.     private boolean hasLights;
  31.  
  32.     /**
  33.      * numberOfSeats: the number of seats
  34.      */
  35.     private int numberOfSeats;
  36.  
  37.     /**
  38.      * model: the model of the car
  39.      */
  40.     private String model;
  41.  
  42.     /**
  43.      * length: length of the car in metres
  44.      */
  45.     private double length;
  46.  
  47.     /**
  48.      * isOnDisplay: true if the artifact is on display
  49.      */
  50.     private boolean isOnDisplay;
  51.  
  52.     // Default Constructor
  53.     public Car() {
  54.         // eg:
  55.         isOnDisplay = false;
  56.         make = "unknown make";
  57.         mileage = 0;
  58.         isTaxExempt = false;
  59.         hasLights = false;
  60.         numberOfSeats = 0;
  61.         model = "unknown model";
  62.         length = 0;
  63.         isOnDisplay = false;
  64.     }
  65.  
  66.     /**
  67.      * @param make
  68.      * @param mileage
  69.      * @param isTaxExempt
  70.      * @param hasLights
  71.      * @param numberOfSeats
  72.      * @param model
  73.      * @param length
  74.      * @param isOnDisplay
  75.      */
  76.     public Car(String make, int mileage, boolean isTaxExempt,
  77.             boolean hasLights, int numberOfSeats, String model, double length,
  78.             boolean isOnDisplay) {
  79.         this.make = make;
  80.         this.mileage = mileage;
  81.         this.isTaxExempt = isTaxExempt;
  82.         this.hasLights = hasLights;
  83.         this.numberOfSeats = numberOfSeats;
  84.         this.model = model;
  85.         this.length = length;
  86.         this.isOnDisplay = isOnDisplay;
  87.     }
  88.  
  89.     /**
  90.      * Gets the car Make.
  91.      *
  92.      * @return the make
  93.      */
  94.     public String getMake() {
  95.         return make;
  96.     }
  97.  
  98.     /**
  99.      * Sets the car Make.
  100.      *
  101.      * @param make
  102.      *            the make to set
  103.      */
  104.     public void setMake(String make) {
  105.         this.make = make;
  106.     }
  107.  
  108.     /**
  109.      * Gets the car Mileage.
  110.      *
  111.      * @return the mileage
  112.      */
  113.     public int getMileage() {
  114.         return mileage;
  115.     }
  116.  
  117.     /**
  118.      * Sets the car Mileage
  119.      *
  120.      * @param mileage
  121.      *            the mileage to set
  122.      */
  123.     public void setMileage(int mileage) {
  124.         this.mileage = mileage;
  125.     }
  126.  
  127.     /**
  128.      * Gets if the car is tax exempt.
  129.      *
  130.      * @return the isTaxExempt
  131.      */
  132.     public boolean isTaxExempt() {
  133.         return isTaxExempt;
  134.     }
  135.  
  136.     /**
  137.      * Sets the car tax exemption status.
  138.      *
  139.      * @param isTaxExempt
  140.      *            the isTaxExempt to set
  141.      */
  142.     public void setTaxExempt(boolean isTaxExempt) {
  143.         this.isTaxExempt = isTaxExempt;
  144.     }
  145.  
  146.     /**
  147.      * Gets if the car has lights
  148.      *
  149.      * @return the hasLights
  150.      */
  151.     public boolean isHasLights() {
  152.         return hasLights;
  153.     }
  154.  
  155.     /**
  156.      * Sets whether the car has lights.
  157.      *
  158.      * @param hasLights
  159.      *            the hasLights to set
  160.      */
  161.     public void setHasLights(boolean hasLights) {
  162.         this.hasLights = hasLights;
  163.     }
  164.  
  165.     /**
  166.      * Gets the car number of seats.
  167.      *
  168.      * @return the numberOfSeats
  169.      */
  170.     public int getNumberOfSeats() {
  171.         return numberOfSeats;
  172.     }
  173.  
  174.     /**
  175.      * Sets the car number of seats.
  176.      *
  177.      * @param numberOfSeats
  178.      *            the numberOfSeats to set
  179.      */
  180.     public void setNumberOfSeats(int numberOfSeats) {
  181.         this.numberOfSeats = numberOfSeats;
  182.     }
  183.  
  184.     /**
  185.      * Gets the car model.
  186.      *
  187.      * @return the model
  188.      */
  189.     public String getModel() {
  190.         return model;
  191.     }
  192.  
  193.     /**
  194.      * Sets the car model.
  195.      *
  196.      * @param model
  197.      *            the model to set
  198.      */
  199.     public void setModel(String model) {
  200.         this.model = model;
  201.     }
  202.  
  203.     /**
  204.      * Gets the car length.
  205.      *
  206.      * @return the length
  207.      */
  208.     public double getLength() {
  209.         return length;
  210.     }
  211.  
  212.     /**
  213.      * Sets the car length.
  214.      *
  215.      * @param length
  216.      *            the length to set
  217.      */
  218.     public void setLength(double length) {
  219.         this.length = length;
  220.     }
  221.  
  222.     /**
  223.      * Gets whether the car is on display.
  224.      *
  225.      * @return the isOnDisplay
  226.      */
  227.     public boolean isOnDisplay() {
  228.         return isOnDisplay;
  229.     }
  230.  
  231.     /**
  232.      * Sets whether the car is on display.
  233.      *
  234.      * @param isOnDisplay
  235.      *            the isOnDisplay to set
  236.      */
  237.     public void setOnDisplay(boolean isOnDisplay) {
  238.         this.isOnDisplay = isOnDisplay;
  239.     }
  240.  
  241.     /**
  242.      * Overrides the Object.toString method
  243.      *
  244.      * @return a String representation of the object
  245.      */
  246.     public String toString() {
  247.         return "Car make=" + make + ", model=" + model
  248.                 + ", tax exemption status=" + isTaxExempt + ", has lights="
  249.                 + hasLights + ", mileage=" + mileage + ", length=" + length
  250.                 + "m " + ", is on display=" + isOnDisplay;
  251.     }
  252.  
  253.     /**
  254.      * Overrides the Object.equals method
  255.      *
  256.      * @return a boolean indicating whether the two strings are equal
  257.      */
  258.     public boolean equals(Object obj) {
  259.         if (obj instanceof Car) {
  260.             Car car = (Car) obj;
  261.             if ((make.equals(car.getMake())) && (mileage == car.getMileage())
  262.                     && (isTaxExempt == car.isTaxExempt())
  263.                     && (hasLights == car.isHasLights())
  264.                     && (numberOfSeats == car.getNumberOfSeats())
  265.                     && (model == car.getModel()) && (length == car.getLength())
  266.                     && (isOnDisplay == car.isOnDisplay()))
  267.                 return true;
  268.         }
  269.         return false;
  270.     }
  271.  
  272. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement