手记

Java入门第二季租车系统


/client/

package didi;
import java.util.Scanner;

public class Client {

public static void main(String[] args) {
    Car[] cars={
            new MannedCar("奥迪A4",4,500),
            new MannedCar("马自达6",4,500),
            new Pickup("皮雪卡6", 2, 4, 450),
            new MannedCar("金龙",20,800),
            new Trunk("松花江",4,400),
            new Trunk("依维柯",20,1000)                
    };
    // TODO Auto-generated method stub
    System.out.println("欢迎使用租车系统");
    System.out.println("您是否要租车?");
    Scanner in = new Scanner(System.in);
    int input = in.nextInt();
    if(input==0){
        System.out.println("下次光临");
        System.exit(0);
    }
    else if(input==1){
        for(int i=0;i<cars.length;i++){
            System.out.print(i+":");
            cars[i].getList();
            System.out.println();

        }           
    }
    System.out.println("请输入你想租车的数量");
    Scanner in_1 = new Scanner(System.in);
    int num = in_1.nextInt();
    Car[] cars1 = new Car[num];
    for(int i=0;i<num;i++){
        System.out.println("第"+(i+1)+"辆为:");
        Scanner in_2 = new Scanner (System.in);
        cars1[i]=cars[in_2.nextInt()];
        }
    System.out.println("请输入租车的天数");
    Scanner in_3 = new Scanner(System.in);
    int day = in_3.nextInt();
    System.out.println("总价为:");
    int sum=0;
    for(int i=0;i<num;i++){
         sum+=cars1[i].getRent();

    }
    sum=sum*day;
    System.out.print(sum+"元");

}

}

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