求助大神来写一个java的小程序,题目如下

2024-11-05 10:33:32
推荐回答(3个)
回答(1):

货不多说直接代码
public class car {

private String car_number;
private float car_price;
private float rebate;//折扣

public float getRebate() {
return rebate;
}
public void setRebate(float rebate) {
this.rebate = rebate;
}
public String getCar_number() {
return car_number;
}
public void setCar_number(String car_number) {
this.car_number = car_number;
}
public float getCar_price() {
return car_price;
}
public void setCar_price(float car_price) {
this.car_price = car_price;
}
//设置价格参数
public void carString() {
car_price=1;
car_number="100";
rebate=1;
}
//修改价格
public void modify(float price){
car car=new car();
car.setRebate(price);;
}
public static void main(String agrs[]) {
car car =new car();
car.carString();//设置参数
System.out.println(car.getRebate());
car.modify((float)0.8);//修改
System.out.println(car.getRebate());
}
}

回答(2):

  public class Car{
  private String color;
  private String type;
  private String num;
  private double price;
private double discount=0.8;

public set.../get...

public double getNewPrice(price){
return price*discount;
}

public Static void main(args[]){
system.out.printlin(.....)
}


}

回答(3):

这不很简单么?
car类
public class Car{
private String car_no;

private String car_name;

private String car_type;

private double car_price;

这里有两个构造方法;

这里有get - set 方法;

}