Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Car
- {
- private String make;
- private String model;
- private int year = 0;
- private int price = 0;
- private int totalPrice = 0;
- public Car(String name)
- {
- this.make = make;
- this.model = model;
- year = 0;
- price = 0;
- totalPrice = 0;
- }
- public void setMake (String mak)
- {
- make = mak;
- }
- public void setModel (String mod)
- {
- model = mod;
- }
- public void setYear (int yr)
- {
- year = yr;
- }
- public void setPrice (int prc)
- {
- price = prc;
- }
- public void settotalPrice (int tprc)
- {
- totalPrice = tprc;
- }
- public String getMake()
- {
- return make;
- }
- public String getModel()
- {
- return model;
- }
- public int getYear()
- {
- return year;
- }
- public int getPrice()
- {
- return price;
- }
- public int gettotalPrice()
- {
- return totalPrice;
- }
- public static void main(String[] args)
- {
- Car dodge = new Car("Dodge Dakota");
- dodge.setMake("Dodge");
- dodge.setModel("Dakota");
- dodge.setYear(2000);
- dodge.setPrice(15000);
- System.out.println("The car " + dodge.getMake() + " " + dodge.getModel() + " was made in the year " + dodge.getYear() + " for roughly " + dodge.getPrice() + " US dollars.");
- Car honda = new Car("Honda CRV");
- honda.setMake("Honda");
- honda.setModel("CRV");
- honda.setYear(2009);
- honda.setPrice(20000);
- System.out.println("The car " + honda.getMake() + " " + honda.getModel() + " was made in the year " + honda.getYear() + " for roughly " + honda.getPrice() + " US dollars.");
- Car pontiac = new Car("Pontiac LeMans");
- pontiac.setMake("Pontiac");
- pontiac.setModel("LeMans");
- pontiac.setYear(1970);
- pontiac.setPrice(3500);
- System.out.println("The car " + pontiac.getMake() + " " + pontiac.getModel() + " was made in the year " + pontiac.getYear() + " for roughly " + pontiac.getPrice() + " US dolalrs.");
- Car totalPrice = new Car("Total Price");
- totalPrice.setPrice(dodge.getPrice() + honda.getPrice() + pontiac.getPrice());
- System.out.println("The total price of all three cars is " + totalPrice.gettotalPrice());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement