索鸟网

  1. 首页
  2. JAVA第二季 哒哒租车网

JAVA第二季 哒哒租车网


----------------------------------------car.java-----------------------------------------------
package com.car;

public class Card {
private Integer people;
private Integer dunwei;
private Integer qian;
private String carname;

public Card(Integer people,Integer dunwei,Integer qian,String carname)
{
    this.setPeople(people);
    this.setDunwei(dunwei);
    this.qian=qian;
    this.carname=carname;
}

public Integer getPeople() {
    return people;
}

public void setPeople(Integer people) {
    this.people = people;
}

public Integer getDunwei() {
    return dunwei;
}

public void setDunwei(Integer dunwei) {
    this.dunwei = dunwei;
}

public Integer getQian() {
    return qian;
}

public void setQian(Integer qian) {
    this.qian = qian;
}

public String getCarname() {
    return carname;
}

public void setCarname(String carname) {
    this.carname = carname;
}

}

------------------------------------------Test.java--------------------------------------------
package com.car;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Test {
int[] arr=new int[50];
int sumPeople=0;
int sumDunwei=0;
int sumQian=0;
List<Card> shuzu = new ArrayList<>();
public int scanner()
{
Scanner scanner = new Scanner(System.in);
int sCanner = scanner.nextInt();
return sCanner;
}
public int caidan()
{
System.out.println("有如下这些车:");
System.out.println("序号 汽车名称 租金 容量");
Card AoDi = new Card(4,0,500,"奥迪A4");
Card MaZiDa = new Card(4,0,400,"马自达6");
Card PiKaXue = new Card(4,2,450,"皮卡雪");
Card JingNong = new Card(20,0,800,"金龙");
Card SongHuaJiang = new Card(0,4,400,"松花江");
Card YWK = new Card(0,20,1000,"以为课");

    shuzu.add(AoDi);shuzu.add(MaZiDa);shuzu.add(PiKaXue);shuzu.add(JingNong);shuzu.add(SongHuaJiang);shuzu.add(YWK);
    for(int i=0;i<6;i++)
    {
        System.out.println((i+1)+".     "+shuzu.get(i).getCarname()+"      "+shuzu.get(i).getQian()+"元      "+shuzu.get(i).getPeople()+"人      "+shuzu.get(i).getDunwei()+"吨");
    }
    System.out.println("输入你要租车的辆数:");
    Test Carnum = new Test();
    int carnum = Carnum.scanner();
    return carnum;
}
public int xuanche(int i)
{
    for(int j=1;j<=i;j++)
    {
        do {
            System.out.println("你要的第"+j+"辆车的序号是:");
            arr[j]=scanner();
        }while(arr[j]>6);
    }
    return i;
}
public void zairen(int i)
{
    for(int j=1;j<=i;j++)
    {
        if(arr[j]!=5&&arr[j]!=6)
        {
            System.out.print(shuzu.get(j-1).getCarname()+"  ");
            sumPeople+=shuzu.get(j-1).getPeople();
            sumDunwei+=shuzu.get(j-1).getDunwei();
            sumQian+=shuzu.get(j-1).getQian();
        }
    }
    System.out.println("共载人:"+sumPeople);
}
public void zaihuo(int i)
{
    for(int j=1;j<=i;j++)
    {
        if(arr[j]==3)
            System.out.print(shuzu.get(j-1).getCarname()+"  ");
        if(arr[j]==5||arr[j]==6)
        {
            System.out.print(shuzu.get(j-1).getCarname()+"  ");
            sumPeople+=shuzu.get(j-1).getPeople();
            sumDunwei+=shuzu.get(j-1).getDunwei();
            sumQian+=shuzu.get(j-1).getQian();
        }
    }
    System.out.println("共载货:"+sumDunwei);
}

public static void main(String[] args) {
    Test CaiDan = new Test();
    System.out.println("欢迎使用你爸爸的租车系统:\n你到底租不租?:1租 0不租");
    int p=CaiDan.scanner();
    if(p==0)
    {
        System.out.println("滚滚滚滚滚滚滚滚");
    }
    else
    {
        int f=CaiDan.xuanche(CaiDan.caidan());
        System.out.println("输入祖车天数:");
        int TianSu=CaiDan.scanner();
        System.out.println("你的账单:\n****可以坐人的车:");
        CaiDan.zairen(f);
        System.out.println("****可以放货的车:");
        CaiDan.zaihuo(f);
        System.out.println("****合计"+CaiDan.sumQian*TianSu+"元");
    }
}

}
-------------------------------------运行结果-------------------------------------------
欢迎使用你爸爸的租车系统:
你到底租不租?:1租 0不租
1
有如下这些车:
序号 汽车名称 租金 容量

  1. 奥迪A4 500元/天 载人:4
  2. 马自达6 400元/天 载人:4
  3. 皮卡雪 450元/天 载人:4 载货2
  4. 金龙 800元/天 载人:20
  5. 松花江 400元/天 载货:4
  6. 以为课 1000元/天 载货:20
    输入你要租车的辆数:
    4
    你要的第1辆车的序号是:
    1
    你要的第2辆车的序号是:
    2
    你要的第3辆车的序号是:
    3
    你要的第4辆车的序号是:
    4
    输入祖车天数:
    3
    你的账单:
    可以坐人的车:
    奥迪A4 马自达6 皮卡雪 金龙 共载人:32
    可以放货的车:
    皮卡雪 共载货:2
    ****合计6450元
相关标签: JAVA

来源地址:http://www.imooc.com/article/19231 版权归作者所有!

相关教程

  • java第二季____哒哒租车系统

    Car类 public class Car { private int passenger_num; private int goods_num; private String name; private int price; public int getPassenger_num() { return passe
  • java基础第二季,哒哒租车系统

    测试类(main) package com.imooc.rentcar; import java.util.Scanner; public class test01 { public static void main(String[] args) { // TODO Auto-generated method stub Sc
  • JAVA入门第二季-哒哒租车系统

    总的所有车的父类 public class car { protected String name; protected int money; public String getname(){ return name; } public int getmoney(){ return money
  • java学习第二季哒哒租车系统

    根据自己的理解写的,还不完善,错误的地方还请不吝赐教,谢谢! cars父类: public abstract class Car { public double getPrice() { return price; } public void setPrice(double price) { this.pric
  • 哒哒租车系统——java第二季大作业

    新建一个car类 package com.axhu; public class Car { String name; int money; int personnum; int burden; } Burdencar类 package com.axhu; public class Burdencar extends Car { pub
  • Java入门第二季综合练习--哒哒租车系统

    Main.java package practiceFinal02; import java.util.Scanner; public class Main { private static int totalPassengers = 0; private static int totalShipment = 0; private stat
  • 第二季项目实战哒哒租车系统

    package didi; //父类 public abstract class Didi { public abstract void show(int no,String name,int price,int person,int weight); } package didi; //载货车类 public class CurrentCar extends Didi
  • 哒哒租车系统(Java入门第二季最后作业)

    父类:定义车 package com.imooc; public class Car { private String name;//车的名字 private int carNum;//车的编号 private int price;//车的价格 private int carrying;//载货量 priva