亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

第一次寫的代碼,請大家多多指教,非常感謝~~~

package com.dada;
//定義父類Car,定義車輛信息參數
public class Car {
?private String Num;
?private String chexing;
?private double price;
?private int Zaihuo;
?private int Zairen;
?
?
?public int getZaihuo() {
??return Zaihuo;
?}
?public void setZaihuo(int zaihuo) {
??Zaihuo = zaihuo;
?}
?public int getZairen() {
??return Zairen;
?}
?public void setZairen(int zairen) {
??Zairen = zairen;
?}
?public String getNum() {
??return Num;
?}
?public void setNum(String num) {
??Num = num;
?}
?public String getChexing() {
??return chexing;
?}
?public void setChexing(String chexing) {
??this.chexing = chexing;
?}
?public double getPrice() {
??return price;
?}
?public void setPrice(double price) {
??this.price = price;
?}
???
}


package com.dada;

public class Keche extends Car? {
?//集成父類Car,定義可出的參數病顯示車輛信息,將載貨量置為0
?public Keche(String Num,String chexing,double price,int Zairen) {
??// TODO Auto-generated constructor stub
??????? this.setNum(Num);
??????? this.setChexing(chexing);
??????? this.setPrice(price);
??????? this.setZairen(Zairen);
??????? this.setZaihuo(0);
??????? System.out.println(Num + " " + chexing + " " +price + "元/日 " + Zairen + "人");
?}


}

package com.dada;

public class Huoche extends Car {
?//集成父類Car,定義貨車的參數病顯示車輛信息,將載人數置為0
?public Huoche(String Num,String chexing,double price,int Zaihuo) {
??// TODO Auto-generated constructor stub
??this.setNum(Num);
??this.setChexing(chexing);
??this.setPrice(price);
??this.setZaihuo(Zaihuo);
??this.setZairen(0);
??????? System.out.println(Num + " " + chexing + " " +price + "元/日 " + Zaihuo + "噸");
?}


}

package com.dada;

public class Pika extends Car? {
?//集成父類Car,定義皮卡的參數病顯示車輛信息
?public Pika(String Num,String chexing,double price,int Zaihuo,int Zairen) {
??
??// TODO Auto-generated constructor stub
??this.setNum(Num);
??this.setChexing(chexing);
??this.setPrice(price);
??this.setZaihuo(Zaihuo);
??this.setZairen(Zairen);
??System.out.println(Num + " " + chexing + " " +price + "元/日 " + Zaihuo + "噸? " + Zairen + "人");
?}

???
}

package com.dada;

import java.util.Scanner;

