Java第一个系统

做的是一个租车系统的模拟项目。

大致思路。

1.创建大类Car赋予属性,设置set/get方法;

2.创建子类详细car并通过set方法附值;

3.具体实现main类。

定义父类

public class Car { 
private String name;
 //名称
 private double price; 
//租金
 private int capacity;
 //容量 
private double weight; 
//载重
 public Car() { } 

public String getName() {
 return name; 
} 
public void setName(String name) { 
this.name = name;
 } 
public double getPrice() {
 return price;
 }
 public void setPrice(double price) {
 this.price = price; 
}
 public int getCapacity() {
 return capacity; 
} 
public void setCapacity(int capacity) {
 this.capacity = capacity; }
 public double getWeight() {
 return weight; 
} 
public void setWeight(double weight) {
 this.weight = weight; } 
}

 定义子类,如aodi

public class Aodi extends Car{
public Aodi(){
	this.setName("sdsadsadsa");
	this.setPrice(100);
	this.setWeight(60.0);
	this.setCan(5);
	
}
}

 用于输出的类:

import java.util.Scanner;
public class test1 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//创建Scanner对象
Car car1=new Aodi();
Car car2=new Mazida();
Car car3=new Qq();
Car car4=new Qirui();
Car car5=new Benchi();
System.out.println();
Scanner wy =new Scanner(System.in);
int enter =	wy.nextInt();
if(enter==1){
	System.out.println("欢迎下次再来");
	return;
}
System.out.println("=========您可租车的类型及其价目表========");
System.out.println("序号\t汽车名称\t\t租金\t\t载人\t\t载重");
System.out.println("1、\t"+car1.getName()+"\t\t"+car1.getPrice()+"\t\t"+car1.getCan()+"\t\t"+car1.getWeight());
System.out.println("2、\t"+car2.getName()+"\t\t"+car2.getPrice()+"\t\t"+car2.getCan()+"\t\t"+car2.getWeight());
System.out.println("3、\t"+car3.getName()+"\t\t"+car3.getPrice()+"\t\t"+car3.getCan()+"\t\t"+car3.getWeight());
System.out.println("4、\t"+car4.getName()+"\t\t"+car4.getPrice()+"\t\t"+car4.getCan()+"\t\t"+car4.getWeight());
System.out.println("5、\t"+car5.getName()+"\t\t"+car5.getPrice()+"\t\t"+car5.getCan()+"\t\t"+car5.getWeight());
System.out.println("========请输入您需要租车的车辆========");

int sumprice=0;
double sumweight=0;
double sumcan=0;
int num=wy.nextInt();
for(int i=1;i<=num;i++){
	System.out.println("请输入第"+i+"辆车的序号");
	int witch=wy.nextInt();
	switch(witch){
	case 1:
		sumprice +=car1.getPrice();
		sumweight +=car1.getWeight();
		sumcan +=car1.getCan();
		break;
	case 2:
		sumprice +=car2.getPrice();
		sumweight +=car2.getWeight();
		sumcan +=car2.getCan();
		break;
	case 3:
		sumprice +=car3.getPrice();
		sumweight +=car3.getWeight();
		sumcan +=car3.getCan();
		break;
	case 4:
		sumprice +=car4.getPrice();
		sumweight +=car4.getWeight();
		sumcan +=car4.getCan();
		break;
	case 5:
		sumprice +=car5.getPrice();
		sumweight +=car5.getWeight();
		sumcan +=car5.getCan();
		break;	
		
	}
}
System.out.println("========请输入需要租车的天数========");
int day=wy.nextInt();
sumprice*=day;
System.out.println("========您的账单=======");
System.out.println("总价格为;"+sumprice+"/t/t总载人:"+sumcan+"/t/t总载重:"+sumweight);
	}

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值