练习

public class chengfa {

  private int shu;
  private   int shu2;


public void getShu(int shu)
{
    this.shu=shu;
}
    public void getShu2(int shu)
    {
        this.shu2=shu;
    }


   public void jisuan()
   {
       System.out.println("How much is"+" "+shu+" "+"times"+" "+shu2);
   }

   public int panduan(int jieguo)
   {
       if (shu*shu2==jieguo)
       {
           System.out.println("Very good");
           System.out.println("下一题");

       }
       else {
           System.out.println("No.Please try again");
           cuowu();

       }
       return jieguo;

   }

   public void cuowu()
   {
       int zaiyici=shu*shu2;
       Scanner scanner = new Scanner(System.in);

       for (int i =0;i>-1;i++)
       {
           System.out.println("重复该题");
           System.out.println("How much is"+shu+" "+"times"+" "+shu2);
           int jieguo2=scanner.nextInt();
           if (jieguo2==zaiyici){
               System.out.println("Very good");
               break;
           }

       }

   }

}

public class main2 {
    public static void main(String[] args) {
        chengfa cheng =new chengfa();

       for (int i = 0;i>-1;i++)
       {
         int shu =(int)(Math.random()*10);
         cheng.getShu(shu);
          int shu2  = (int) (Math.random() * 10);
           cheng.getShu2(shu2);
           cheng.jisuan();
           Scanner scanner = new Scanner(System.in);
           System.out.println("输入答案");
           int jieguo = scanner.nextInt();
           cheng.panduan(jieguo);
       }

    }
}

public abstract class MotoVehicle {
    private String no;//车牌号
    private String brand;//品牌

    abstract int calRent(int days);//计算租金

    public MotoVehicle()
    {

    }
    public MotoVehicle(String no, String brand)
    {
        this.no = no;
        this.brand = brand;
    }

    public String getNo() {
        return no;
    }

    public void setNo(String no) {
        this.no = no;
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }


}
public class Car extends MotoVehicle{


    public Car(String no, String brand)
    {
        super(no,brand);

    }
    @Override
    int calRent(int days) {
        if(getBrand().equals("宝马"))
        {
            return 500 * days;
        }
        else
        {
            return 600 * days;
        }

    }
}
public class Bus extends MotoVehicle {

    private int seatCount;

    public int getSeatCount() {
        return seatCount;
    }

    public void setSeatCount(int seatCount) {
        this.seatCount = seatCount;
    }

    public Bus(String no, String brand, int seatCount)
    {
        super(no,brand);
        this.seatCount = seatCount;
    }

    @Override
    int calRent(int days) {
        if (seatCount<=16)
        {
            return 800*days;
        }
        else {
            return 1500*days;
        }
    }
}
public class TestRent {
    public static void main(String[] args) {
        System.out.println("欢迎");
        System.out.println("请输入天数");
        Scanner scanner =  new Scanner(System.in);
        int days = scanner.nextInt();
        System.out.println("请输入汽车类型1.轿车,2.客车");
        int type = scanner.nextInt();
        if(type == 1)
        {
            System.out.println("输入品牌");
            String brand = scanner.next();

            Car car = new Car("辽N12345",brand);
            int money = car.calRent(days);
            System.out.println("租金为"+money);
        }
        else
        {

            System.out.println("输入座位数");
            int seatCount=scanner.nextInt();

           Bus bus = new Bus("liaoN3412","金龙",seatCount);
           int money = bus.calRent(days);
            System.out.println("租金为"+money);
        }
    }


}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语...
    子非鱼_t_阅读 31,974评论 18 399
  • 三、RSA scalabilityRSA可扩展性 Obviously a post-quantum RSA pub...
    jorson2000阅读 3,698评论 0 0
  • 大巴车穿行 在运河的堤岸 屋顶紫色的三角梅 盛开着这个夏天 你在我的座前 车里响起一首歌 "夜空中最亮的星" 你迷...
    北疆牧者阅读 3,304评论 1 4
  • 加缪是不相信明天的,他不只一次大声对未来说不,对今天说是。 文│吴春晖 加缪是穷人家的孩子,他不是在书本中学到自由...
    KSZxMX阅读 5,090评论 0 3
  • 感恩2017 你好2018 日子很快 转眼一年 酸甜苦辣 一杯酒 风霜雨雪 当如歌
    安心100阅读 1,358评论 0 1