A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 酷我之情 中级黑马   /  2016-8-18 20:36  /  380 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

import java.util.Scanner;
class Demo3_Car {
        public static void main(String[] args) {
                Scanner sc = new Scanner(System.in);
                ZuCheVanload zc = new ZuCheVanload("三菱",6);
                System.out.println(zc.getBrand() + "车,有" + zc.getWheel() + "个车轮");
                zc.run();
                int i = sc.nextInt();
                zc.ZhuChe(i);
                System.out.println("租车总金为" + zc.ZhuChe(i) + "元");
                System.out.println("-----------------------------");
               
                ZuCheMinbus zb = new ZuCheMinbus("奔驰",4);
                System.out.println(zb.getBrand() + "车,有" + zb.getWheel() + "个车轮");
                int j = sc.nextInt();
                zb.ZhuChe(j);
                System.out.println("租车总金为" + zb.ZhuChe(j) + "元");
                Minbus z = new Minbus();
                z.run();


        }
}
abstract class Car {
        private String brand;
        private int wheel;


        public Car() {}


        public Car(String brand,int wheel) {
                this.brand = brand;
                this.wheel = wheel;
        }
        public void setBrand(String brand) {
                this.brand = brand;
        }
        public String getBrand() {
                return brand;
        }
        public void setWheel(int wheel) {
                this.wheel = wheel;
        }
        public int getWheel() {
                return wheel;
        }
        public abstract void run();
}
class Vanload extends Car {
        public Vanload() {}


        public Vanload(String brand,int wheel) {
                super(brand,wheel);
        }
        public void run() {
                System.out.println("每小时90km");
        }
}
class Minbus extends Car {
        public Minbus() {}


        public Minbus(String brand,int wheel) {
                super(brand,wheel);
        }
        public void run() {
                System.out.println("每小时180km");
        }
}
interface ZhuCheMony {
        public abstract int ZhuChe(int i);
}
class ZuCheVanload extends Vanload implements ZhuCheMony {
        public ZuCheVanload() {}


        public ZuCheVanload(String brand,int wheel) {
                super(brand,wheel);
        }
        public int ZhuChe(int i) {
                int sum = 0;
                if (i <= 2 && i >= 0) {
                        sum = 300 * i;
                       
                }else if (i > 2){
                        sum = 600+400 * (i - 2);
                       
                }else {
                        System.out.println("对不起,你输入有误");
                }
                return sum;
        }
}
class ZuCheMinbus extends Vanload implements ZhuCheMony {
        public ZuCheMinbus() {}


        public ZuCheMinbus(String brand,int wheel) {
                super(brand,wheel);
        }
        public int ZhuChe(int i) {
                int sum = 0;
                if (i <= 2 && i >= 0) {
                        sum = 100 * i;
                }else if(i > 2){
                        sum = 200 + 150 * (i-2);
                }else {
                        System.out.println("对不起,你输入有误");
                }
                return sum;
        }
}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马