好車班,我需要編寫代碼,使這個文件使用Java創建
public class HW1tester
{
public static void main(String[] args)
{
Car car1 = new Car();
Car car2 = new Car("Ford", 2013, 20000);
Car car3 = new Car("Audi", 2012, 25000);
Car car4 = new Car();
car2.setPrice(22000);
car2.setYear(2011);
car4.setBrand("Cadillac");
System.out.println("This car is " + car1.getBrand() + ", year " + car1.getYear() + ", price " + car1.getPrice());
System.out.println("This car is " + car2.getBrand() + ", year " + car2.getYear() + ", price " + car2.getPrice());
System.out.println("This car is " + car3.getBrand() + ", year " + car3.getYear() + ", price " + car3.getPrice());
System.out.println("This car is " + car4.getBrand() + ", year " + car4.getYear() + ", price " + car4.getPrice());
System.out.println("The total car number is: " + car1.getNumber());
System.out.println("The total car number is: " + car2.getNumber());
System.out.println("The total car number is: " + car3.getNumber());
System.out.println("The total car number is: " + car4.getNumber());
}
}
到目前爲止,我有這個,但我不知道什麼是地獄,我做錯了。
public class Car
{
private int yearModel;
private String brand;
private int priceModel;
private int numberModel;
public Car(String b, int year, int price, int number)
{
yearModel = year;
brand = b;
priceModel = price;
numberModel = number;
}
public int getYear()
{
return yearModel;
}
public String getBrand()
{
return brand;
}
public int getPrice()
{
return priceModel;
}
public int getNumber()
{
return numberModel;
}
public void setYear(int year)
{
yearModel = year;
}
public void setBrand(String carBrand)
{
brand = carBrand;
}
public void setPrice(int price)
{
priceModel = price;
public void setNumber(int number)
{
numberModel = number;
}
}
每次我現在運行的第一個代碼,它只是給我上CAR1,CAR2等錯誤,我只是似乎無法看到我在做什麼錯可言,我希望有人能幫助我。順便說一下,我無法對HW1tester進行任何更改。
@downvoter閱讀我的完整答案,讓我知道downvote的原因 – gprathour 2014-09-29 03:43:48
任何人都在乎給出理由? – gprathour 2014-09-29 03:44:43
對我來說很不錯 – 2014-09-29 03:45:35