最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊

Java oop:租車系統(tǒng)詳細(xì)解析和顏色分層,幫你更易看懂結(jié)構(gòu)

2020-02-21 11:46 作者:詩書畫唱  | 我要投稿

package b;


import java.util.Scanner;


public class Text {


public static void main(String[] args) {


che xiaohuoche = new huoche(1, "小貨車", 30, 0, 3);


che dahuoche = new huoche(2, "大貨車", 50, 0, 5);


che xiaokeche = new keche(3, "小客車", 40, 4, 0);


che dakeche = new keche(4, "大客車", 80, 10, 0);


che xiaopika = new pika(5, "小皮車", 60, 2, 4);


che dapika = new pika(6, "大皮車", 100, 4, 8);


che[] c = new che[6];


c[0] = xiaohuoche;

c[1] = dahuoche;

c[2] = xiaokeche;


c[3] = dakeche;

c[4] = xiaopika;

c[5] = dapika;


yonghu yh = new yonghu();


che[] c_zuche = null;


while (true) {


System.out.println("---------神舟租車系統(tǒng)-----------");


System.out.println("請輸入你的操作:1.登錄? 2.注冊? 3.跳出系統(tǒng)");


Scanner s = new Scanner(System.in);


int num = s.nextInt();


if (num == 1) {


System.out.println("----執(zhí)行登錄操作----");


System.out.println("請輸入用戶名:");


String uname = s.next();


System.out.println("請輸入你的密碼");


String pwd = s.next();


if (uname.equals(yh.uname) && pwd.equals(yh.pwd)) {


System.out.println("登錄成功!");


break;


} else {


System.out.println("登錄失敗");


}


} else if (num == 2) {


System.out.println("----執(zhí)行注冊操作----");


System.out.println("請輸入用戶名:");


String uname = s.next();


System.out.println("請輸入你的密碼");


String pwd = s.next();


System.out.println("請輸入你的姓名");


String name = s.next();


yh.uname = uname;


yh.pwd = pwd;


yh.name = name;


System.out.println("注冊成功!");


} else if (num == 3) {


System.exit(0);


}


}


// 租車操作


while (true) {


System.out.println("歡迎," + yh.name + "請選擇你的操作:");


System.out

.println("1.查看車輛列表? 2.進(jìn)行租車? 3.查看我的租車總價(jià)格,總載人量,總載物量 4.跳出系統(tǒng)");


Scanner s1 = new Scanner(System.in);


int num = s1.nextInt();


if (num == 1) {


for (che i : c) {/* 相當(dāng)于for(int i=0;i<c.length;i++) */


i.jieshao();


}


} else if (num == 2) {


System.out.println("請輸入你要租的車輛數(shù)");


int num1 = s1.nextInt();


c_zuche = new che[num1];


for (int i = 0; i < num1; i++) {


System.out.println("請輸入第" + (i + 1) + "車輛的編號");


int bianhao = s1.nextInt();


switch (bianhao) {


case 1:


c_zuche[i] = xiaohuoche;

break;


case 2:


c_zuche[i] = dahuoche;

break;


case 3:


c_zuche[i] = xiaokeche;

break;


case 4:


c_zuche[i] = dakeche;

break;


case 5:


c_zuche[i] = xiaopika;

break;


case 6:


c_zuche[i] = dapika;

break;


}


}


System.out.println("租車成功!");


} else if (num == 3) {


if (c_zuche == null) {


System.out.println("你還沒有進(jìn)行租車呢!");


} else {


int zongjiage = 0;


int zongzairenliang = 0;


int zongzaiwuliang = 0;


for (che i : c_zuche) {


i.jieshao();


zongjiage += i.jiage;


zongzairenliang += i.zaikeliang;


zongzaiwuliang += i.zaiwuliang;


}


System.out.println("總價(jià)格" + zongjiage + "總載人量" +


zongzairenliang + "總載物量" + zongzaiwuliang);


}


} else {


System.exit(0);/* 終止系統(tǒng),不可為break,break是跳出循環(huán) */


}


}


}


}


class yonghu {


String uname;


String pwd;


String name;


}


abstract class che {


int bianhao;


String name;


int jiage;


int zaikeliang;


int zaiwuliang;


public che(int bianhao, String name, int jiage, int zaikeliang,int zaiwuliang) {


this.bianhao = bianhao;


this.name = name;


this.jiage = jiage;


this.zaikeliang = zaikeliang;


this.zaiwuliang = zaiwuliang;


}


abstract void jieshao();


}


class huoche extends che {


public huoche(int bianhao, String name, int jiage,


int zaikeliang, int zaiwuliang) {


super(bianhao, name, jiage, zaikeliang, zaiwuliang);


}


void jieshao() {


System.out.println("編號" + this.bianhao + "\t名稱" + this.name +


"\t價(jià)格" + this.jiage + "\t載物量" + this.zaiwuliang);


}


}


class keche extends che {


public keche(int bianhao, String name, int jiage, int zaikeliang,


int zaiwuliang) {


super(bianhao, name, jiage, zaikeliang, zaiwuliang);


}


void jieshao() {


System.out.println("編號" + this.bianhao + "\t名稱" +


this.name + "\t價(jià)格" + this.jiage + "\t載人量" + this.zaikeliang);


}


}


class pika extends che {


public pika(int bianhao, String name, int jiage, int zaikeliang,


int zaiwuliang) {


super(bianhao, name, jiage, zaikeliang, zaiwuliang);


}


void jieshao() {


System.out.println("編號" + this.bianhao + "\t名稱" +


this.name + "\t價(jià)格" + this.jiage + "\t載人量" + this.zaikeliang + "載物量" +


this.zaiwuliang);


}


}



Java oop:租車系統(tǒng)詳細(xì)解析和顏色分層,幫你更易看懂結(jié)構(gòu)的評論 (共 條)

分享到微博請遵守國家法律
潮州市| 哈密市| 华池县| 镇雄县| 巴马| 杨浦区| 西和县| 固原市| 平凉市| 郓城县| 股票| 北宁市| 资中县| 耒阳市| 保山市| 湄潭县| 皋兰县| 郯城县| 临沂市| 延边| 通城县| 建阳市| 丽江市| 苍南县| 治多县| 古浪县| 海南省| 内乡县| 桦南县| 上思县| 朝阳区| 皮山县| 本溪市| 冀州市| 新建县| 阳新县| 巧家县| 区。| 和田市| 大同县| 班戈县|