展开全部
类图设计:
类设计:
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;
}
/**
* 获取汽车编e69da5e6ba9062616964757a686964616f31333337626134号
*
* @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);
}
}