I'm trying to create a program that will calculate real estate commission. The user must enter a sale price and a property code. There are 3 property codes (R,M,C) and each one represents a certain commission rate. I've been trying to figure it out, but i must be missing something. Take a look and let me know:
// RealEstateCommission.java: Calculates real estate commissions
import javax.swing.JOptionPane;
public class Calculator{
/** Main method */
public static void main(
String[] args) {
double salePrice;
char propertyType = ('R', 'M', 'C');
double commissionRate;
// 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 (propertyType == 'R')
commissionRate = 0.070;
else if (propertyType == 'M')
commissionRate = 0.060;
else if (propertyType == 'C')
commissionRate = 0.035;
else{
JOptionPane.showMessageDialog (null,
"Error: Wrong property code, please try again",
"Calculator", JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
// 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,
"Calculator Output",
JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}