第一次寫的代碼,請(qǐng)大家多多指教,非常感謝~~~
package com.dada;
//定義父類Car,定義車輛信息參數(shù)
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,定義可出的參數(shù)病顯示車輛信息,將載貨量置為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,定義貨車的參數(shù)病顯示車輛信息,將載人數(shù)置為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,定義皮卡的參數(shù)病顯示車輛信息
?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)函數(shù)中使用
?public int delflag = 0;
?//定義全局變量i
?public int i = 0;
?//定義全局變量ans2,用來存儲(chǔ)所需車輛數(shù)
?public int? ans2;
??? //顯示租車系統(tǒng)內(nèi)容
?public void Show(){
??????? System.out.println("**************歡迎使用達(dá)達(dá)租車系統(tǒng)****************");
???? System.out.println("請(qǐng)問是否要租車? (1? 是,0? 否)");
???? Scanner scan1=new Scanner(System.in);
???? int ans1 = scan1.nextInt();
???? //定義變量ans1,判斷是否要租車,1位租車,0位不租車,其他會(huì)提示輸入有誤,重新輸入;
???? if(ans1 == 1){
???? ?//進(jìn)入租車函數(shù)
???????? zuche();
???? }
???? else if(ans1 == 0){
???????? System.out.println("感謝您使用達(dá)達(dá)租車系統(tǒng),歡迎您再次使用!");
??????? }
???? else{
???? ?System.out.println("輸入有誤,請(qǐng)您核實(shí)后重新輸入!");
???? ?Show();
???? }
?}
?//租車函數(shù)
?public void? zuche()
?{
??System.out.println("車輛信息如下:");
??????? System.out.println("序號(hào)? 車型 價(jià)格/天 容量");
??????? //顯示所有車輛信息
??????? new Keche("1","奧迪A4",500,4);
??????? new Keche("2","馬自達(dá)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("請(qǐng)輸入需要的數(shù)量:");
???? Scanner scan2=new Scanner(System.in);
???? //用參數(shù)ans2存儲(chǔ)所需車輛數(shù)
???? ans2 = scan2.nextInt();
???? //定義一個(gè)車輛數(shù)為行,3列的二維數(shù)組存儲(chǔ)信息
???? int[][] message = new int[ans2][3];
??????? //進(jìn)行循環(huán)
???? for(? ; i <ans2; i++)
???? {
???????? System.out.println("請(qǐng)輸入需要車的序號(hào):");
????? Scanner no=new Scanner(System.in);
????? //定義變量num,存儲(chǔ)所需要的車的序號(hào)
????? int num = no.nextInt();
????? //將序號(hào)賦值給message數(shù)組的第i行,第一列
????? message[i][0] = num;
???????? System.out.println("請(qǐng)輸入該序號(hào)的車所需數(shù)量:");
????? Scanner ct=new Scanner(System.in);
????? //定義變量count,存儲(chǔ)所需要的序號(hào)的車的數(shù)量
????? int count = ct.nextInt();
???????? System.out.println("請(qǐng)輸入該序號(hào)的車所需天數(shù):");
????? Scanner d=new Scanner(System.in);
????? //定義變量day,存儲(chǔ)所需要的序號(hào)的車的天數(shù)
????? int day = d.nextInt();
????? //將天數(shù)賦值給message數(shù)組的第i行,第二列
????? message[i][1] = day;
????? //根據(jù)車的序號(hào)判斷該車的金額,并賦值給message數(shù)組的第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;
????? }
????? //當(dāng)某輛車所需要的數(shù)量大于1,并且還有剩余車輛數(shù)據(jù)需要錄入時(shí)
????? while(count >1 && i != ans2)
????? {
????? ?//如果該序號(hào)所需車輛大于總車輛數(shù)-已有車輛數(shù)
????? ?if(count > ans2-i )
????? ?{
????? ??System.out.println("您輸入的該序號(hào)車的數(shù)量已經(jīng)超過您所需車的數(shù)量,請(qǐng)核對(duì)信息后重親輸入。如果是總數(shù)量輸入錯(cuò)誤,請(qǐng)按1,如果是該序號(hào)車數(shù)量輸入錯(cuò)誤,請(qǐng)按2");
??????? Scanner m=new Scanner(System.in);
????? ??//定義棉量m1用來存儲(chǔ)是需要對(duì)所有車輛信息重新輸入還是該序號(hào)的車的車輛重新輸入
??????? int m1 = m.nextInt();
??????? //如果需要對(duì)所有租車信息重新輸入,則重新調(diào)用租車函數(shù)
??????? if(m1 == 1)
??????? {
????? ????? zuche();
??????? }
??????? else {
??????? ?System.out.println("請(qǐng)輸入該序號(hào)的車所需數(shù)量:");
???????? Scanner ct1=new Scanner(System.in);
???????? //重新錄入該序號(hào)的車的數(shù)量病復(fù)制給count
???????? count = ct1.nextInt();
??????????? System.out.println("請(qǐng)輸入該序號(hào)的車所需天數(shù):");
???????? Scanner d1=new Scanner(System.in);
???????? //重新錄入該序號(hào)的車的天數(shù)病復(fù)制給day,病復(fù)制給message數(shù)組第i行第2列
???????? day = d1.nextInt();
???????? message[i][1] = day;
??????? }
????? ?}
????? ?//如果該序號(hào)車的數(shù)量是符合邏輯的
????? ?else{
????? ??//講該車數(shù)據(jù)循環(huán)復(fù)制給數(shù)組,并且將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){
??????? ?//計(jì)算并顯示賬單,把message數(shù)組信息作為參數(shù)傳遞
??? ???? total(message);
??????? }
?}
?//計(jì)算并顯示賬單
?public void total(int[][] message)
?{
??//定義sum變量,用來存儲(chǔ)總金額
???? int sum = 0;
???? //將所有的車的信息存在數(shù)組中
???? Car c[] = {new Keche("1","奧迪A4",500,4),new Keche("2","馬自達(dá)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("序號(hào) 車型 價(jià)格/天 容量?? 天數(shù)??? 價(jià)格");
???? //循環(huán)輸出參數(shù)message數(shù)組中的車輛信息
???? for(int s=0 ; s<message.length;s++)
???? {
???? ?//定義變量str用來存儲(chǔ)傳遞的數(shù)組的行數(shù)-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]);
???? ?//計(jì)算總金額
???? ?sum += message[s][2]*message[s][1];
???? }
???? //輸出總金額
???? System.out.println("您的總價(jià)格為:" + 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("連接數(shù)據(jù)庫(kù)異常:"+e.toString());
??}
??
??
??System.out.println("歡迎您再次使用達(dá)達(dá)租車系統(tǒng)");
?}
?
}
2016-06-13
看起來不像是第一次寫吧,寫的很好啊,代碼也不是很亂,樓上說代碼繁瑣的代碼長(zhǎng)的是自己菜吧。我大概看了下,思路很清晰,這倒不像是個(gè)剛剛會(huì)寫代碼的新手。
2016-06-07
下邊看的頭暈了,,,好繁瑣
2016-06-06
看得頭暈
2016-06-06
你這代碼好長(zhǎng)啊,怪不得沒人評(píng)論。