Problem:
Design and implement a class called Car that contains instance data that represents the make, model, and year of the car. Define the Car constructor to initialize these values. Include getter and setter methods for all instance data, and a toString method that returns a one-line description of the car. Create a driver class called CarTest, whose main method instantiates and updates several Car objects.
Solution:
public class Car
{
private String make;
private String model;
private int year;
public Car(String make,String model,int year)
{
this.make = make;
this.model= model;
this.year = year;
}
public String setCarMake(String make)
{
this.make = make;
return make;
}
public String getCarMake()
{
return make;
}
public String setCarModel(String model)
{
this.model = model;
return model;
}
public String getCarModel()
{
return model;
}
public int setCarYear(int year)
{
this.year = year;
return year;
}
public int getCarYear()
{
return year;
}
public String toString()
{
return "Car make: " + make + "
Car model: " + model + " Car Year:" + year;
}
public static void main (String[] args)
{
Car car1 = new Car("Toyota", "Corolla" , 1996);
Car car2 = new Car("Nissan", "Murano" , 2004);
Car car3 = new Car("Infinity", "Mazda" , 2013);
car1.setCarMake("BMW");
System.out.println(car1);
System.out.println(car1.getCarYear());
car2.setCarModel("Altima");
System.out.println(car2);
System.out.println(car2.getCarMake());
car3.setCarYear(2012);
System.out.println(car3);
System.out.println(car3.getCarModel());
}
}
Excellent .. Amazing .. I’ll bookmark your blog and take the feeds also…I’m happy to find so many useful info here in the post, we need work out more techniques in this regard, thanks for sharing. Revs check
ReplyDeleteYour post has those facts which are not accessible from anywhere else. It’s my humble request to u please keep writing such remarkable articles Toronto Limousine Service
ReplyDeleteWe are really grateful for your blog. Many things are here to learn. Extended Car Warranty
ReplyDeleteExtremely pleasant article, I appreciated perusing your post, exceptionally decent share, I need to twit this to my adherents. Much appreciated!. Hamilton Wedding Limo
ReplyDeleteThis is very interesting content! I have thoroughly enjoyed reading your points and have come to the conclusion that you are right about many of them. You are great. Party Bus Toronto
ReplyDeletelocked keys in nissan versa https://carleg.com/locked-keys-in-2010-Nissan-Versa-SL-Hatchback
ReplyDeleteA few experts offer versatile enumerating administrations to give their clients accommodation and genuine feelings of serenity, as the last can watch their car getting expertly cleaned. car detailing north york
ReplyDeleteCars and minivans went under the Dodge nameplate, while its trucks, the Dodge Ram and Dodge Dakota, became Ram trucks. If you're looking at a used truck that comes from an earlier model year, it's a Dodge Ram. jaxcjdrwestside.com
ReplyDeleteThe issue was the more seasoned set up instructor, great or impassive, continued being allotted the better classes. Best Dissertation Writing Service UK
ReplyDeleteThe electric car is presently generally well known with organizations who need to develop an eco-accommodating picture. The primary Peugeot iOn was conveyed to the UK for the EDF Energy Company. ev charging point installation
ReplyDeleteI like to add about 20% to my max limit to allow for cars that can be negotiated within the budget. fuel consumption calculator
ReplyDeleteCar ac behavior code plz
ReplyDeleteThanks so much for sharing this awesome info! I am looking forward to see more postsby you! Car Accessories
ReplyDeletesite promotion will always be a tedious job but you can outsource site promotion on some indian or pakistani guy` أشهر المعالم في مدينة طرابزون
ReplyDeleteoffroad outlaws mod apk download
ReplyDeleteThis post is so useful and relevant. Too easy to understand. Thanks for your post. Keep blogging
ReplyDeletecheap car rental auckland
genshin impact mod apk | genshin impact mod apk | roblox mod apk
ReplyDelete