• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

converting a character into a number

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to create a program that calculate's real estate commission. I need certain property codes such as S,L, and M to represent different commission rates. How would i do this?
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi John,

Welcome to JavaRanch!

How you would do this depends on a couple of things. If there are only a few rates, then the easiest thing to do just looks like



On the other hand, if there are a hunded different rates, then you'd want to put the codes and rates into arrays, and look up the code in this "table" as needed.



In both cases, the code could be modified a bit to report an error if the code was not recognized; as written, it will just use a default.
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
john corsic
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help! I'm slowly on my way to figuring this out.

There are only three rates. I want the program to request the sale price of the property and then request the property code (the property code will correspond to a certain rate). Finally, i want it to calculate and display the commission based on the input. I am going to post the work I have done so far, if someone could please point me in the right direction.

Thanks again for all the help, i'm just a beginner.

// RealEstateCommission.java: Calculates real estate commissions
import javax.swing.JOptionPane;

public class Assignment2_1tests {
/** 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",
"Assignment2_1test 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))",
"Assignment2_1tests 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",
"Assignment2_1tests Output", 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,
"Assignment2_1tests Output",
JOptionPane.INFORMATION_MESSAGE);

System.exit(0);

}

}
 
Without subsidies, chem-ag food costs four times more than organic. Or this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic