5-3 CreditCard
Post date: Mar 8, 2014 6:01:26 PM
//This program uses two void methods.
package creditcard;
import javax.swing.JOptionPane;
public class CreditCard
{
public static void main(String[] args)
{
double salary; // Annual salary
int creditRating; // Credit rating
String input; // To hold the user's input
// Get the user's annual salary.
input = JOptionPane.showInputDialog("What is your annual salary?");
salary = Double.parseDouble(input);
// Get the user's credit rating (1 through 10).
input = JOptionPane.showInputDialog("on a scale of "
+"1 through 10, what is your credit rating?\n"
+"(10 = excellent, 1 = very bad)");
creditRating = Integer.parseInt(input);
// Determine whether the user qualifies.
if (salary >= 20000 && creditRating >= 7)
qualify();
else
noQualify();
System.exit(0);
}
/*
The qualify method informs the user that he
or she qualifies for the credit card.
*/
public static void qualify()
{
JOptionPane.showMessageDialog(null, "Congratulations! You qualify for the credit card!");
}
/*
The noQualify method informs the user that he
or she does not qualify for the credit card.
*/
public static void noQualify()
{
JOptionPane.showMessageDialog(null, "I'm sorry. You do not qualify for the credit card.");
}
}