1.
package com.it.bean;
/**
* 定义属性
* @author qgx
*
*/
public class DIDIinfo {
private int id; //车俩编号
private String name; //车俩名称
private int price;//车俩价格
private int weight; //载重量
private int quantity; //载人数
/**
* 无参构造
*/
public DIDIinfo() {
super();
// TODO Auto-generated constructor stub
}
/**
* 有参构造
* @param id
* @param name
* @param price
* @param weight
* @param quantity
*/
public DIDIinfo(int id, String name, int price, int weight, int quantity) {
super();
this.id = id;
this.name = name;
this.price = price;
this.weight = weight;
this.quantity = quantity;
}
/**
* 输入获取
* @return
*/
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public int getWeight() {
return weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
}
2.
package com.it.data;
import com.it.bean.DIDIinfo;
/**
* 开辟内存空间
* @author qgx
*
*/
public class DIdata {
public static DIDIinfo []di=new DIDIinfo[10];
/**
* 静态初始化
*/
static{
DIDIinfo d1=new DIDIinfo(1, "雪佛兰 ", 2000 , 0, 4);
DIDIinfo d2=new DIDIinfo(2, "皮卡 ", 1000 , 2, 2);
DIDIinfo d3=new DIDIinfo(3, "五菱宏光 ", 1500 , 0, 6);
DIDIinfo d4=new DIDIinfo(4, "奔驰 ", 2000 , 1, 4);
DIDIinfo d5=new DIDIinfo(5, "货车 ", 2500 , 6, 0);
DIDIinfo d6=new DIDIinfo(6, "比亚迪 ", 2000 , 0, 4);
di[0]=d1;
di[1]=d2;
di[2]=d3;
di[3]=d4;
di[4]=d5;
di[5]=d6;
}
}
3.
package com.it.service;
import java.util.Scanner;
import com.it.bean.DIDIinfo;
import com.it.data.DIdata;
public class DIservice {
/**
* 通过序号找到车俩信息
* @param id
* @return
*/
public DIDIinfo Id(int id){
DIDIinfo []did= DIdata.di;
DIdata da=new DIdata();
for (int i = 0; i < did.length; i++){
if(did[i].getId()==id){
return did[i];
}
}return null;
}
}
4.
package com.it.test;
import java.util.Scanner;
import com.it.bean.DIDIinfo;
import com.it.data.DIdata;
import com.it.service.DIservice;
/**
* 测试
* @author qgx
*
*/
public class Test {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("欢迎进入我的租车系统,我将全程为您服务");
System.out.println("请确认是否进入租车系统:是 输入1 , 否输入2:");
int a=sc.nextInt();
if(a==1){
System.out.println("以下是您可以选择的车俩类型:");
DIDIinfo []did= DIdata.di;
DIservice sv=new DIservice();
System.out.println("编号"+"\t"+"车俩名称"+"\t"+"价格(元/天)"+"\t"+"载物"+"\t"+"载人");
for (int i = 0; i < did.length&&did[i]!=null; i++) {
System.out.println(did[i].getId()+"\t"+did[i].getName()
+"\t"+did[i].getPrice()+"\t"+did[i].getWeight()+"\t"+did[i].getQuantity());
}
System.out.println("请输入你想租借的车俩个数:");
int b=sc.nextInt();
int j=1;
int sum=0;
String name=null;
int weight=0;
int quantity=0;
while(j<=b){
System.out.println("请输入你想租借的第"+j+"辆车序号:");
int c=sc.nextInt();
if(c==sv.Id(c).getId()){
sum=sum+sv.Id(c).getPrice();
if(name==null){
name=sv.Id(c).getName();
}else{
name=name+sv.Id(c).getName();
}
weight=weight+sv.Id(c).getWeight();
quantity=quantity+sv.Id(c).getQuantity();
}
j++;
}
System.out.println("您选择的车俩名称为:"+name);
System.out.println("您选择的车俩载重为:"+weight+"t");
System.out.println("您选择的车俩载人为:"+quantity+"人");
System.out.println("您选择的车俩的总价格为:"+sum+"元/天");
}
}
}
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