import javax.swing.JOptionPane;
import java.util.Arrays;
/** This program will evaluate a bank customer
for a Home Loan Equaty
*/
public class HomeEquatyLoan
{
public static void main(String[] args)
{
String firstName,lastName, stringInput; // Customer forst and last name.
char usStatus ; //To hold 'y' or 'n;.
String usStatus1; // Citizenship status of the customer.
int ageCustomer, yearsWork; // Customer data records.
double annualSalaryMin = 35000;
double annualSalaryMax = 75000; // Customer salary.
double annualSalary;
// Get the customer information.
firstName = JOptionPane.showInputDialog("Enter first name");
lastName = JOptionPane.showInputDialog("Enter last name");
stringInput = JOptionPane.showInputDialog("Enter customer age: "); //Customer age.
ageCustomer = Integer.parseInt(stringInput);
stringInput = JOptionPane.showInputDialog("Enter customer years at work: "); //Customer years at work.
yearsWork = Integer.parseInt(stringInput);
stringInput = JOptionPane.showInputDialog("Enter customer annual salary: "); //Annual salary.
annualSalary = Double.parseDouble(stringInput);
usStatus1 = JOptionPane.showInputDialog("Enter the US Citizen Status");
usStatus = usStatus1.charAt(0);
while(annualSalary <= annualSalaryMin || annualSalary > annualSalaryMax)
{
stringInput = JOptionPane.showInputDialog("The annual salary does not fall into the range" +
"allowed by State law." + " Please enter the annual salary");
annualSalary = Double.parseDouble(stringInput);
}
while(yearsWork < 7)
{
stringInput = JOptionPane.showInputDialog("The customer years of work should be greater or" +
"equal that seven(7)." + " Please enter years at work");
yearsWork = Integer.parseInt(stringInput);
}
while((usStatus != 'y') || (usStatus != 'Y'))
{
usStatus1 = JOptionPane.showInputDialog("The customer must be an US Citizen in order to qualify" +
"for the loan.\n" + " Please enter citizenship status");
usStatus = usStatus1.charAt(0);
}
//Display results
JOptionPane.showMessageDialog(null, firstName +" "+ lastName + "\n"+
"Age :" + ageCustomer +"\n" + "US Citizen: "+ usStatus + "\n" + "Years of Work: " + yearsWork +
"\n" + "Annual Salary: $" + annualSalary + "\n" + "Qualify for the Home Equaity loan");
System.exit(0);
}
}
答案 0 :(得分:2)
while((usStatus != 'y') || (usStatus != 'Y'))
只有当usStatus
同时等同于'y'
和'Y'
时才会终止。它应该是:
while (usStatus != 'y' && usStatus != 'Y')