Car.java - PART 1 import java.util.Scanner public class Car private private private private private private String make String model int price int year

Car.java - PART 1 import java.util.Scanner public class Car...

This preview shows page 1 - 3 out of 8 pages.

// PART 1 import java.util.Scanner; public class Car { private String make; private String model; private int price; private int year; private static int carNum=0; private static int menu; // default constructor public Car() { this.make=null; this.model=null; this.price=0; this.year=0; } // parametrized constructor public Car(String make, String model, int price, int year){ this.make=make; this.model=model; this.price=price; this.year=year; } // copy constructor public Car(Car aCar){ this.make=aCar.make; this.model=aCar.model; this.price=aCar.price; this.year=aCar.year; } // accessor methods public String getMake() { return make; } public String getModel() { return model; } public int getPrice() { return price; } public int getYear() { return year; } // mutator methods public void setMake(String Make) { this.make = make; } public void setModel(String Model) { this.model = model; } public void setPrice(int Price) {
Image of page 1
this.price = price; } public void setYear(int Price) { this.year = year; } /** * Returns the total number of cars that have been created. * @return an int representing the total number of created cars. */ public static int findNumberOfCreatedCars() { return carNum; } /** * Compares the values of the price of the car to determine if two cars have the same price. * @param other The other Car that is being compared. * @return true if both prices are the same, and false if both are not the same. */ public boolean equals(Car otherCar){ return((price==otherCar.price) && (year==otherCar.year)); } // display car object info public String toString() { return ("Make: "+make+"\n"+ "Model: "+model+"\n"+ "Price: $"+price+"\n"+ "Year: "+year+"\n"); } /** * Searches all the created car objects in database and prints the ones by the desired make and model. * @param make The make the user wishes to search for. * @param model The model the user wishes to search for. */ public static void findCarBy(Car[] carDatabase, String make, String model) { int carsFound = 0; for (int i =0; i<carDatabase.length; i++) { if (carDatabase[i] != null && carDatabase[i].getMake().equals(make) && carDatabase[i].getModel().equals(model)) { System.out.println(carDatabase[i]); System.out.println("");
Image of page 2
Image of page 3

You've reached the end of your free preview.

Want to read all 8 pages?

  • Fall '09
  • Method, Das Model, Mutator method

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture