第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

花了好長時間才做出來,求大神指教有什么不對的或者可以優(yōu)化的地方

一開始看到不止的題目沒有頭緒,參照了前輩們的答案才做出來,修修改改了好久總算達成了跟課程老師的題目差不多的要求,和自己加的一些交互代碼。

幫小弟提下意見或者建議 謝謝啦

package?com.imooc;
/*車?父類*/
public?class?Car?{?
	protected??String?carName;?//車名
	protected??int?money;?//價格
	protected??int?seatNum;?//座位數(shù)
	protected??double?weigthNum;?//載貨量?直接用了double類型
	private??double?toMoney=0;?//總價格
	private??int?toSeat=0;?//總座位
	private??int?toWeigth=0;?//總載重
	private?int?day=1;?//租車天數(shù)
	
	public?Car(String?newCarName,int?newMoney,int?newSeatNum,double?NewWeigthNum)?{
????????????this.carName=newCarName;
	??this.money=newMoney;		
	??this.seatNum=newSeatNum;		
	??this.weigthNum=NewWeigthNum;
	?}
	?
	public?Car()?{
	}
	
	public?String?getCarName()?{
	????return?carName;
	}
	
	public?int?getMoney()?{
	????return?money;
	}
	
	public?int?getSeatNum()?{
	????return?seatNum;
	}
	
	public?double?getWeigthNum()?{
	????return?weigthNum;
	}
	
	public?double?getToMoney()?{
	????return?toMoney;	
	}
	
	public?int?getToSeat()?{
	????return?toSeat;	
	}
	
	public?int?getToWeigth()?{
	????return?toWeigth;
	}
	
	public?int?getDay()?{
	????return?day;	
	}
	
	public?void?show()?{
		if(weigthNum<=0)?{
			System.out.println("\t"+carName+"\t"+money+"元/天\t載人:"+seatNum+"人");
		}		
		else?if(seatNum<=0)?{
			System.out.println("\t"+carName+"\t"+money+"元/天\t載貨:"+weigthNum+"噸");
		}else?{			
		System.out.println("\t"+carName+"\t"+money+"元/天\t載人:"+seatNum+"人?載貨:"+weigthNum+"噸");		
		}	
	}	
}
package?com.imooc;
/*客車?子類*/
public?class?PassCar?extends?Car?{
	public?PassCar(String?newCarName,int?newMoney,int?newSeatNum){
????????????super.carName=newCarName;
????????????super.money=newMoney;
????????????super.seatNum=newSeatNum;
????????}
}
package?com.imooc;
/*皮卡車?子類*/
public?class?PickupCar?extends?Car?{
????public?PickupCar(String?newCarName,int?newMoney,int?newSeatNum,double?weigthNum){
????????super.carName=newCarName;		
????????super.money=newMoney;		
????????super.seatNum=newSeatNum;		
????????super.weigthNum=weigthNum;	
????????}	
}
package?com.imooc;
/*貨車?子類*/
public?class?TruckCar?extends?Car?{		
????public?TruckCar(String?newCarName,int?newMoney,double?weigthNum){		
????????super.carName=newCarName;		
????????super.money=newMoney;		
????????super.weigthNum=weigthNum;	
????????}
}?	


  1. package com.imooc;

  2. import java.util.*;

  3. /*運行類*/

  4. public class Initail {

  5. public static void main(String[] args) {

  6. Scanner input = new Scanner(System.in);

  7. System.out.println("***歡迎使用答答租車系統(tǒng)***");

  8. System.out.println("您是否要租車?輸入數(shù)字\t1是,2否"); //判斷是否要租車

  9. Car carVa=new Car();

  10. int toSeat=carVa.getToSeat(); //定義車總座位數(shù)

  11. double toWeigth=carVa.getWeigthNum(); //定義值車總載重數(shù)

  12. double toMoney=carVa.getMoney(); //定義總價格?

  13. int day=carVa.getDay();

  14. int carType=0; //定義選擇的車序號

  15. int maxC=999; //定義最大租車數(shù)量


  16. for(int tf=3;tf>=0;tf--) {?

  17. int confirmInt=input.nextInt(); //輸入數(shù)字判斷是否要租車


  18. if(confirmInt==1) {

  19. tf=-1; //結(jié)束外層租車需求循環(huán)判斷 18行


  20. Car car[]={

  21. new PassCar("奧迪A4",500,4),

  22. new PassCar("馬自達6",400,4),

  23. new PassCar("金龍",800,20),

  24. new PickupCar("皮卡雪6",450,4,2),

  25. new TruckCar("松花江",400,4),

  26. new TruckCar("依維柯",1000,20),

  27. };


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

  29. for(int c=0,d=1;c<car.length;c++,d++) { //顯示租車列表

  30. System.out.print(d+".");

  31. car[c].show();

  32. }


  33. int carNum=3; //定義租車數(shù)量

  34. System.out.println("請輸入您要租車的數(shù)量");

  35. for(int tfNum=3;tfNum>=0;tfNum--) { //循環(huán)最大租車數(shù)量

  36. carNum=input.nextInt();?

  37. String carN[]=new String[carNum]; //定義數(shù)組,保存選擇后的車輛-車名

  38. int carS[]=new int[carNum]; //定義數(shù)組,保存選擇后的車輛-座位數(shù)

  39. double carW[]=new double[carNum]; //定義數(shù)組,保存選擇后的車輛-載重數(shù)

  40. List<String> listS = new ArrayList<String>();?

  41. List<String> listW = new ArrayList<String>();?

  42. if(carNum>0&&carNum<=maxC) { //判斷租車數(shù)量.小于max=999, 進入選車循環(huán)

  43. tfNum=-1;


  44. for(int i=1,tfNo=3;i<=carNum;) {

  45. System.out.println("請輸入第"+i+"輛車的序號,輸入"+"[ 0 ]"+"直接進入下一步租車天數(shù)界面");

  46. carType=input.nextInt(); //選擇車序號

  47. if(carType<=car.length&&carType>0) { //如果輸入的車序號小于車輛數(shù)據(jù)總長度

  48. tfNo=3;

  49. toMoney=toMoney+car[carType-1].getMoney(); //計算總價格?

  50. toSeat=toSeat+car[carType-1].getSeatNum(); //計算總座位/載人數(shù)

  51. toWeigth=toWeigth+car[carType-1].getWeigthNum(); //計算總載重數(shù)

  52. carS[i-1]=car[carType-1].getSeatNum(); //保存我們選擇的車座位數(shù)為數(shù)組

  53. carW[i-1]=car[carType-1].getWeigthNum();//保存我們選擇的車載重為數(shù)組

  54. carN[i-1]=car[carType-1].getCarName(); //保存我們選擇的車名為數(shù)組

  55. i++;

  56. if(i<carNum) {

  57. //顯示租車列表

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

  59. for(int c=0,d=1;c<car.length;c++,d++) {?

  60. System.out.print(d+".");

  61. car[c].show();

  62. }

  63. }

  64. }

  65. else {

  66. if(tfNo>0&&carType!=0) {

  67. //顯示租車列表

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

  69. for(int c=0,d=1;c<car.length;c++,d++) {?

  70. System.out.print(d+".");

  71. car[c].show();

  72. }

  73. System.out.println();

  74. System.out.println("輸入錯誤!此序號的車輛不存在,還可輸入"+tfNo+"次。");

  75. tfNo--;

  76. }

  77. else if(tfNo<=0) {

  78. System.out.println("輸入的租車數(shù)量,錯誤次數(shù)已達3次,退出租車界面");

  79. break;

  80. }

  81. }

  82. //判斷車輛完選擇之后

  83. if(i>carNum||carType==0) {?


  84. System.out.println("請輸入租車天數(shù):");

  85. day=input.nextInt();

  86. if(day>0) { //判斷租車天數(shù)

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

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

  89. for(int s=0;s<carN.length;s++) {

  90. if(!listS.contains(carN[s])) { //判斷重復(fù)值

  91. if(carS[s]>0) { //判斷座位數(shù)大于0

  92. listS.add(carN[s]); //加到list

  93. }

  94. }

  95. }

  96. System.out.print(listS); //輸出去重復(fù)值后的車

  97. if(toSeat<=0) { //判斷有沒有選擇客車

  98. System.out.println("無");

  99. }else {

  100. System.out.println("\t總載人:"+toSeat+"人");

  101. }

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

  103. for(int w=0;w<carN.length;w++) {

  104. if(!listW.contains(carN[w])) { //判斷重復(fù)值

  105. if(carW[w]>0) { //判斷座位數(shù)大于0

  106. listW.add(carN[w]); //加到list

  107. }

  108. }

  109. }

  110. System.out.print(listW); //輸出 去重復(fù)值 后的車

  111. if(toWeigth<=0) { //判斷有沒有選擇貨車

  112. System.out.println("無");

  113. }else {

  114. System.out.println("\t總載貨:"+toWeigth+"噸");

  115. }

  116. System.out.println("租車總價格:"+toMoney*day+"元");

  117. }else {

  118. int tfDay=3;

  119. System.out.println("租車天數(shù)錯誤,請重新輸入:");

  120. while(tfDay>=0) {

  121. day=input.nextInt();

  122. tfDay--;

  123. }

  124. if(tfDay<=0) {

  125. System.out.println("輸入租車天數(shù)錯誤次數(shù)已達最大值,默認給您選擇租車天數(shù)為1天");

  126. day=1;

  127. }

  128. }

  129. if(carType==0) {

  130. break;

  131. }

  132. }

  133. }

  134. }

  135. else{

  136. if(tfNum>0) {

  137. System.out.println("輸入錯誤!租車數(shù)量需要在1-"+maxC+"之間,還可輸入"+tfNum+"次。");

  138. System.out.println("請重新輸入租車數(shù)量:");

  139. }

  140. else if(tfNum<=0) {

  141. System.out.println("輸入的租車數(shù)量,錯誤次數(shù)已達3次,退出租車界面");

  142. break;

  143. }

  144. }

  145. }

  146. }

  147. else if(confirmInt==2) {

  148. System.out.println("您選擇了否,感謝使用!");

  149. break;

  150. }

  151. else if(confirmInt!=1||confirmInt!=2){

  152. if(tf>0) {

  153. System.out.println("輸入錯誤!還可輸入"+tf+"次。");

  154. System.out.println("輸入數(shù)字選擇您是否要租車? 1是,2否");

  155. }

  156. else if(tf<=0) {

  157. System.out.println("輸入需求錯誤次數(shù)已到達3次,退出租車界面。");

  158. }

  159. }

  160. }

  161. }


  162. }

