課程
/后端開發(fā)
/Java
/Java入門第二季 升級版
求源碼
2017-10-20
源自:Java入門第二季 升級版 12-1
正在回答
把所有的代碼放在一起了,不然不好弄
package com.imooc.dd;
import java.util.Scanner;
public class main {
public main(String[] args) {
int[] cx = null;? //存放出借車的序列
int num = 0;? ? ?//所有出借車的價(jià)格之和
Car[] cars = {new ZaiHuoCar("松花江", 800, 3, 5), new ZaiHuoCar("松花江plus", 2000, 0, 20), new ZaiKeCar("奧迪", 300, 2, 20), new ZaiKeCar("金龍", 800, 30, 4), new PiKaCar("皮卡1", 200, 4, 2), new PiKaCar("皮卡2", 500, 2, 4)};
Scanner input = new Scanner(System.in);
System.out.println("歡迎使用達(dá)達(dá)租車系統(tǒng):");
System.out.println("你是否要租車:1是 0否");
int t = input.nextInt();
if (t == 1) {
System.out.println("您可租車的類型及其價(jià)目表:");
System.out.println("序號\t汽車類型\t汽車名稱\t租金\t容量");
for (int i = 0; i < cars.length; i++) {
System.out.println((i+1) + ".\t" + cars[i].user());
}
System.out.println("請輸入您要租車的數(shù)量:");
int q = input.nextInt();? //出借車的數(shù)量
cx = new int[q];
for (int i = 0; i < q; i++) {
System.out.println("請輸入第" + (i+1) + "輛車的序列:");
cx[i] = input.nextInt();
System.out.println("請輸入您要租車的天數(shù):");
int day = input.nextInt();? //出借車的天數(shù)
System.out.println("您的帳單:");
System.out.println("***可載人的車有:");
if (cars[cx[i]-1].zr != 0) {
System.out.print("\t" + cars[cx[i]-1].name);
num += cars[cx[i]-1].zr;
System.out.println("\t共載人:" + num + "人");
num = 0;
System.out.println("***載貨的車有:");
if(cars[cx[i]-1].zh != 0) {
num += cars[cx[i]-1].zh;
System.out.println("\t共載貨:" + num + "噸");
num += cars[cx[i]-1].penny;
System.out.print("***租車總價(jià)格:" + num*day);
} else {
System.out.println("退出系統(tǒng)!");
/**
*? 所有車的父類
*/
public abstract class Car {
String kinds;? //車的種類
String name;? //車的名字
int penny;? ? //租車每天的價(jià)格
int zr;? ? ? ?//載人量
int zh;? ? ? ?//載貨量
public abstract String user();
* 載貨車
public class ZaiHuoCar extends Car {
public ZaiHuoCar(String name, int penny, int zr, int zh) {
super.name = name;
super.penny = penny;
if (zr != 0) {
super.zr = 0;
if (zh <= 0) {
System.out.println("輸入的載貨量有誤!");
} else if (zh >0 && zh < 10) {
super.kinds = "輕型貨運(yùn)車";
super.zh = zh;
super.kinds = "重型貨運(yùn)車";
@Override
public String user() {
return kinds + "\t" + name + "\t" + penny + "元/天\t載貨:" + zh + "噸";
* 載客車
public class ZaiKeCar extends Car {
public ZaiKeCar(String name, int penny, int zr, int zh) {
if (zh != 0) {
super.zh = 0;
if (zr <= 0) {
System.out.println("輸入的載人數(shù)有誤!");
} else if (zr >0 && zr < 10) {
super.kinds = "小客車";
super.zr = zr;
super.kinds = "大客車";
return kinds + "\t" + name + "\t" + penny + "元/天\t載人:" + zr + "人";
* 皮卡車
public class PiKaCar extends Car {
public PiKaCar(String name, int penny, int zr, int zh) {
super.kinds = "皮卡";
if (zr <= 0 || zr > 5) {
if (zh > 0 && zh < 5) {
return kinds + "\t" + name + "\t" + penny + "元/天\t載人:" + zr + "人 載貨:" + zh + "噸";
舉報(bào)
課程升級!以終為始告別枯燥,在開發(fā)和重構(gòu)中體會Java面向?qū)ο缶幊痰膴W妙
1 回答答答租車系統(tǒng)
2 回答答答租車系統(tǒng)
3 回答答答租車系統(tǒng)標(biāo)準(zhǔn)代碼
4 回答菜鳥做的答答租車系統(tǒng)
2 回答嗒嗒租車系統(tǒng)答案
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2019-05-25
把所有的代碼放在一起了,不然不好弄
package com.imooc.dd;
import java.util.Scanner;
public class main {
public main(String[] args) {
int[] cx = null;? //存放出借車的序列
int num = 0;? ? ?//所有出借車的價(jià)格之和
Car[] cars = {new ZaiHuoCar("松花江", 800, 3, 5), new ZaiHuoCar("松花江plus", 2000, 0, 20), new ZaiKeCar("奧迪", 300, 2, 20), new ZaiKeCar("金龍", 800, 30, 4), new PiKaCar("皮卡1", 200, 4, 2), new PiKaCar("皮卡2", 500, 2, 4)};
Scanner input = new Scanner(System.in);
System.out.println("歡迎使用達(dá)達(dá)租車系統(tǒng):");
System.out.println("你是否要租車:1是 0否");
int t = input.nextInt();
if (t == 1) {
System.out.println("您可租車的類型及其價(jià)目表:");
System.out.println("序號\t汽車類型\t汽車名稱\t租金\t容量");
for (int i = 0; i < cars.length; i++) {
System.out.println((i+1) + ".\t" + cars[i].user());
}
System.out.println("請輸入您要租車的數(shù)量:");
int q = input.nextInt();? //出借車的數(shù)量
cx = new int[q];
for (int i = 0; i < q; i++) {
System.out.println("請輸入第" + (i+1) + "輛車的序列:");
cx[i] = input.nextInt();
}
System.out.println("請輸入您要租車的天數(shù):");
int day = input.nextInt();? //出借車的天數(shù)
System.out.println("您的帳單:");
System.out.println("***可載人的車有:");
for (int i = 0; i < q; i++) {
if (cars[cx[i]-1].zr != 0) {
System.out.print("\t" + cars[cx[i]-1].name);
num += cars[cx[i]-1].zr;
}
}
System.out.println("\t共載人:" + num + "人");
num = 0;
System.out.println("***載貨的車有:");
for (int i = 0; i < q; i++) {
if(cars[cx[i]-1].zh != 0) {
System.out.print("\t" + cars[cx[i]-1].name);
num += cars[cx[i]-1].zh;
}
}
System.out.println("\t共載貨:" + num + "噸");
num = 0;
for (int i = 0; i < q; i++) {
num += cars[cx[i]-1].penny;
}
System.out.print("***租車總價(jià)格:" + num*day);
} else {
System.out.println("退出系統(tǒng)!");
}
}
/**
*? 所有車的父類
*/
public abstract class Car {
String kinds;? //車的種類
String name;? //車的名字
int penny;? ? //租車每天的價(jià)格
int zr;? ? ? ?//載人量
int zh;? ? ? ?//載貨量
public abstract String user();
}
/**
* 載貨車
*/
public class ZaiHuoCar extends Car {
public ZaiHuoCar(String name, int penny, int zr, int zh) {
super.name = name;
super.penny = penny;
if (zr != 0) {
super.zr = 0;
}
if (zh <= 0) {
System.out.println("輸入的載貨量有誤!");
} else if (zh >0 && zh < 10) {
super.kinds = "輕型貨運(yùn)車";
super.zh = zh;
} else {
super.kinds = "重型貨運(yùn)車";
super.zh = zh;
}
}
@Override
public String user() {
return kinds + "\t" + name + "\t" + penny + "元/天\t載貨:" + zh + "噸";
}
}
/**
* 載客車
*/
public class ZaiKeCar extends Car {
public ZaiKeCar(String name, int penny, int zr, int zh) {
super.name = name;
super.penny = penny;
if (zh != 0) {
super.zh = 0;
}
if (zr <= 0) {
System.out.println("輸入的載人數(shù)有誤!");
} else if (zr >0 && zr < 10) {
super.kinds = "小客車";
super.zr = zr;
} else {
super.kinds = "大客車";
super.zr = zr;
}
}
@Override
public String user() {
return kinds + "\t" + name + "\t" + penny + "元/天\t載人:" + zr + "人";
}
}
/**
* 皮卡車
*/
public class PiKaCar extends Car {
public PiKaCar(String name, int penny, int zr, int zh) {
super.name = name;
super.penny = penny;
super.kinds = "皮卡";
if (zr <= 0 || zr > 5) {
System.out.println("輸入的載人數(shù)有誤!");
} else {
super.zr = zr;
if (zh > 0 && zh < 5) {
super.zh = zh;
} else {
System.out.println("輸入的載貨量有誤!");
}
}
}
@Override
public String user() {
return kinds + "\t" + name + "\t" + penny + "元/天\t載人:" + zr + "人 載貨:" + zh + "噸";
}
}
}