944,117 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 5723
  • Java RSS
You are currently viewing page 1 of this multi-page discussion thread
Nov 19th, 2007
0

integer comparison

Expand Post »
Hi I am creating a house search programme. the objective of this programme is to sell houses within a range specified by the potential buyer. Now the buyer would type in the amount he is willing to spend and the houses closest to this range should be presented to him/her even if they are a long way off, so long as they are the closest.

Many thanks in advance
Similar Threads
Reputation Points: 14
Solved Threads: 0
Junior Poster in Training
Grub is offline Offline
60 posts
since Oct 2007
Nov 19th, 2007
0

Re: integer comparison

And what is your question?
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Nov 19th, 2007
0

Re: integer comparison

"do my homework for me", probably.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Nov 19th, 2007
0

Re: integer comparison

Sorry, my question is, how do I compare the integer values (price) of the houses to a user defined integer and determine which has the closest value to the user defined integer.
Reputation Points: 14
Solved Threads: 0
Junior Poster in Training
Grub is offline Offline
60 posts
since Oct 2007
Nov 19th, 2007
0

Re: integer comparison

With comparison operators and subtraction.

This would normally be done through a query to a database though, not in your Java code.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Nov 20th, 2007
0

Re: integer comparison

I am afraid the requirement is only through the java code. the logic eludes me.
Reputation Points: 14
Solved Threads: 0
Junior Poster in Training
Grub is offline Offline
60 posts
since Oct 2007
Nov 20th, 2007
0

Re: integer comparison

Well at least give it a try. Post the code and all error/compile messages as well as what it does (not) do that you expected, once you have written something.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Nov 20th, 2007
0

Re: integer comparison

Java Syntax (Toggle Plain Text)
  1. if (a - b > 0) {
  2. // blah blah blah
  3. }

Sheesh, how hard can it get?
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Nov 20th, 2007
0

Re: integer comparison

you migh wanna do a binary search and keep some parameters until you find the closest ones
house1: $10k
house2: $25k
house3: &50k and so on and then search through the array or binary tree depending which one you wanna use to storage your data until you get the closest price
if you wanna compare the value i think you cant do (a - b > 0) you have to do eiher:

int dif = a - b;
if (dif > 0);

or

if ((a - b) > 0)
Last edited by uonsin; Nov 20th, 2007 at 11:47 pm.
Reputation Points: 8
Solved Threads: 2
Newbie Poster
uonsin is offline Offline
17 posts
since Oct 2007
Nov 21st, 2007
0

Re: integer comparison

Click to Expand / Collapse  Quote originally posted by uonsin ...
if you wanna compare the value i think you cant do (a - b > 0) you have to do eiher:

int dif = a - b;
if (dif > 0);

or

if ((a - b) > 0)
Wrong.

I'm sorry, but, take two minutes to perform a test and you can avoid making false assumptions like this.

Edit: I mean, both of your examples, of course, work, but so does the original, making your "workarounds" unnecessary (although I will often use the second myself, to make maintenance of the code, for some of the novice programmers we have here, clearer).
Last edited by masijade; Nov 21st, 2007 at 2:31 am.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: need help with java program.
Next Thread in Java Forum Timeline: array problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC