作业代码,傻瓜版

来源:12-1 综合练习

qq_时光老佡_04298173

2016-12-01 16:49

学得时间太短了,就只会用一点简单方法,用了抽象的多态,if,for,switch,import 。感觉思路还是比较清楚。先父类 再子类最后是操作Initail.(先写了分开的 后面合起来的时候出了点问题 加了static 就好了(public class Jl extends Auto 改成public static class Jl extends Auto ))

package 综合作业合;

import java.util.*;

public abstract class Auto {

   public  String Name;

public float Price;

public int Nm;

public int Zkl;

public int Zhl;

public abstract void Run();

 //

public static class Ada4 extends Auto {

public String Name="奥迪A4";

public float Price=500;

public int Nm=1;

public int Zkl=4;

        public  void Run() {

           System.out.println(Nm+"     "+Name+"   "+Price+"元/天"+"  "+Zkl+"人");

}

         }

//

public static class Jl extends Auto {

public String Name="金龙";

public float Price=800;

public int Nm=4;

public int Zkl=20;

   public void Run() {

System.out.println(Nm+"     "+Name+"         "+Price+"元/天"+"  "+Zkl+"人");

        }

           }

   //

public static class Mzd6 extends Auto {

public String Name="马自达6";

public float Price=400;

public int Nm=2;

public int Zkl=4;

   public void Run() {

System.out.println(Nm+"     "+Name+"  "+Price+"元/天"+"  "+Zkl+"人");

}

       }

//

public static class Pkx extends Auto {

public String Name="皮卡雪6";

public float Price=450;

public int Nm=3;

public int Zkl=4;

public int Zhl=2;

public void Run() {

System.out.println(Nm+"     "+Name+"  "+Price+"元/天"+"   "+Zkl+"人"+Zhl+"吨");

}

}

//

public static class Shj extends Auto {

public String Name="松花江";

public float Price=400;

public int Nm=5;

public int Zhl=4;

public void Run() {

System.out.println(Nm+"     "+Name+"     "+Price+"元/天"+"   "+Zhl+"吨");

}

//

public static class Ywh extends Auto {

public String name="依维河";

public float price=1000;

public int Nm=6;

        public int Zhl=20;

public void Run() {

System.out.println(Nm+"     "+name+"     "+price+"元/天"+"  "+Zhl+"吨");

}


}


public static void main(String[] args) {

System.out.println("您是否租车?  1是 0否");

Scanner input = new Scanner(System.in);

  int r = input.nextInt();  

  if(r==1){

System.out.println("您可租车的类型及其价目表:");

System.out.println("序号"+"  "+"汽车名称"+"      "+"租金"+"         "+"容量");

Auto i1=new Ada4();

i1.Run();

Auto i2=new Mzd6();

i2.Run();

Auto i3=new Pkx();

i3.Run();

Auto i4=new Jl();

i4.Run();

Auto i5=new Shj();

i5.Run();

Auto i6=new Ywh();

i6.Run();

System.out.println("请输入您要租车的数量:");

Scanner input1 = new Scanner(System.in);

  int r1 = input1.nextInt(); 

  float  num=0;

  int a1=0,a2=0,a3=0,a4=0,a5=0,a6=0;

    for(int n=1;n<=r1;n++){

    System.out.println("请输入第"+n+"辆车的序号");

  Scanner input2 = new Scanner(System.in);

    int z = input2.nextInt(); 

    switch(z){

    case 1:

    num=num+500;

    a1++;

    break;

    case 2:

    num=num+400;

   a2++;

    break;

    case 3:

    num=num+450;

    a3++;

    break;

    case 4:

    num=num+800;

    a4++;

    break;

    case 5:

    num=num+400;

    a5++;

    break;

    case 6:

    num=num+1000;

    a6++;

    break;   

    }

         }

             System.out.println("请输入租车的天数:");

            Scanner input3 = new Scanner(System.in);

              int x = input3.nextInt(); 

     int sumpeople=a1*4+a2*4+a3*4+a4*20+a5*0+a6*0; 

     int sumzaihuo=a3*2+a5*4+a6*20;

     float sumzongjia=num*x;

              System.out.println("您的账单:");

              

              System.out.println("***可载人的车有:");

              if(a1>0){System.out.print("奥迪A4,");}

              if(a2>0){System.out.print("马自达6,");}

              if(a3>0){System.out.print("皮卡雪6,");}

              if(a4>0){System.out.print("金龙,");}

              System.out.println("共载人:"+sumpeople);

              System.out.println("***载货的车有:");

              if(a3>0){System.out.print("皮卡雪6,");}

              if(a5>0){System.out.print("松花江,");}

              if(a6>0){System.out.print("依维河,");}

              System.out.println("共载货:"+sumzaihuo);

              System.out.println("租车总价:"+sumzongjia);

}


}


}


写回答 关注

1回答

  • _Riser
    2016-12-01 19:58:52

    为什么要加static?新手同问。

    qq_时光老...

    我也不懂,求解。。

    2016-12-02 16:40:37

    共 2 条回复 >

Java入门第二季 升级版

课程升级!以终为始告别枯燥,在开发和重构中体会Java面向对象编程的奥妙

530654 学习 · 6091 问题

查看课程

相似问题