boolean problem

//How to compare two houses size

Privatedouble houseSize;

Privateint numberOfRoom;

//Set and get methods

.......................

publicdouble compareHouse(House h){

return ?

}

publicstaticvoid main(Strings[]args){

House myHouse =new House();

House yourHouse =new House();

MyHouse.sethouseSize(20);

yourHouse.sethouseSize(40);

// compareHouse: it returns =0 , >0 or <0;

if( )

............................

//Two problems: 1:what should the compareHouse method return.

//2: how can I test the program, the result should be; =0 , >0 or <0;

}

[1300 byte] By [peter0001a] at [2007-10-3 4:31:05]
# 1

> Two problems: 1:what should the compareHouse method return

It's your method. You are supposed to define what it returns. It can be a random number for all I care.

> //2: how can I test the program, the result should be; =0 , >0 or <0;

By creating a house, setting some values and call the compareHouse method, to see whether it returns what you expect.

CeciNEstPasUnProgrammeura at 2007-7-14 22:34:26 > top of Java-index,Java Essentials,Java Programming...
# 2

You already answer question 1 in question 2! That method should return either <0 (-1 for example), 0 or >0 (1 for example). That would be:

<0 when house 1 is "smaller than" house 2

0 when house 1 is equal to house 2

>0 when house1 is "greather than" house 2

I suggest you check out the Comparable interface and the Collections.sort() method.

gimbal2a at 2007-7-14 22:34:26 > top of Java-index,Java Essentials,Java Programming...
# 3

> You already answer question 1 in question 2! That

> method should return either <0 (-1 for example), 0 or

> >0 (1 for example). That would be:

>

> <0 when house 1 is "smaller than" house 2

> 0 when house 1 is equal to house 2

> >0 when house1 is "greather than" house 2

How wo you know without specs? Could be the other way around as well. :) And OP still has to define "smaller" and "greater". More rooms? More size? Both?

CeciNEstPasUnProgrammeura at 2007-7-14 22:34:26 > top of Java-index,Java Essentials,Java Programming...
# 4

I'm unsure exactly what you expect from an answer, but here's a suggestion:

return houseSize - h.getHouseSize();

It depends on whether you also want the number of rooms to be taken into account in the comparison? It's for yourself to decide.

Yours, Ole

OleVVa at 2007-7-14 22:34:26 > top of Java-index,Java Essentials,Java Programming...