課程作業(yè)嗒嗒租車系統(tǒng) 源碼如下 不同看法可以交流
Car.java
package com.dada.test;
public class Car {
private int id;
private String name;
private int price;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public Car(int id, String name, int price) {
super();
this.id = id;
this.name = name;
this.price = price;
}
}
GoodCar.java
package com.dada.test;
public class GoodCar extends Car {
private int goodcapacity;
public GoodCar(int id, String name, int price, int goodcapacity) {
super(id, name, price);
this.goodcapacity = goodcapacity;
}
public int getGoodcapacity() {
return goodcapacity;
}
public void setGoodcapacity(int goodcapacity) {
this.goodcapacity = goodcapacity;
}
}
GPCar.java
package com.dada.test;
public class GPCar extends Car {
private int goodcapacity;
private int peoplecapacity;
public GPCar(int id, String name, int price, int goodcapacity, int peoplecapacity) {
super(id, name, price);
this.goodcapacity = goodcapacity;
this.peoplecapacity = peoplecapacity;
}
public int getGoodcapacity() {
return goodcapacity;
}
public void setGoodcapacity(int goodcapacity) {
this.goodcapacity = goodcapacity;
}
public int getPeoplecapacity() {
return peoplecapacity;
}
public void setPeoplecapacity(int peoplecapacity) {
this.peoplecapacity = peoplecapacity;
}
}
PeopleCar.java
package com.dada.test;
public class PeopleCar extends Car {
private int peoplecapacity;
public PeopleCar(int id, String name, int price, int peoplecapacity) {
super(id, name, price);
this.peoplecapacity = peoplecapacity;
}
public int getPeoplecapacity() {
return peoplecapacity;
}
public void setPeoplecapacity(int peoplecapacity) {
this.peoplecapacity = peoplecapacity;
}
}
Test.java
package com.dada.test;
import java.util.Scanner;
import com.dada.test.*;
public class Test {
public static void main(String[] args) {
PeopleCar pc1 = new PeopleCar(1,"奧迪A4",500,4);
PeopleCar pc2 = new PeopleCar(2,"馬自達(dá)6",400,4);
GPCar gpc = new GPCar(3,"皮卡雪6",450,2,4);
PeopleCar pc3 = new PeopleCar(4,"金龍",800,20);
GoodCar gc1 = new GoodCar(5,"松花江",400,4);
GoodCar gc2 = new GoodCar(6,"依維柯",1000,20);
Scanner sc = new Scanner(System.in);
boolean keep = true;
System.out.println("*********嗒嗒租車系統(tǒng)*********");
while(keep){
System.out.print("是否租用汽車1/0:");
if("0".equals(sc.next())){
System.out.println("*********系統(tǒng)已退出*********");
break;
}
?
System.out.println("您可租車的類型及價(jià)目表:");
System.out.println("1. 奧迪A4 500元/天 載人:4人\n" +"2. 馬自達(dá)6 400元/天 載人:4人\n" +"3. 皮卡雪6 450元/天 載人:4人載貨:2噸\n"+"4. 金龍 800元/天 載人:20人\n"+"5. 松花江 400元/天 載貨:4噸\n"+"6. 依維柯 1000元/天 載貨:20噸\n");
int peoplesum=0;
int goodsum=0;
int pricesum=0;
String carname="";
System.out.print("輸入你租用車的數(shù)量:");
int carnum = sc.nextInt();
System.out.print("請(qǐng)輸入你租用車的天數(shù):");
int day =sc.nextInt();
for(int i=0;i<carnum;i++){
System.out.print("輸入你租用第" + (i+1) + "倆車的id:");
int id = sc.nextInt();
if(id==1){
carname +=pc1.getName()+"? ";
peoplesum += pc1.getPeoplecapacity();
pricesum += pc1.getPrice()*day;
}else if(id==2){
carname +=pc2.getName()+"? ";
peoplesum += pc2.getPeoplecapacity();
pricesum += pc2.getPrice()*day;
}else if(id==3){
carname +=gpc.getName()+"? ";
peoplesum += gpc.getPeoplecapacity();
goodsum += gpc.getGoodcapacity();
pricesum += gpc.getPrice()*day;
}else if(id==4){
carname +=pc3.getName()+"? ";
peoplesum += pc3.getPeoplecapacity();
pricesum += pc3.getPrice()*day;
}else if(id==5){
carname +=gc1.getName()+"? ";
goodsum += gc1.getGoodcapacity();
pricesum += gc1.getPrice()*day;
}else if(id==6){
carname +=gc2.getName()+"? ";
goodsum += gc2.getGoodcapacity();
pricesum += gc2.getPrice()*day;
}else{
System.out.println("您輸入的id有誤!");
}
}
System.out.println("選擇的車有:"+carname );
System.out.println("租金:"+pricesum);
System.out.println("載人量:"+peoplesum+"人");
System.out.println("載貨量:"+goodsum+"噸");
}
}
}
2019-02-04
你這個(gè)代碼有一些問題??
當(dāng)你在選擇是否租車的時(shí)候 沒有考慮0/1之外的其他情況 比如輸入3的話也會(huì)進(jìn)入選車界面
當(dāng)你輸入要租的車輛序號(hào)時(shí),如果輸入一個(gè)錯(cuò)誤的車輛序號(hào),比如11,這時(shí)會(huì)提示輸入錯(cuò)入,重新輸入
就像這樣,用戶會(huì)少選擇一輛車
2019-03-08
請(qǐng)問一下,如果需要租用兩種汽車,該腫么辦?
2019-01-20
//Car.java
//MannedCar.java
? ??
//PikaCar.java
//CarryCargoCar.java
//Text.java
2019-01-17