java程序员 达达集团_Java课后项目 达达租车系统

public abstract class Cars {

//创建抽象主类

public int id;

public String name;

public int money;

public int num;

public int day;

public String toString2() {

return id +"\t" + name +"\t"+num+"台\t"+day+"天\t"+money;

}

}

public class Trunk extends Cars{

//Trunk类

private int cap1;

public Trunk(int id,String name,int money,int cap1){

this.id =id;

this.name =name;

this.money =money;

this.cap1=cap1;

}

public String toString() {

return id +"\t" + name +"\t"+money+"\t载货量:"+cap1+"吨";

}

}

public class Bus extends Cars{

//Bus类

private int cap2;

public Bus(int id,String name,int money,int cap2){

this.id =id;

this.name =name;

this.money =money;

this.cap2=cap2;

}

public String toString(){

return id +"\t" + name +"\t"+money +"\t载人数:"+cap2+"人";

}

}

public class Pickup extends Cars{

//皮卡类

private int cap1;

private int cap2;

public Pickup(int id,String name,int money,int cap1,int cap2){

this.id =id;

this.name =name;

this.money =money;

this.cap1=cap1;

this.cap2=cap2;

}

public String toString() {

return id +"\t" + name +"\t"+money+"\t载货量:"+cap1+"吨"+" 载人数:"+cap2+"人";

}

}

import java.util.Scanner;

public class Test {

static int I1=0;

static int I2=0;

static int I3=0;

static int I4=0;

static int I5=0;

static int I6=0;

public static void main(String[] args) {

// TODO Auto-generated method stub

//创建对象

Cars c1 =new Bus(1,"奥迪A6",500,4);

Cars c2 =new Bus(2,"马自达6",400,4);

Cars c3 =new Pickup(3,"皮卡雪6",450,2,4);

Cars c4 =new Bus(4,"金龙",800,20);

Cars c5 =new Trunk(5,"松花江",300,2);

Cars c6 =new Trunk(6,"依维柯",900,10);

Cars Array[]=new Cars[]{c1,c2,c3,c4,c5,c6};

//开始

System.out.println("欢迎使用租车系统!");

System.out.println("您是否要租车?\t1.Y\t2.N");

Scanner input1 =new Scanner(System.in);

if(input1.nextInt() == 1){

System.out.println("您可租用的车型价目表:");

System.out.println("序号\t汽车名称\t日租金\t容量");

//列表

for(int i=0;i

System.out.println(Array[i].toString());

//选车(初始化)

int start =1;

int[] arr=new int[]{I1,I2,I3,I4,I5,I6};

//选车(循环)

do{

System.out.print("请输入想选择的车的序号:");

Scanner input2 =new Scanner(System.in);

int ID=input2.nextInt();

//验证序号合理性

if(ID>6 ||ID<1){

System.out.println("输入错误!没有此序号的车!");

continue;

}

System.out.print("请输入想租的台数:");

Scanner input3 =new Scanner(System.in);

int NUM=input3.nextInt();

//计数

arr[ID-1]=arr[ID-1]+NUM;

Array[ID-1].num =arr[ID-1];

//天数

System.out.print("请输入租车天数:");

Scanner input4 =new Scanner(System.in);

int DAY =input4.nextInt();

Array[ID-1].day +=DAY;

//询问循环

System.out.println("请问还要继续租车吗?\t1.Y\t2.N");

Scanner input5 =new Scanner(System.in);

start =input5.nextInt();

}while(start ==1);

//输出订单

int MONEY=0;

System.out.println("您的订单:");

System.out.println("序号\t名称\t数量\t天数\t日租金");

for(int j=0;j

if(arr[j]!=0)

System.out.println(Array[j].toString2());

//计算租金

MONEY =(Array[j].day *Array[j].num *Array[j].money )+ MONEY;

}

System.out.println("总租金为:"+MONEY);

}

System.out.println("谢谢使用。");

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值