继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

Java入门第二季6.1问题编码

芒果蛋糕
关注TA
已关注
手记 1
粉丝 0
获赞 3

以下是新手式代码写法,请勿参考。
新人刚开始接触JAVA希望能得到求各种达人的建议和意见。QAQ

![图片描述][1]//创建文字类
![图片描述][2]//填写文字类方法
![图片描述][3]//创建车的父类
![图片描述][4]//创建子类继承父的各种参数


输入代码
```import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.*; //导入输入源
public class test {
    int sum = 0;
    int age = 0;
    double avg = 0d
    int X = 0;
    int Y = 0;
    String A;
    String B = "";
    String C = "";
    String D = "";
    double Z = 0d;        ;//定义全局变量保存输出值

    public static void main(String args[]) throws Exception {

        test mi2 = new test();
        //把字符流添加到缓冲流
        BufferedReader x = new BufferedReader(new InputStreamReader(System.in));
        User mi = new Method();

//进入系统
        mi.system();
        String X = x.readLine();
        String x1 = "1";

        if (X.equals(x1)) {//如果不确认进入则退出
            mi.select();//显示价目表
        } else {
            mi.end();
            System.exit(0);//结束程序
        }
        mi.num();
        String Y = x.readLine();//输入租车数量

        int Y1 = Integer.parseInt(Y);//输入强转int类
        String num[] = new String[Y1];

        mi2.nums(num);

        mi.day();
        String D = x.readLine();//输入要租的天数
        int D1 = Integer.parseInt(D);
        int amount = 0;
        amount = mi2.sum * D1;

        mi.bill();
        mi.people();
        System.out.println(mi2.C + "  " + "载人量:" + mi2.age + "人");

        mi.cargo();
        System.out.println(mi2.D + "  " + "载货量:" + mi2.avg + "吨");
        mi.amount();
        System.out.println(amount + "元。");

    }

    public void nums(String num[]) throws Exception {
        BufferedReader x = new BufferedReader(new InputStreamReader(System.in));
        User mi = new Method();   //实例化各种车
        OneCar car1 = new OneCar();
        TwoCar car2 = new TwoCar();
        ThreeCar car3 = new ThreeCar();
        FourCar car4 = new FourCar();
        FiveCar car5 = new FiveCar();
        SixCar car6 = new SixCar();

        for (int i = 0; i < num.length; i++) {//每当租车数量+1的时候循环以下语句
            mi.style();
            A = x.readLine();//输入要租车的类型
            num[i] = A;
            if (A.equals("1")) {  //如果输入对应值就会调用该车的配置参数
                X = car1.num;
                Y = car1.people;
                B = car1.name;
                Z = car1.cargo;
            } else if (A.equals("2")) {
                X = car2.num;
                Y = car2.people;
                B = car2.name;
                Z = car2.cargo;
            } else if (A.equals("3")) {
                X = car3.num;
                Y = car3.people;
                B = car3.name;
                Z = car3.cargo;
            } else if (A.equals("4")) {
                X = car4.num;
                Y = car4.people;
                B = car4.name;
                Z = car4.cargo;
            } else if (A.equals("5")) {
                X = car5.num;
                Y = car5.people;
                B = car5.name;
                Z = car5.cargo;
            } else if (A.equals("6")) {
                X = car6.num;
                Y = car6.people;
                B = car6.name;
                Z = car6.cargo;
            }
            sum = sum + X;     //输出金钱总额,人头数,吨数,汽车名称

            age = age + Y;

            avg = avg + Z;
            if (Z == 0) {
                C = C + B + ",";
            } else {
                D = D + B + ",";
            }

        }
    }

}

  [1]: http://img.mukewang.com/5959c6c30001437b06530373.png
  [2]: http://img.mukewang.com/5959c6d40001559811630819.png
  [3]: http://img.mukewang.com/5959c71d0001291104700194.png
  [4]: http://img.mukewang.com/5959c7380001c37b07160238.png
打开App,阅读手记
2人推荐
发表评论
随时随地看视频慕课网APP

热门评论

老哥稳 我愣是没看懂 高手过招招招致命

你这里用到了流的概念,新手貌似还没有学到这里吧。。。

查看全部评论