Hey guys, I'm working on an assignment which requires me to have one of my constructors to have parameters though I get an error in "Car c2 = new Car();" that it cannot find symbol.
Also I am required to enter the necessary get and set methods to be able to access and change the contents of the car object fields accordingly. Where do I place the get/set methods and what are they?
Thanks
class Car {
String regnum;
String make;
String model;
int price;
Car(String rn, String ma, String mo, int p){
regnum = rn;
make = ma;
model = mo;
price = p;
}
}
class Garage{
public static void main (String args[]){
Car c1 = new Car("ABC123", "BMW", "Saloon",15000);
Car c2 = new Car();
c2.regnum = "DEF123";
c2.make = "Honda";
c2.model = "Hatchback";
c2.price = 8000;
System.out.println("Registration Number: " +c1.regnum);
System.out.println("Make: " +c1.make);
System.out.println("Model: " +c1.model);
System.out.println("Price: " +c1.price);
System.out.println();
System.out.println("Registration Number: " +c2.regnum);
System.out.println("Make: " +c2.make);
System.out.println("Model: " +c2.model);
System.out.println("Price: " +c2.price);
}
}