wood burning stoves
The moose likes Beginning Java and the fly likes calculating real estate commissions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "calculating real estate commissions" Watch "calculating real estate commissions" New topic

calculating real estate commissions

john corsic

Joined: May 14, 2005
Posts: 13
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
"the commission is" + commission,
"Cakculator Output",

String transactionString = JOptionPane.showInputDialog (null,
"Would you like to do another transaction (YES or No)",
"Calculator Input", JOptionPane.QUESTION_MESSAGE);

while (transactionString.equals ("YES"))


Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 805
Hello -

Yes, a while loop would work for that. Inside the while, after you get the input values, you can then add those values to some sort of tally field(s).

Also, could you please use the CODE UBB tags to enclose any code in future posts? Doing so maintains the formatting and makes reading it a whole lot easier.


Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
here's a slightly different way of doing it.
it may give you some ideas on how to complete yours

I agree. Here's the link: http://aspose.com/file-tools
subject: calculating real estate commissions
It's not a secret anymore!