package rentcar; //第一个类
public abstract class Car {
public String name;
public int number;
public double money;
}
package rentcar; //第二个类
public class pikeuptruck extends Car implements Takething{
public int thingnum;
public void takes(){
System.out.println("我可以载货哦");
}
public pikeuptruck(int number,String name,double money,int thingnum){
this.number=number;
this.name=name;
this.money=money;
this.thingnum=thingnum;
}
}
package rentcar; //第三个类
public class Smallcar extends Car {
public int personnum;
public Smallcar(int number,String name,double money, int personnum){
this.number=number;
this.name=name;
this.money=money;
this.personnum=personnum;
}
}
package rentcar; //第四个类
public class truck extends Car implements Takething{
public int thingnum;
public void takes(){
System.out.println("我可以载货哦");
}
public truck(int number,String name,double money,int thingnum){
this.number=number;
this.name=name;
this.money=money;
this.thingnum=thingnum;
package rentcar; //定义一个接口
public interface Takething {
public void takes();
}
}
}
package rentcar; //第五个类
import java.util.Scanner;
import java.util.*;
public class Carsystem {
public Car[] cars={new Smallcar(1,"奥迪A4",500,4),new Smallcar(2,"马自达6",400,4),
new pikeuptruck(3,"皮卡雪6",450,4),new truck(4,"金龙",800,20),new truck(5,"松花江",400,4),
new truck(6,"依维柯",1000,20)
};
public void countmoney11(int[] b,int d){
int countm=0;
int countp=0;
int countt=0;
for(int e=0;e<b.length;e++)
{
switch(b[e])
{
case 1:
countm=countm+500;
countp=countp+4;
break;
case 2:
countm=countm+450;
countp=countp+4;
break;
case 3:
countm=countm+500;
countp=countp+4;
countt=countt+4;
break;
case 4:
countm=countm+800;
countp=countp+20;
break;
case 5:
countm=countm+400;
countt=countt+4;
break;
case 6:
countm=countm+1000;
countt=countt+20;
break;
}
}
System.out.println("可载人的车有:");
for(int e1=0;e1<b.length;e1++)
{
switch(b[e1])
{
case 1:
System.out.println("奥迪A4");
break;
case 2:
System.out.println("马自达6");
break;
case 3:
System.out.println("皮卡雪6");
break;
}
System.out.print("共载人:"+countp);
}
System.out.print("共载人:"+countp);
System.out.println("可载货的车有:");
for(int e1=0;e1<b.length;e1++)
{
switch(b[e1])
{
case 6:
System.out.println("依维柯");
break;
case 5:
System.out.println("松花江");
break;
case 3:
System.out.println("皮卡雪6");
break;
}
}
System.out.print("共载货:"+countt);
System.out.print("租车总价格:"+countm);
}
public static void main(String[] args,int[] cars,int[] b){
System.out.println("欢迎使用达达打车系统");
System.out.println("您是否要租车:1是,2否");
Scanner scan1=new Scanner(System.in);
int p=scan1.nextInt(); //可否使用p.chick();
if(p==1){
System.out.println("您可租的车的类型及价目表:");
System.out.println("序号 汽车名称 租金 容量");
for(int i=0;i<=5;i++){
System.out.println(cars[i]);
}
System.out.println("请输入您要租汽车的数量");
Scanner scan2=new Scanner(System.in);
int q=scan2.nextInt();
if(q!=0){
for(int c=0;q<=0;q--,c++){
System.out.println("请输入第一辆租汽车的序号");
Scanner scan3=new Scanner(System.in);
int a=scan3.nextInt();
b[c]=a;
}
}
System.out.println("请输入您要租汽车的天数:");
Scanner scan4=new Scanner(System.in);
int d=scan4.nextInt();
System.out.println("您的账单:");
Carsystem mycars=new Carsystem();
mycars.countmoney11(b, d);
}
else{
System.out.println("希望您下次光临");
}
}
}
JustWannaHugU
相关分类