收费java代码 java收费了

java难题 , 急,求代码?接口和类全在一个包下收费java代码,如果不在一个包下记得import调用收费java代码,show的重写你根据需要自己改
//ShouFei 接口
public interface ShouFei {
public void fuFei(double mileage);
public void show();
}
//Bus类
public class Bus implements ShouFei{
String airConditioning;
double money;
public Bus(String airConditioning){
this.airConditioning = airConditioning;
}
@Override
public void fuFei(double mileage) {
if(airConditioning.equals("空调")){
money = 2;
}else{
money = 1;
}
}
@Override
public void show() {
System.out.println("公交车,"+airConditioning+",费用:"+money);
}
}
//Taxi类
public class Taxi implements ShouFei{
double mileage;
boolean isDay;
double money;
public Taxi(boolean isDay){
this.isDay = isDay;
}
@Override
public void fuFei(double mileage) {
this.mileage = mileage;
//判断是否为白天
if(isDay){
//判断里程数是否大于三公里
if(mileage3){
money=8;
}else{
money = 8 + (mileage-3)*1.5;
}
}else{
if(mileage3){
money=10;
}else{
money = 10 + (mileage-3)*1.5;
}
}
}
@Override
public void show() {
System.out.print("出租车,");
if(isDay){
System.out.print("白天");
}else{
System.out.print("晚上");
}
System.out.println(",里程数:"+mileage+"收费:"+money);
}
}
//测试类
public class Test {
public static void main(String[] args) {
Bus bus = new Bus("空调");
bus.fuFei(10);
bus.show();
Taxi taxi = new Taxi(true);
taxi.fuFei(20);
taxi.show();
}
}
java 编程,停车收费简易系统代码如下,仅实现功能,未考虑安全等情况.
//ParkingTest.java
/**
* 停车程序入口.本示例为考虑数据安全等.仅作为示例,未经调试.
* @author menglg
*
*/
public class ParkingTest {
public static void main(String[] args) {
// 程序入口,可以安排停车出车
for (int i = 0; i100; i++) {
if (ParkingManage.hasPosition()) {
ParkingManage.enterParking(i + "");
continue;
}
break;
}
for (int i = 0; i100; i++) {
ParkingManage.outParking(i + "");
}
System.out.println(ParkingManage.totalCost());
}
}
//ParkingManage.java
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class ParkingManage {
private static ListParking parkings = new ArrayList();
private static final int maxNumber = 100;
private static int currentNumber;
public static void enterParking(String lpn) {
if (lpn == null || lpn.length() == 0) {
return;
}
Parking p = new Parking(lpn);
p.setEnterDate(new Date());
parkings.add(p);
}
public static void outParking(String lpn) {
if (lpn == null || lpn.length() == 0) {
return;
}
for (Parking p : parkings) {
if (!lpn.equals(p.getLpn()))
continue;
Date now = new Date();
p.setOutDate(now);
parkings.remove(p);
currentNumber += p.getCost();
break;
}
}
public static int totalCost() {
return currentNumber;
}
public static boolean hasPosition() {
return parkings.size()maxNumber;
}
}
//Parking.java
import java.util.Date;
public class Parking {
private String lpn;
private Date enterDate;
private Date outDate;
private int cost;
public Parking(String lpn) {
this.lpn = lpn;

推荐阅读