练习是有一个名为 Tenant 的类,用于存储公寓租户的值。在主类 Prog2 中,我试图创建一个 ArrayList,它可以保存 4 个不同的值,所有这些值都与租户类有关,它们是 - 租户的姓名、公寓号码、初始首付款和每月付款。我希望能够将这些值打印在单独的行中,这将为每个租户提供所有 4 条信息 - 然后是一个空白行,然后如果有另一个租户,则为另一个租户提供相同的 4 条信息。我可以让程序正确提示问题,但我得到的只是空值和 0 打印出来(见下面的评论)。我感谢所有的帮助——我在这方面不是最擅长的。
// this class is the tenant class that passes all the tenant's
information
public class Tenant {
private String firstName;
private String lastName;
private String aptNumber;
private double yearlyRent;
private String fullName;
private double firstPayment;
private double monthlyPayment;
public Tenant(String name, String aptNum, double fPayment, double
mPayment){
name = fullName;
aptNum = aptNumber;
fPayment = firstPayment;
mPayment= monthlyPayment;
}
public Tenant() {
}
public void setFirstName(String name) {
firstName = name;
}
public void setLastName(String lName) {
lastName= lName;
}
public void setAptNumber(String apt) {
aptNumber = apt;
}
public void setRent(double rent) {
yearlyRent = rent;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public String getAptNumber() {
return aptNumber;
}
public double getRent() {
return yearlyRent;
}
public double getFirstPayment() {
double monthlyRent = yearlyRent/12;
firstPayment = monthlyRent * 3;
return firstPayment;
}
public double getmonthlyPayment() {
double firstAndLast = yearlyRent/12;
monthlyPayment = (yearlyRent - firstAndLast)/11;
return monthlyPayment;
}
public String getFullName(){
fullName = firstName + " " + lastName;
return fullName;
}
}
// The below class contains the main method
public class Prog2 {
public static double getDouble(Scanner scan) {
System.out.println("Enter yearly rent:");
while (!scan.hasNextDouble()) {
scan.next();
System.out.println("Error: please enter a numeric
value");
}
return scan.nextDouble();
}
慕码人8056858
慕运维8079593
相关分类