public class Show {
?//定義全局變量delflag,在zuche()和total(int[][] message)函數中使用
?public int delflag = 0;
?//定義全局變量i
?public int i = 0;
?//定義全局變量ans2,用來存儲所需車輛數
?public int? ans2;
??? //顯示租車系統內容
?public void Show(){
??????? System.out.println("**************歡迎使用達達租車系統****************");
???? System.out.println("請問是否要租車? (1? 是,0? 否)");
???? Scanner scan1=new Scanner(System.in);
???? int ans1 = scan1.nextInt();
???? //定義變量ans1,判斷是否要租車,1位租車,0位不租車,其他會提示輸入有誤,重新輸入;
???? if(ans1 == 1){
???? ?//進入租車函數
???????? zuche();
???? }
???? else if(ans1 == 0){
???????? System.out.println("感謝您使用達達租車系統,歡迎您再次使用!");
??????? }
???? else{
???? ?System.out.println("輸入有誤,請您核實后重新輸入!");
???? ?Show();
???? }
?}

?//租車函數
?public void? zuche()
?{
??System.out.println("車輛信息如下:");
??????? System.out.println("序號? 車型 價格/天 容量");
??????? //顯示所有車輛信息
??????? new Keche("1","奧迪A4",500,4);
??????? new Keche("2","馬自達6 ",400,4);
??????? new Keche("3","金龍 ",800,20);
??????? new Pika("4","皮卡雪6",450,2,4);
??????? new Huoche("5","松花江",400,4);
??????? new Huoche("6","依維柯",1000,20);
???????
??????? System.out.println("請輸入需要的數量:");
???? Scanner scan2=new Scanner(System.in);
???? //用參數ans2存儲所需車輛數
???? ans2 = scan2.nextInt();
???? //定義一個車輛數為行,3列的二維數組存儲信息
???? int[][] message = new int[ans2][3];

??????? //進行循環
???? for(? ; i <ans2; i++)
???? {
???????? System.out.println("請輸入需要車的序號:");
????? Scanner no=new Scanner(System.in);
????? //定義變量num,存儲所需要的車的序號
????? int num = no.nextInt();
????? //將序號賦值給message數組的第i行,第一列
????? message[i][0] = num;
???????? System.out.println("請輸入該序號的車所需數量:");
????? Scanner ct=new Scanner(System.in);
????? //定義變量count,存儲所需要的序號的車的數量
????? int count = ct.nextInt();
???????? System.out.println("請輸入該序號的車所需天數:");
????? Scanner d=new Scanner(System.in);
????? //定義變量day,存儲所需要的序號的車的天數
????? int day = d.nextInt();
????? //將天數賦值給message數組的第i行,第二列
????? message[i][1] = day;
????? //根據車的序號判斷該車的金額,并賦值給message數組的第i行第3列
????? if(num==1)
????? {
????? ?message[i][2] = 500;
????? }
????? if(num==2 || num==5)
????? {
????? ?message[i][2] = 400;
????? }
????? if(num==3)
????? {
????? ?message[i][2] = 800;
????? }
????? if(num==4)
????? {
????? ?message[i][2] = 450;
????? }
????? if(num==6)
????? {
????? ?message[i][2] = 1000;
????? }
????? //當某輛車所需要的數量大于1,并且還有剩余車輛數據需要錄入時
????? while(count >1 && i != ans2)
????? {
????? ?//如果該序號所需車輛大于總車輛數-已有車輛數
????? ?if(count > ans2-i )
????? ?{

????? ??System.out.println("您輸入的該序號車的數量已經超過您所需車的數量,請核對信息后重親輸入。如果是總數量輸入錯誤,請按1,如果是該序號車數量輸入錯誤,請按2");
??????? Scanner m=new Scanner(System.in);
????? ??//定義棉量m1用來存儲是需要對所有車輛信息重新輸入還是該序號的車的車輛重新輸入
??????? int m1 = m.nextInt();
??????? //如果需要對所有租車信息重新輸入,則重新調用租車函數
??????? if(m1 == 1)
??????? {
????? ????? zuche();
??????? }

??????? else {
??????? ?System.out.println("請輸入該序號的車所需數量:");
???????? Scanner ct1=new Scanner(System.in);
???????? //重新錄入該序號的車的數量病復制給count
???????? count = ct1.nextInt();
??????????? System.out.println("請輸入該序號的車所需天數:");
???????? Scanner d1=new Scanner(System.in);
???????? //重新錄入該序號的車的天數病復制給day,病復制給message數組第i行第2列
???????? day = d1.nextInt();
???????? message[i][1] = day;
??????? }
????? ?}
????? ?//如果該序號車的數量是符合邏輯的
????? ?else{
????? ??//講該車數據循環復制給數組,并且將i的值增加
????? ??for(int j= 0;j<count-1;j++){
????? ???i++;
????? ???message[i][0] = num;
????? ???message[i][1] = day;
????? ???message[i][2] = message[i-1][2];
????? ??}
????? ?break;
????? ?}

????? }
?????
???? }
????
??????? if(delflag !=1){
??????? ?//計算并顯示賬單,把message數組信息作為參數傳遞
??? ???? total(message);
??????? }

?}
?//計算并顯示賬單
?public void total(int[][] message)
?{
??//定義sum變量,用來存儲總金額
???? int sum = 0;
???? //將所有的車的信息存在數組中
???? Car c[] = {new Keche("1","奧迪A4",500,4),new Keche("2","馬自達6 ",400,4),new Keche("3","金龍 ",800,20),
???? ??new Pika("4","皮卡雪6",450,2,4),new Huoche("5","松花江",400,4),new Huoche("6","依維柯",1000,20)};
???? System.out.println("您的賬單如下:");
???? System.out.println("序號 車型 價格/天 容量?? 天數??? 價格");
???? //循環輸出參數message數組中的車輛信息
???? for(int s=0 ; s<message.length;s++)
???? {
???? ?//定義變量str用來存儲傳遞的數組的行數-1
???? ?int str= message[s][0]-1;
???? ?//顯示車輛信息
???? ?System.out.println(c[str].getNum() + "? " + c[str].getChexing() + "? " + c[str].getPrice() + "? " + c[str].getZairen() + c[str].getZaihuo() + "? "? + "? " + message[s][1] + "? " + message[s][2]);
???? ?//計算總金額
???? ?sum += message[s][2]*message[s][1];
???? }
???? //輸出總金額
???? System.out.println("您的總價格為:" + sum + "元");
???? delflag=1;
?}

}

package com.dada;


public class ini {

?public static void main(String[] args) throws Exception {
??
??// TODO Auto-generated method stub
??Show s = new Show();
??try{
???s.Show();
??}
??catch(Exception e){
???System.out.println("連接數據庫異常:"+e.toString());
??}
??
??
??System.out.println("歡迎您再次使用達達租車系統");
?}
?

}

正在回答

4 回答

看起來不像是第一次寫吧,寫的很好啊,代碼也不是很亂,樓上說代碼繁瑣的代碼長的是自己菜吧。我大概看了下,思路很清晰,這倒不像是個剛剛會寫代碼的新手。

0 回復 有任何疑惑可以回復我~
#1

慕粉陽光小白 提問者

以前接觸過,但是確實沒有完整的寫過,都只是寫一寫實現具體功能的函數~~~謝謝評價,我還在學習中~~~
2016-06-13 回復 有任何疑惑可以回復我~

下邊看的頭暈了,,,好繁瑣

0 回復 有任何疑惑可以回復我~

看得頭暈


0 回復 有任何疑惑可以回復我~

你這代碼好長啊,怪不得沒人評論。

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

第一次寫的代碼,請大家多多指教,非常感謝~~~

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號