手记

Java第二季租车系统的项目程序

//父类
package com.xianmu;

public abstract class Car {
public Car()
{
System.out.println("车型有");
System.out.println("皮卡车1,皮卡车2,客车1,客车2");
}
public int number;
public abstract void price(int number);
public abstract void chexing();
public abstract void zaihuo(int number);
public abstract void zairen(int number);

}


//子类客车1
package com.xianmu;

public class kache2 extends Car {
public int price=111;
public String carname="卡车1";
public int huoliang=11;
public int renliang=1;
public int number;
@Override
public void price(int number) {
// TODO Auto-generated method stub
System.out.println("总金额为"+(number*price));
}

@Override
public void chexing() {
    // TODO Auto-generated method stub
    System.out.println(carname);
}

@Override
public void zaihuo(int number) {
    // TODO Auto-generated method stub
    System.out.println("总载货量为"+(number*huoliang));
}

@Override
public void zairen(int number) {
    // TODO Auto-generated method stub
    System.out.println("总载人量为"+(number*renliang));
}

}


//子类卡车1
package com.xianmu;

public class kache1 extends Car {
public int price=222;
public String carname="卡车2";
public int huoliang=22;
public int renliang=2;
public int number;
@Override
public void price(int number) {
// TODO Auto-generated method stub
System.out.println("总金额为"+(number*price));
}

@Override
public void chexing() {
    // TODO Auto-generated method stub
    System.out.println(carname);
}

@Override
public void zaihuo(int number) {
    // TODO Auto-generated method stub
    System.out.println("总载货量为"+(number*huoliang));
}

@Override
public void zairen(int number) {
    // TODO Auto-generated method stub
    System.out.println("总载人量为"+(number*renliang));
}

}


package com.xianmu;

public class ceshi {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    kache1 a=new kache1();
    kache2 b=new kache2();
    final int qq=3;
    final int ww=5;
    a.chexing();
    a.price(qq);
    a.zaihuo(qq);
    a.zairen(qq);
    b.chexing();
    b.price(ww);
}

}

0人推荐
随时随地看视频
慕课网APP