尝试创建一个项目,该项目使用用户输入和已知信息来确定每天的汽车租赁费用。我遇到的问题是 CarRental 类似乎没有从测试类获得输入。不知道如何解决它。
租车类
public class CarRental {
private String customerName;
private String ratingKey;
private double baseFactor;
private double basefactor;
private double fudge;
private double computeDailyFee;
public CarRental(String customerName, String ratingKey, double baseFactor, double fudge, double computeDailyFee) {
this.customerName = customerName;
this.ratingKey = ratingKey;
this.baseFactor = baseFactor;
this.basefactor = basefactor;
this.fudge = fudge;
this.computeDailyFee = computeDailyFee;
//intitialize
}
public String getcustomerName() {
return this.customerName;
}
public String getratingKey() {
return ratingKey;
}
public void setcustomerName(String newCustomerName) {
customerName = newCustomerName;
System.out.println(customerName);
}
public void setratingKey(String newRatingKey) {
ratingKey = newRatingKey;
System.out.println(ratingKey);
}
public double baseFactor() {
switch (ratingKey.charAt(0)) {
case 'S':
baseFactor = 1.0;
break;
case 'C':
baseFactor = 1.2;
break;
case 'U':
baseFactor = 1.4;
break;
case 'T':
baseFactor = 1.6;
break;
case 'B':
baseFactor = 2.0;
break;
default:
System.out.println("Invalid type");
break;
}
System.out.println(baseFactor);
return baseFactor;
}
public double fudge() {
switch (ratingKey.charAt(1)) {
case 'N':
fudge = 11.40;
break;
case 'V':
fudge = 0;
break;
default:
System.out.println("Invalid type");
break;
}
System.out.println(fudge);
return fudge;
}
public double computeDailyFee() {
computeDailyFee = (baseFactor() * (89.22 - fudge()));
System.out.println(computeDailyFee);
return computeDailyFee;
}
}
类出租测试
public class RentalTest {
public static void main(String[] args) {
CarRental rental = new CarRental("customerName", "ratingKey", 0.0, 0.0, 0.0);
String newCustomerName = rental.getcustomerName();
String newCustomerName = JOptionPane.showInputDialog("Enter your name");
//System.out.println(newCustomerName);
RentalTest rentaltest = new RentalTest();
JOptionPane.showMessageDialog(null, "Input code for model, then code for condition (No Spaces)");
String newRatingKey = JOptionPane.showInputDialog(
"Models: 'S' = Sub-compact 'C'=Car 'U'=SUV 'T'=Truck 'B'=Bigfoot\n"
+ "Condition: 'N'= New 'V' = Vintage");
newRatingKey = newRatingKey.toUpperCase();
//System.out.println(newRatingKey);
}
}