黑马程序员技术交流社区

标题: 交流一下代码 [打印本页]

作者: 酷我之情    时间: 2016-8-18 20:36
标题: 交流一下代码
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;
        }
}






欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2