日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

java二嗨租车项目_Java入门第二季6-1租车项目代码

發布時間:2023/12/1 java 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java二嗨租车项目_Java入门第二季6-1租车项目代码 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一共有5個類

Car類 //作為父類

package com.imooc;

public class Car {

public int ID;

public String name;

public int rent;

public int PersonCapacity;

public int GoodsCapacity;

}

2.passengerCar //客車

public class passengerCar extends Car{

public passengerCar(int newID,String newName,int newRent,int newPersonCapacity){

this.ID = newID;

this.name = newName;

this.rent = newRent;

this.PersonCapacity = newPersonCapacity;

}

}

3.Pickup //皮卡

public class Pickup extends Car{

public Pickup(int newID,String newName,int newRent,int newPersonCapacity,int newGoodsCapacity){

this.ID = newID;

this.name = newName;

this.rent = newRent;

this.PersonCapacity = newPersonCapacity;

this.GoodsCapacity = newGoodsCapacity;

}

}

4.Trunk //貨車

public class Trunk extends Car{

public Trunk(int newID,String newName,int newRent,int newGoodsCapacity){

this.ID = newID;

this.name = newName;

this.rent = newRent;

this.GoodsCapacity = newGoodsCapacity;

}

}

5.StartMain // 主函數

package com.imooc;

import java.util.*;

public class StartMain {

public static void main(String[] args){

Car[] AllCar = {new passengerCar(1,"奧迪A4",500,4),new passengerCar(2,"馬自達6",400,4),new Pickup(3,"皮卡雪",450,4,2),new passengerCar(4,"金龍",800,20),new Trunk(5,"松花江",400,4),new Trunk(6,"依維柯",1000,20)};

System.out.println("歡迎來到租車系統");

System.out.println("您是否要租車:1是 0否");

Scanner input = new Scanner(System.in);

int Acess = input.nextInt();

if(Acess!=1)

return;

System.out.println("您可租車的類型及其價目表:");

System.out.println("序號 汽車名稱 租金 容量 ");

for(int i=0;i

if(AllCar[i] instanceof passengerCar) {

System.out.printf("%-1d. %-6s%-4d元/天 載人:%-1d人%n",AllCar[i].ID,AllCar[i].name,AllCar[i].rent,AllCar[i].PersonCapacity);

}

else if(AllCar[i] instanceof Trunk){

System.out.printf("%-1d. %-6s%-4d元/天 載貨:%-1d噸%n",AllCar[i].ID,AllCar[i].name,AllCar[i].rent,AllCar[i].GoodsCapacity);

}

else{

System.out.printf("%-1d. %-6s%-4d元/天 載人:%-1d人 載貨:%-1d噸%n",AllCar[i].ID,AllCar[i].name,AllCar[i].rent,AllCar[i].PersonCapacity,AllCar[i].GoodsCapacity);

}

}

System.out.println("請輸入您要租汽車的數量:");

int Num = input.nextInt();

//創建一個Car類,存儲被租的汽車對象

Car[] odered = new Car[Num];

//輸入汽車的序號

for(int i = 0;i < Num;i++) {

System.out.println("請輸入第"+ (i+1) +"輛車的序號");

//汽車序號

int id = input.nextInt();

//通過遍歷AllCar里所有汽車的ID,把用戶選擇的車對象放進odered數組

for(int j = 0;j

if(AllCar[j].ID == id){

odered[i]=AllCar[j];

break;

}

}

}

System.out.println("請輸入租車天數");

int days = input.nextInt();

System.out.println("您的賬單:");

System.out.println("***可載人的車有:");

int PassengerNum=0;

int TotalPrice=0;

//這里的算價錢還有問題,皮卡算了兩次價格,待修改。

//隨便修改了一下,第二次屏蔽了皮卡的租金計算,還待優化

for(int i =0;i

if(odered[i] instanceof passengerCar || odered[i] instanceof Pickup){

System.out.println(odered[i].name);

PassengerNum += odered[i].PersonCapacity;

TotalPrice += odered[i].rent;

// System.out.println("第"+(i+1)+"臺車的價錢為:"+odered[i].rent);

}

}

System.out.println("共載人:"+ PassengerNum +"人");

System.out.println("載貨的汽車有:");

int GoodsNum=0;

for(int i = 0;i

if(odered[i] instanceof Trunk || odered[i] instanceof Pickup){

System.out.println(odered[i].name);

GoodsNum +=odered[i].GoodsCapacity;

if(odered[i] instanceof Trunk) {

TotalPrice += odered[i].rent;

}

// System.out.println("第"+(i+1)+"臺車的價錢為:"+odered[i].rent);

}

}

System.out.println("共載貨:"+GoodsNum+"噸");

System.out.printf("***租車總價格:"+(TotalPrice*3)+"元");

}

}

總結

以上是生活随笔為你收集整理的java二嗨租车项目_Java入门第二季6-1租车项目代码的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。