首页 > IT职业 > IT生活 > java小项目,租车系统
这学期要学java,本以为暑假学windows程序设计的,没想到一些事情耽误了 ,只能回来再补了,因为学过c++,面向对象的三大特性什么的,c++比java难一点,所以学java感觉还比骄轻松,下面就是一个小项目,租车系统
抽象汽车类Auto.ava
package hireAuto;
public abstract class Auto {
//抽象类没必要定义属性,但是取得车型,价格,容量都是一样的,不妨定义属性
String name;
int price;
int capacity;//表示载人
int capacity2;//表示载货
int a;//a为1则表示可以载人,反之不可
int b;//b为1则表示可以载货,反之不可
public String getName()
{
return name;
}
public int getPrice()
{
return price;
}
public int getCapacity()
{
return capacity;
}
public int getCapacity2()
{
return capacity2;
}
//只有运输不同
public abstract void transport();//运输,货车载人,客车载客
} A.java
package hireAuto;
public class A extends Auto {
public A()
{
this.name="奥迪A4";
this.price=500;
this.capacity=4;
this.capacity2=0;
this.a=1;
this.b=0;
}
public void transport()
{
System.out.println(this.getName()+"t"+this.getPrice()+"元/天tt"+"载人:"+this.getCapacity()+"人");
}
} B.java
package hireAuto;
public class B extends Auto {
public B()
{
this.name="马自达6";
this.price=400;//单位:元/天
this.capacity=4;//单位:人
this.capacity2=0;
this.a=1;
this.b=0;
}
public int getPricePerDay()
{
return getPrice()*getCapacity();
}
public void transport()
{
System.out.println(this.getName()+"t"+this.getPrice()+"元/天tt"+"载人:"+this.getCapacity()+"人");
}
} C.java
package hireAuto;
public class C extends Auto {
int capacity2;//单位:吨
public C()
{
this.name="皮卡雪6";//即可载人,也可载货
this.price=450;//单位:元/天
this.capacity=4;//单位:人
this.capacity2=2;//单位:吨
this.a=1;
this.b=1;
}
public int getCapacity2()
{
return capacity2;
}
public void transport() {
// TODO Auto-generated method stub
System.out.println(getName()+"t"+getPrice()+"元/天tt"+"载人:"+getCapacity()+"人 载货:"+getCapacity2()+"吨");
}
} D.java
package hireAuto;
public class D extends Auto {
public D()
{
this.name="金龙";
this.price=800;//单位:元/天
this.capacity=20;//单位:人
this.capacity2=0;
this.a=1;
this.b=0;
}
@Override
public void transport() {
// TODO Auto-generated method stub
System.out.println(getName()+"t"+getPrice()+"元/天tt"+"载人:"+getCapacity()+"人");
}
} E.java
package hireAuto;
public class E extends Auto {
public E()
{
this.name="松花江";
this.price=400;//单位:元/天
this.capacity=0;
this.capacity2=4;
this.a=0;
this.b=1;
}
@Override
public void transport() {
// TODO Auto-generated method stub
System.out.println(getName()+"t"+getPrice()+"元/天tt"+"载货:"+getCapacity()+"吨");
}
} F.java
package hireAuto;
public class F extends Auto {
public F()
{
this.name="依维柯";
this.price=1000;//单位:元/天
this.capacity=0;//单位:吨
this.capacity2=20;
this.a=0;
this.b=1;
}
@Override
public void transport() {
// TODO Auto-generated method stub
System.out.println(getName()+"t"+getPrice()+"元/天t"+"载货:"+getCapacity()+"吨");
}
} hireAutoSystem.java(相当于c++的主函数了)
package hireAuto;
import java.util.Scanner;
public class hireAutoSystem {
public static void main(String[] args) {
// TODO Auto-generated method stub
final int count=6;//可租用的数量
System.out.println("欢迎来到滴滴租车系统");
System.out.println("是否租车:1(是),0(否)");
Scanner input=new Scanner(System.in);
int iSel=input.nextInt();
if(iSel==0)
{
System.out.println("欢迎使用此系统,再见");
return ;
}
System.out.println("下面是可租车的类型及价格等信息");
System.out.println("序号t汽车型号t租金tt容量");
Auto[] autoArr=new Auto[6];
autoArr[0]=new A();
autoArr[1]=new B();
autoArr[2]=new C();
autoArr[3]=new D();
autoArr[4]=new E();
autoArr[5]=new F();
for(int i=0;icount)
{
System.out.println("对不起,输入数量有误!!!再见");
return;
}
int[] auto=new int[iCount];
System.out.println("请依次输入要租车的序号");
for(int i=0;i 来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/3643/viewspace-2799458/ ,如需转载,请注明出处,否则将追究法律责任。