課程
/后端開發(fā)
/Java
/Java入門第二季 升級(jí)版
老師,能親自寫一下出來嗎?
2020-04-20
源自:Java入門第二季 升級(jí)版 12-2
正在回答
package java22;
import java.util.*;
import java.util.Scanner;?
public class RentCar {
public static void main(String[] args) {
System.out.println("歡迎使用答答租車系統(tǒng):");
System.out.println("您是否要租車:1是 0否");
boolean withDraw2 = true,withDraw3 = true,withDraw4 = true;
Scanner strRent = new Scanner(System.in); //第1次輸入,是否租車
if(strRent.hasNext()){? ?
String Rent = strRent.nextLine();
//System.out.println(Rent);
if(Rent.equals("1")){
? ? ? ? System.out.println("您可租車的類型及其價(jià)目表:");
? ? ? ? System.out.println("序號(hào)? ? 汽車名稱? ? ? ? 租金? ? ? ? ?容量");
? ? ? ? System.out.println("1.? ?奧迪A4? ? ? ?500元/天? ?載人:4人");//載人 1-4人,2-4人,3-4人,4-20人
? ? ? ? System.out.println("2.? ?馬自達(dá)6 ? 400元/天? ?載人:4人");//載貨 3-2噸,5-4噸,6-20噸
? ? ? ? System.out.println("3.? ?皮卡雪6? ? ? 450元/天? ? 載人:4 載貨:2噸");
? ? ? ? System.out.println("4.? ?金龍 ? 800元/天? ?載人:20人");
? ? ? ? System.out.println("5.? ?松花江? ? ? ? ? ? 400元/天? ?載貨:4噸");
? ? ? ? System.out.println("6.? ?依維柯? ? ? ? ? ? 1000元/天 載貨:20噸");
? ? ? ? System.out.println("請(qǐng)輸入您要租汽車的數(shù)量:");
// System.out.println("您可租車的類型及其價(jià)目表:");
//? ? ? ? System.out.println("序號(hào)\t汽車名稱\t租金\t容量");
//? ? ? ? System.out.println("1.奧迪A4\t500元/天\t載人:4人");//載人 1-4人,2-4人,3-4人,4-20人
//? ? ? ? System.out.println("2.馬自達(dá)6\t400元/天\t載人:4人");//載貨 3-2噸,5-4噸,6-20噸
//? ? ? ? System.out.println("3.皮卡雪6\t450元/天\t載人:4 載貨:2噸");
//? ? ? ? System.out.println("4.金龍\t800元/天\t載人:20人");
//? ? ? ? System.out.println("5.松花江\t400元/天\t載貨:4噸");
//? ? ? ? System.out.println("6.依維柯\t1000元/天\t載貨:20噸");
//? ? ? ? System.out.println("請(qǐng)輸入您要租汽車的數(shù)量:");
? ? ? ? Rent = null;? ? ? ?
? ? ? ? Scanner strRentNumber = new Scanner(System.in); //第2次輸入,租幾輛
? ? ? ? if(strRentNumber.hasNext()){
? ? ? ? String RentNumber = strRentNumber.nextLine();
? ? ? ? for (int i = 0; i < RentNumber.length(); i++){
? ? ? ? if(withDraw2 == true){
? ? ? ? if (!Character.isDigit(RentNumber.charAt(i))){
? ? ? ? System.out.println("非法輸入!");
? ? ? ? withDraw2 = false;
? ? ? ? break;
? ? ? ? }
? ? ? ? }else{break;}
? ? ? ? int rentNumber = Integer.parseInt(RentNumber);? ? ? ?
? ? ? ? int[] rentCar = new int[rentNumber + 1];
? ? ? ? for(int i = 0; i<rentNumber+1;i++){
? ? ? ? rentCar[i] = 0;
? ? ? ? int j = 1,i = 1;
? ? ? ? while(j <= rentNumber){
? ? ? ? if(withDraw3 == true){
? ? ? ? System.out.println("請(qǐng)輸入第"+j+"輛車的序號(hào):");
? ? ? ? Scanner strCarType = new Scanner(System.in);//第3次輸入,租哪輛車
? ? ? ? if(strCarType.hasNext()){
? ? ? ? String CarType = strCarType.nextLine();
? ? ? ? for (i = 0; i < CarType.length(); i++){? ? ? ?
? ? ? ? ? ? ? ? if (!Character.isDigit(CarType.charAt(i))){
? ? ? ? ? ? ? ? System.out.println("非法輸入!");
? ? ? ? ? ? ? ? withDraw3 = false;
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ?if(withDraw3 == true){
? ? ? ? int carType = Integer.parseInt(CarType);
? ? ? ? rentCar[j] = carType;
? ? ? ? if(rentCar[j] < 1 || rentCar[j] > 6)
? ? ? ? ? ? {?
? ? ? ? System.out.println( "沒有" + rentCar[j] + "型車。");
? ? ? ? System.out.println("再見!");
? ? ? ? withDraw3 = false;
? ? ? ? ? ? ? ?}
? ? ? ?
? ? ? ? j++;
? ? ? ? double cost = 0.0,load = 0.0;
? ? ? ? int manned = 0;
? ? ? ? for(i = 1; i <= rentNumber;i++){
? ? ? ? if(rentCar[i] > 0){
? ? ? ? switch (rentCar[i]){
? ? ? ? case 0:break;
? ? ? ? case 1:cost += 500;manned += 4;break;
? ? ? ? case 2:cost += 400;manned += 4;break;
? ? ? ? case 3:cost += 450;manned += 4;load += 2;break;
? ? ? ? case 4:cost += 800;manned += 20;break;
? ? ? ? case 5:cost += 400;load += 4;break;
? ? ? ? case 6:cost += 1000;load += 20;break;
? ? ? ? default:break;
? ? ? ? ? ?}
? ? ? ? System.out.println("請(qǐng)輸入租車天數(shù):");//第4次輸入,租車天數(shù)
? ? ? ? Scanner strDays = new Scanner(System.in);?
? ? ? ? if(strDays.hasNext()){
? ? ? ? String RentDays = strDays.nextLine();
? ? ? ? for ( i = 0; i < RentDays.length(); i++){? ? ? ?
? ? ? ? ? ? if (!Character.isDigit(RentDays.charAt(i))){
? ? ? ? ? ? System.out.println("非法輸入!");
? ? ? ? ? ? withDraw4 = false;
? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? if(withDraw4 == true){
? ? ? ? int rentDays = Integer.parseInt(RentDays);?
? ? ? ? cost *= rentDays;
? ? ? ? System.out.println("您的賬單:");
? ? ? ? System.out.println("**可載人的車有:");
? ? ? ? if(manned == 0){
? ? ? ? System.out.println("無");
? ? ? ? else{
? ? ? ? ? for(i = 1;i <= rentNumber;i++){
? ? ? ? if (rentCar[i] == 1||rentCar[i] == 2||rentCar[i] == 3||rentCar[i] == 4){
? ? ? ? switch(rentCar[i]){
? ? ? ? case 1:System.out.print("奧迪A4" + " ");break;
? ? ? ? case 2:System.out.print("馬自達(dá)6" + " ");break;
? ? ? ? case 3:System.out.print("皮卡雪6" + " ");break;
? ? ? ? case 4:System.out.print("金龍" + " ");break;? ? ? ?
? ? ? ? }? ? ? ?
? ? ? ? System.out.println("共載人:" + manned);
? ? ? ? System.out.println("**載貨的車有:");
? ? ? ? if(load == 0){
? ? ? ? if (rentCar[i] == 3||rentCar[i] == 5||rentCar[i] == 6){
? ? ? ? case 3:System.out.print("皮卡雪6" + " ");break;? ? ? ?
? ? ? ? case 5:System.out.print("松花江" + " ");break;
? ? ? ? case 6:System.out.print("依維河" + " ");break;
? ? ? ? ? }? ? ? ?
? ? ? ? System.out.println("共載貨:" + load + "噸");
? ? ? ? System.out.println("**租車總價(jià)格:" + cost +"元");
? ? ? ? System.out.println("賬單計(jì)算結(jié)束.感謝您的光臨,祝您生活愉快!");
}else if(Rent.equals("0"))
? {
System.out.println("ByeBye!");
? }else{
? System.out.println("非法輸入!再見!");
? }? ? ? ?
}
面向?qū)ο蟮拇a被我寫成面向過程的,我對(duì)我也是...有點(diǎn)醉
雖然我覺得大家應(yīng)該自己動(dòng)手解決思考。但是老師也要寫一遍出來讓我們參考講解一下把。就像是把這個(gè)問題 實(shí)例化解決一下看看. 按照上一節(jié)的項(xiàng)目思考方式 一步一步的構(gòu)建編寫出完整的代碼,幫助同學(xué)們養(yǎng)成良好的編寫習(xí)慣與思維方式。? ?我還是參考同學(xué)的代碼 了解到自己之前學(xué)的不扎實(shí)。例如 有參的構(gòu)造方法,循環(huán),判斷等 但是多數(shù)同學(xué)都只是把代碼寫出來,沒注釋,沒思路圖。這樣看起來很費(fèi)勁. 我是零基礎(chǔ).課程也是針對(duì)零基礎(chǔ)。希望理解。
太多了,視頻里面寫出來費(fèi)時(shí)間
舉報(bào)
課程升級(jí)!以終為始告別枯燥,在開發(fā)和重構(gòu)中體會(huì)Java面向?qū)ο缶幊痰膴W妙
2 回答租車系統(tǒng)問題
1 回答答答租車系統(tǒng)
2 回答答答租車系統(tǒng)
3 回答租車系統(tǒng)代碼
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2020-07-11
package java22;
import java.util.*;
import java.util.Scanner;?
public class RentCar {
public static void main(String[] args) {
System.out.println("歡迎使用答答租車系統(tǒng):");
System.out.println("您是否要租車:1是 0否");
boolean withDraw2 = true,withDraw3 = true,withDraw4 = true;
Scanner strRent = new Scanner(System.in); //第1次輸入,是否租車
if(strRent.hasNext()){? ?
String Rent = strRent.nextLine();
//System.out.println(Rent);
if(Rent.equals("1")){
? ? ? ? System.out.println("您可租車的類型及其價(jià)目表:");
? ? ? ? System.out.println("序號(hào)? ? 汽車名稱? ? ? ? 租金? ? ? ? ?容量");
? ? ? ? System.out.println("1.? ?奧迪A4? ? ? ?500元/天? ?載人:4人");//載人 1-4人,2-4人,3-4人,4-20人
? ? ? ? System.out.println("2.? ?馬自達(dá)6 ? 400元/天? ?載人:4人");//載貨 3-2噸,5-4噸,6-20噸
? ? ? ? System.out.println("3.? ?皮卡雪6? ? ? 450元/天? ? 載人:4 載貨:2噸");
? ? ? ? System.out.println("4.? ?金龍 ? 800元/天? ?載人:20人");
? ? ? ? System.out.println("5.? ?松花江? ? ? ? ? ? 400元/天? ?載貨:4噸");
? ? ? ? System.out.println("6.? ?依維柯? ? ? ? ? ? 1000元/天 載貨:20噸");
? ? ? ? System.out.println("請(qǐng)輸入您要租汽車的數(shù)量:");
// System.out.println("您可租車的類型及其價(jià)目表:");
//? ? ? ? System.out.println("序號(hào)\t汽車名稱\t租金\t容量");
//? ? ? ? System.out.println("1.奧迪A4\t500元/天\t載人:4人");//載人 1-4人,2-4人,3-4人,4-20人
//? ? ? ? System.out.println("2.馬自達(dá)6\t400元/天\t載人:4人");//載貨 3-2噸,5-4噸,6-20噸
//? ? ? ? System.out.println("3.皮卡雪6\t450元/天\t載人:4 載貨:2噸");
//? ? ? ? System.out.println("4.金龍\t800元/天\t載人:20人");
//? ? ? ? System.out.println("5.松花江\t400元/天\t載貨:4噸");
//? ? ? ? System.out.println("6.依維柯\t1000元/天\t載貨:20噸");
//? ? ? ? System.out.println("請(qǐng)輸入您要租汽車的數(shù)量:");
? ? ? ? Rent = null;? ? ? ?
? ? ? ? Scanner strRentNumber = new Scanner(System.in); //第2次輸入,租幾輛
? ? ? ? if(strRentNumber.hasNext()){
? ? ? ? String RentNumber = strRentNumber.nextLine();
? ? ? ? for (int i = 0; i < RentNumber.length(); i++){
? ? ? ? if(withDraw2 == true){
? ? ? ? if (!Character.isDigit(RentNumber.charAt(i))){
? ? ? ? System.out.println("非法輸入!");
? ? ? ? withDraw2 = false;
? ? ? ? break;
? ? ? ? }
? ? ? ? }else{break;}
? ? ? ? }
? ? ? ? if(withDraw2 == true){
? ? ? ? int rentNumber = Integer.parseInt(RentNumber);? ? ? ?
? ? ? ? int[] rentCar = new int[rentNumber + 1];
? ? ? ? for(int i = 0; i<rentNumber+1;i++){
? ? ? ? rentCar[i] = 0;
? ? ? ? }
? ? ? ? int j = 1,i = 1;
? ? ? ? while(j <= rentNumber){
? ? ? ? if(withDraw3 == true){
? ? ? ? System.out.println("請(qǐng)輸入第"+j+"輛車的序號(hào):");
? ? ? ? Scanner strCarType = new Scanner(System.in);//第3次輸入,租哪輛車
? ? ? ? if(strCarType.hasNext()){
? ? ? ? String CarType = strCarType.nextLine();
? ? ? ? for (i = 0; i < CarType.length(); i++){? ? ? ?
? ? ? ? ? ? ? ? if (!Character.isDigit(CarType.charAt(i))){
? ? ? ? ? ? ? ? System.out.println("非法輸入!");
? ? ? ? ? ? ? ? withDraw3 = false;
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ?if(withDraw3 == true){
? ? ? ? int carType = Integer.parseInt(CarType);
? ? ? ? rentCar[j] = carType;
? ? ? ? if(rentCar[j] < 1 || rentCar[j] > 6)
? ? ? ? ? ? {?
? ? ? ? System.out.println("非法輸入!");
? ? ? ? System.out.println( "沒有" + rentCar[j] + "型車。");
? ? ? ? System.out.println("再見!");
? ? ? ? withDraw3 = false;
? ? ? ? }
? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ?}
? ? ? ?
? ? ? ? }else{break;}
? ? ? ? j++;
? ? ? ? }
? ? ? ? if(withDraw3 == true){
? ? ? ? double cost = 0.0,load = 0.0;
? ? ? ? int manned = 0;
? ? ? ? for(i = 1; i <= rentNumber;i++){
? ? ? ? if(rentCar[i] > 0){
? ? ? ? switch (rentCar[i]){
? ? ? ? case 0:break;
? ? ? ? case 1:cost += 500;manned += 4;break;
? ? ? ? case 2:cost += 400;manned += 4;break;
? ? ? ? case 3:cost += 450;manned += 4;load += 2;break;
? ? ? ? case 4:cost += 800;manned += 20;break;
? ? ? ? case 5:cost += 400;load += 4;break;
? ? ? ? case 6:cost += 1000;load += 20;break;
? ? ? ? default:break;
? ? ? ? }
? ? ? ? ? ?}
? ? ? ? }
? ? ? ? System.out.println("請(qǐng)輸入租車天數(shù):");//第4次輸入,租車天數(shù)
? ? ? ? Scanner strDays = new Scanner(System.in);?
? ? ? ? if(strDays.hasNext()){
? ? ? ? String RentDays = strDays.nextLine();
? ? ? ? for ( i = 0; i < RentDays.length(); i++){? ? ? ?
? ? ? ? ? ? if (!Character.isDigit(RentDays.charAt(i))){
? ? ? ? ? ? System.out.println("非法輸入!");
? ? ? ? ? ? withDraw4 = false;
? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? if(withDraw4 == true){
? ? ? ? int rentDays = Integer.parseInt(RentDays);?
? ? ? ? cost *= rentDays;
? ? ? ? }
? ? ? ? }
? ? ? ? if(withDraw4 == true){
? ? ? ? System.out.println("您的賬單:");
? ? ? ? System.out.println("**可載人的車有:");
? ? ? ? if(manned == 0){
? ? ? ? System.out.println("無");
? ? ? ? }
? ? ? ? else{
? ? ? ? ? for(i = 1;i <= rentNumber;i++){
? ? ? ? if(rentCar[i] > 0){
? ? ? ? if (rentCar[i] == 1||rentCar[i] == 2||rentCar[i] == 3||rentCar[i] == 4){
? ? ? ? switch(rentCar[i]){
? ? ? ? case 1:System.out.print("奧迪A4" + " ");break;
? ? ? ? case 2:System.out.print("馬自達(dá)6" + " ");break;
? ? ? ? case 3:System.out.print("皮卡雪6" + " ");break;
? ? ? ? case 4:System.out.print("金龍" + " ");break;? ? ? ?
? ? ? ? default:break;
? ? ? ? }
? ? ? ? }
? ? ? ? }? ? ? ?
? ? ? ? }
? ? ? ? }
? ? ? ? System.out.println("共載人:" + manned);
? ? ? ? System.out.println("**載貨的車有:");
? ? ? ? if(load == 0){
? ? ? ? System.out.println("無");
? ? ? ? }
? ? ? ? else{
? ? ? ? ? for(i = 1;i <= rentNumber;i++){
? ? ? ? if(rentCar[i] > 0){
? ? ? ? if (rentCar[i] == 3||rentCar[i] == 5||rentCar[i] == 6){
? ? ? ? switch(rentCar[i]){
? ? ? ? case 3:System.out.print("皮卡雪6" + " ");break;? ? ? ?
? ? ? ? case 5:System.out.print("松花江" + " ");break;
? ? ? ? case 6:System.out.print("依維河" + " ");break;
? ? ? ? default:break;
? ? ? ? }
? ? ? ? }
? ? ? ? ? }? ? ? ?
? ? ? ? ? ?}
? ? ? ? }
? ? ? ? System.out.println("共載貨:" + load + "噸");
? ? ? ? System.out.println("**租車總價(jià)格:" + cost +"元");
? ? ? ? System.out.println("賬單計(jì)算結(jié)束.感謝您的光臨,祝您生活愉快!");
? ? ? ? }
? ? ? ? }
? ? ? ? }
? ? ? ? }
}else if(Rent.equals("0"))
? {
System.out.println("ByeBye!");
? }else{
? System.out.println("非法輸入!再見!");
? }? ? ? ?
}
}
}
面向?qū)ο蟮拇a被我寫成面向過程的,我對(duì)我也是...有點(diǎn)醉
2020-06-07
雖然我覺得大家應(yīng)該自己動(dòng)手解決思考。但是老師也要寫一遍出來讓我們參考講解一下把。就像是把這個(gè)問題 實(shí)例化解決一下看看. 按照上一節(jié)的項(xiàng)目思考方式 一步一步的構(gòu)建編寫出完整的代碼,幫助同學(xué)們養(yǎng)成良好的編寫習(xí)慣與思維方式。? ?我還是參考同學(xué)的代碼 了解到自己之前學(xué)的不扎實(shí)。例如 有參的構(gòu)造方法,循環(huán),判斷等 但是多數(shù)同學(xué)都只是把代碼寫出來,沒注釋,沒思路圖。這樣看起來很費(fèi)勁. 我是零基礎(chǔ).課程也是針對(duì)零基礎(chǔ)。希望理解。
2020-05-05
太多了,視頻里面寫出來費(fèi)時(shí)間