posted May 20, 2005 01:45 AM
--------------------------------------------------------------------------------
I've created a program that calculates real estate commission. The person inputs the sale amount and then enters a letter which represents a certain commission rate. It then calculates the commission and displays it. After the commission amount is displayed i want it to prompt the user for another transaction. When there are no more transactions i want the program to display the total amount of the properties entered, and the total amount of the commissions calcualted. I'm not too sure what to do. Should i use a while loop? Here is what i have done so far.
// RealEstateCommission.java: Calculates real estate commissions
import javax.swing.JOptionPane;
public class Calculator {
/** Main method */
public static void main(
String[] args) {
double salePrice;
double commissionRate = 0;
// Enter sale price
String salePriceString = JOptionPane.showInputDialog (null,
"Enter sale price",
"Calculator Input", JOptionPane.QUESTION_MESSAGE);
salePrice = Double.parseDouble(salePriceString);
// Enter property code (residential, multidwelling or commercial)
String propertyTypeString = JOptionPane.showInputDialog (null,
"Enter property code (residential (R), multidwelling (M) or commercial(C))",
"Calculator Input", JOptionPane.QUESTION_MESSAGE);
if (propertyTypeString.equals ("R"))
commissionRate = 0.070;
else if (propertyTypeString.equals ("M"))
commissionRate = 0.060;
else if (propertyTypeString.equals ("C"))
commissionRate = 0.035;
// Calculate commission
double commission = salePrice * commissionRate;
// Format to keep two digits after the decimal point
commission = (int)(commission * 100) / 100.0;
// Show results
JOptionPane.showMessageDialog(null,
"the commission is" + commission,
"Cakculator Output",
JOptionPane.INFORMATION_MESSAGE);
String transactionString = JOptionPane.showInputDialog (null,
"Would you like to do another transaction (YES or No)",
"Calculator Input", JOptionPane.QUESTION_MESSAGE);
while (transactionString.equals ("YES"))
System.exit(0);
}
}