正在回答

4 回答

歡迎參考我的學(xué)習(xí)筆記,包括第一季到第三季全部代碼~

https://www.jianshu.com/p/43f45dd0b22f

2 回復(fù) 有任何疑惑可以回復(fù)我~

真長長

0 回復(fù) 有任何疑惑可以回復(fù)我~

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;//輸入異常時退出用

boolean isprint1= false,

isprint2= false,

isprint3_1= false,

isprint3_2 = false,

isprint4= false,

isprint5= false,

isprint6= false;

Scanner strRent = new Scanner(System.in); //第1次輸入,是否租車

if(strRent.hasNext()){? ?

String Rent = strRent.nextLine();

if(Rent.equals("1")){

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

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

? ? ? ? System.out.println("1.? ?奧迪A4? ? ? ?500元/天? ?載人:4人");//載人 1-4人,2-4人,3-4人,4-20人

? ? ? ? System.out.println("2.? ?馬自達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("請輸入您要租汽車的數(shù)量:");? ? ? ? ? ? ? ?

? ? ? ? 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("請輸入第"+j+"輛車的序號:");

? ? ? ? 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("請輸入租車天數(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:

? ? ? ? if(isprint1 == false){

? ? ? ? System.out.print("奧迪A4" + " ");

? ? ? ? isprint1 = true;

? ? ? ? break;

? ? ? ? }

? ? ? ? case 2:

? ? ? ? if(isprint2 == false){

? ? ? ? System.out.print("馬自達6" + " ");

? ? ? ? isprint2 = true;

? ? ? ? break;

? ? ? ? }

? ? ? ?

? ? ? ? case 3:

? ? ? ? if(isprint3_1 == false){

? ? ? ? System.out.print("皮卡雪6" + " ");

? ? ? ? isprint3_1 = true;

? ? ? ? break;

? ? ? ? }? ? ? ?

? ? ? ? case 4:

? ? ? ? if(isprint4 == false){

? ? ? ? System.out.print("金龍" + " ");

? ? ? ? isprint4 = true;

? ? ? ? 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:

? ? ? ? if(isprint3_2 == false){

? ? ? ? System.out.print("皮卡雪6" + " ");

? ? ? ? isprint3_2 = true;

? ? ? ? break;

? ? ? ? }? ? ? ? ? ? ? ?

? ? ? ? case 5:

? ? ? ? if(isprint5 == false){

? ? ? ? System.out.print("松花江" + " ");

? ? ? ? isprint5 = true;

? ? ? ? break;

? ? ? ? }? ? ? ?

? ? ? ? case 6:

? ? ? ? if(isprint6 == false){

? ? ? ? System.out.print("依維河" + " ");

? ? ? ? isprint6 = true;

? ? ? ? break;

? ? ? ? }? ? ? ?

? ? ? ? default:break;

? ? ? ? }

? ? ? ? }

? ? ? ? ? }? ? ? ?

? ? ? ? ? ?}

? ? ? ? }

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

? ? ? ? System.out.println("**租車總價格:" + cost +"元");

? ? ? ? System.out.println("賬單計算結(jié)束.感謝您的光臨,祝您生活愉快!");

? ? ? ? }

? ? ? ? }

? ? ? ? }

? ? ? ? }

}else if(Rent.equals("0"))

? {

System.out.println("ByeBye!");

? }else{

? System.out.println("非法輸入!再見!");

? }? ? ? ?

}

}

}


我來粘個非對象程序的

1 回復(fù) 有任何疑惑可以回復(fù)我~

哇,真長

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消

花了好長時間才做出來,求大神指教有什么不對的或者可以優(yōu)化的地方

我要回答 關(guān)注問題
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號