小白新手求助。试着写了练习,输出也成功了,但是总觉得有问题,请帮忙指正
父类
package ddzc.imooc; public abstract class Car { int num; String name; int jg; int zz; int zr; public int getNum() { return num; } public void setNum(int num) { this.num = num; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getJg() { return jg; } public void setJg(int jg) { this.jg = jg; } public int getZz() { return zz; } public void setZz(int zz) { this.zz = zz; } public int getZr() { return zr; } public void setZr(int zr) { this.zr = zr; } abstract void kan(); }
子类
package ddzc.imooc; //小货车 public class Xh extends Car { int num=1; String name="小货车"; int jg=400; int zz=5; @Override void kan() { // TODO Auto-generated method stub this.setNum(num); this.setName(name); this.setJg(jg); this.setZz(zz); System.out.println(getNum()+"\t"+getName()+"\t"+getJg()+"元/天\t"+"\t载重:"+getZz()+"吨"); } }
package ddzc.imooc; //大货车 public class Dh extends Car { int num=2; String name="大货车"; int jg=1000; int zz=20; @Override void kan() { // TODO Auto-generated method stub this.setNum(num); this.setName(name); this.setJg(jg); this.setZz(zz); System.out.println(getNum()+"\t"+getName()+"\t"+getJg()+"元/天"+"\t载重:"+getZz()+"吨"); } }
package ddzc.imooc; //皮卡 public class Pk extends Car { int num=3; String name="皮卡"; int jg=500; int zz=5; int zr=4; @Override void kan() { // TODO Auto-generated method stub this.setNum(num); this.setName(name); this.setJg(jg); this.setZz(zz); this.setZr(zr); System.out.println(getNum()+"\t"+getName()+"\t"+getJg()+"元/天\t"+"\t载客:"+getZr()+"人"+"\t载重:"+getZz()+"吨"); } }
package ddzc.imooc; //小客车 public class Xk extends Car { int num=4; String name="小客车"; int jg=400; int zr=5; @Override void kan() { // TODO Auto-generated method stub this.setNum(num); this.setName(name); this.setJg(jg); this.setZr(zr); System.out.println(getNum()+"\t"+getName()+"\t"+getJg()+"元/天\t"+"\t载客:"+getZr()+"人"); } }
package ddzc.imooc; //大客车 public class Dk extends Car { int num=5; String name="大客车"; int jg=800; int zr=20; @Override void kan() { // TODO Auto-generated method stub this.setNum(num); this.setName(name); this.setJg(jg); this.setZr(zr); System.out.println(getNum()+"\t"+getName()+"\t"+getJg()+"元/天\t"+"\t载客:"+getZr()+"人"); } }
main
package ddzc.imooc; import java.util.Scanner; public class Imain { public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("*****欢迎来到租车系统*****"); Scanner input=new Scanner(System.in);//输入调用 System.out.print("想要进入租车系统请按:1;退出请按:0:"); int a=input.nextInt(); if(a==1){ System.out.println("*****欢迎进入租车系统*****"); System.out.println("现在可选择的车型有:"); System.out.println("序号\t车型\t价格\t\t容量"); Car xh=new Xh(); xh.kan(); Car dh=new Dh(); dh.kan(); Car pk=new Pk(); pk.kan(); Car xk=new Xk(); xk.kan(); Car dk=new Dk(); dk.kan(); String[] cheXing={xh.name,dh.name,pk.name,xk.name,dk.name}; int[] jG={xh.jg,dh.jg,pk.jg,xk.jg,dk.jg}; int[] xiaoJi=new int[5]; System.out.print("请输入您需要租用几种的车型:"); int b=input.nextInt(); if(b>5||b<1){ System.out.print("您输入的车型错误请重新输入:"); int i=input.nextInt(); b=i; } for(int c=1;b>0&&b<6;b--){ System.out.print("请输入您需要租第"+c+"种车型:"); int chexing=input.nextInt(); for(;chexing>5||chexing<=0;){ System.out.print("您输入的车型错误请重新输入:"); int i=input.nextInt(); chexing=i; } System.out.print("请输入您需要租的天数:"); int tianshu=input.nextInt(); System.out.print("请输入您需要租车的数量:"); int shuliang=input.nextInt(); System.out.println("你要租的第"+c+"种车型为:"+cheXing[chexing-1]+"\t租车的天数为"+tianshu+"天\t租车的数量为"+shuliang+"辆"); xiaoJi[c-1]=jG[chexing-1]*shuliang*tianshu; System.out.println("您租车第"+c+"种车需要的租金为:"+xiaoJi[c-1]); c++; } int zongji=0; for(int d=0;d>=0&&d<5;d++){ zongji=zongji+xiaoJi[d]; } System.out.println("您租车需要的总租金为:"+zongji); }else System.out.println("再见"); }
尤其是总租金的地方。。
ps:~~就不要吐曹命名了。。。。高中开始就英语没及过格的人。现在连代码都记不住。还在一边翻小笔记一边写。。
请帮忙多指正。