JAVA题,新手求解 50
2015-12-04 · 做真实的自己 用良心做教育
类图设计:
类设计:
package car;
public class Car {
private String id;
private String name;
public void setId(String id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
/**
* 获取汽车编号
*
* @return
*/
public String getId() {
return id;
}
/**
* 获取汽车名称
*
* @return
*/
public String getName() {
return name;
}
public Car(String id, String name) {
this.id = id;
this.name = name;
}
}
package car;
public class Seller {
private String name;
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
/**
* 卖一批车
* @param car
* @param num
*/
public void sell(Car car,int num){
System.out.println("卖了一批车,名称:"+car.getName()+"id:"+car.getId());
}
/**
* 卖一辆车
* @param car
*/
public void sell(Car car){
System.out.println("卖了一辆车,名称:"+car.getName()+"id:"+car.getId());
}
}
主类:
package car;
public class TestSell {
public static void main(String[] args) {
Car c1 = new Car("1000","君越");
Seller s1 = new Seller();
s1.sell(c1);
//卖100辆车
s1.sell(c1, 100);
}
}
如果对回答满意,请点【采纳答案】,如果还有问题,请点【追问】
希望我的回答对您有所帮助,希望能采纳。
可以先发给我吗,可以追加悬赏
public class Car {
private String type;
private String id;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
public class Seller {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void sell(String type) {
System.out.println(this.name + "卖出了一辆" + type);
}
public void sell(String type,int number) {
System.out.println(this.name + "卖出了" + number + type );
}
}
public static void main(String[] args) {
Car kaiyue = new Car();
kaiyue.setId("001");
kaiyue.setType("kaiyue");
Car junwei = new Seller();
kaiyue.setId("002");
kaiyue.setType("junwei");
Seller seller = new Seller();
seller.setName("xiaowang");
seller.sell(kaiyue.getType());
seller.sell(junwei.getType(),15);
}