各位大佬,可以幫我看看是哪有問(wèn)題嗎,得到的值不對(duì)(代碼寫(xiě)的很爛,感覺(jué)要重學(xué)0
package 租車(chē)系統(tǒng);
import java.util.*;
public class rukou {
public static void main(String[] args) {
// TODO 自動(dòng)生成的方法存根
Ad AD=new Ad();
Mzd MZD=new Mzd();
Pkx PKX=new Pkx();
Jl JL=new Jl();
Shj SHJ=new Shj();
Ywk YWK=new Ywk();
Gz gz=new Gz();
Tj tj=new Tj();
int ad=0;
int mzd=0;
int pkx=0;
int jl=0;
int shj=0;
int ywk=0;
Scanner input=new Scanner(System.in);
System.out.println("歡迎使用答答租車(chē)系統(tǒng)");
System.out.println("您是否要租車(chē):1是 2否");
int xz=input.nextInt();
if(xz==1)
{
System.out.println("您可租車(chē)的類(lèi)型及其價(jià)目表:");
System.out.println("序號(hào)-----汽車(chē)名稱----租金------容量");
System.out.println("1------奧迪a4----500元/天----載人:4人");
System.out.println("2------馬自達(dá)6----400元/天----載人:4人");
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)輸入您要租汽車(chē)的數(shù)量:");
int sl=input.nextInt();
if(sl>=0)
{
for(int i=1;i<=sl;i++)
{
System.out.println("請(qǐng)輸入第"+i+"輛車(chē)的序號(hào):");
int xh=input.nextInt();
if(xh>=1&&xh<=6)
{
switch(xh) {
case 1:ad++;
case 2:mzd++;
case 3:pkx++;
case 4:jl++;
case 5:shj++;
case 6:ywk++;
break;
}
}else
{
System.out.println("輸入有誤,請(qǐng)重新輸入");
i--;
}
}
}else
System.out.println("輸入有誤,請(qǐng)重新輸入");
}else
{
System.out.println("感謝使用!");
}
System.out.println("請(qǐng)輸入租車(chē)天數(shù):");
int day=input.nextInt();
System.out.println("可載人的車(chē)有:");
tj.zr(ad, mzd, pkx, jl);
System.out.println("共載人:"+gz.gzr(ad, mzd, pkx, jl));
System.out.println("載貨的車(chē)有");
tj.zh(pkx, shj, ywk);
System.out.println("共載貨:"+gz.gzh(pkx, shj, ywk));
}
}
package 租車(chē)系統(tǒng);
public abstract class Car {
public int zr(){
int zr=0;
return zr;
}
public int zw() {
int zh=0;
return zh;
}
public int rmb() {
int rmb=0;
return rmb;
}
}
package 租車(chē)系統(tǒng);
public class Ad extends Car {
public int zr(){
int zr=4;
return zr;
}
public int rmb(){
int rmb=500;
return rmb;
}
}
package 租車(chē)系統(tǒng);
public class Mzd extends Car {
public int zr(){
int zr=4;
return zr;
}
public int rmb() {
int rmb=400;
return rmb;
}
}
package 租車(chē)系統(tǒng);
public class Pkx extends Car {
public int zr(){
int zr=4;
return zr;
}
public int zw() {
int zh=2;
return zh;
}
public int rmb() {
int rmb=450;
return rmb;
}
}
package 租車(chē)系統(tǒng);
public class Jl extends Car {
public int zr(){
int zr=20;
return zr;
}
public int rmb() {
int rmb=800;
return rmb;
}
}
package 租車(chē)系統(tǒng);
public class Shj extends Car {
public int zw() {
int zh=4;
return zh;
}
public int rmb() {
int rmb=400;
return rmb;
}
}
package 租車(chē)系統(tǒng);
public class Ywk extends Car {
public int zw() {
int zh=20;
return zh;
}
public int rmb() {
int rmb=1000;
return rmb;
}
}
package 租車(chē)系統(tǒng);
public class Gz{
public int gzr(int ad,int mzd,int pkx,int jl) {
int zrsum;
zrsum=ad*4+mzd*4+pkx*4+jl*20;
return zrsum;
}
public int gzh(int pkx,int shj,int ywk) {
int zhsum=pkx*2+shj*4+ywk*2;
return zhsum;
}
}
package 租車(chē)系統(tǒng);
public class Tj {
public void zr(int ad,int mzd,int pkx,int jl){
if(ad>0)
System.out.print("奧迪A4? ");
if(mzd>0)
System.out.print("馬自達(dá)6? ");
if(pkx>0)
System.out.print("皮卡雪? ");
if(jl>0)
System.out.print("金龍? ");
}
public void zh(int pkx,int shj,int ywk) {
if(pkx>0)
System.out.print("皮卡雪? ");
if(shj>0)
System.out.print("松花江? ");
if(ywk>0)
System.out.print("依維柯? ");
}
}
2019-08-06
包名的命名規(guī)范好像是小寫(xiě),還是盡量不要用漢語(yǔ)
2019-07-29
有個(gè)建議。最好變量名不要這么寫(xiě),根據(jù)功能用英語(yǔ)寫(xiě),這樣子別人要看懂你的代碼比較容易
2019-07-29
知道問(wèn)題了,少了幾個(gè)break?