This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Java in General and the fly likes if statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "if statement" Watch "if statement" New topic
Author

if statement

Ross McManus
Greenhorn

Joined: Jul 28, 2010
Posts: 28
Hi.

I am trying to write code for a Hotel Booking System.

On the first part it tells me

Rooms numbered 201 to 203 are single bedrooms, with a rate of 35.
Rooms 204 to 212 are double bedrooms with a rate of 60

I guess I am going to have to write an if statement for this. I was just wondering how I write one so that it is

if roomNumber = 201 to 203
{
rate = 35

}

EDIT : I have just tried something and it compiles, Just wondering if anyone could tell me if this is right. Here is the code.






David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

http://www.java2s.com/Tutorial/Java/0080__Statement-Control/Usinginifstatement.htm

Check that out first, then give it a shot--if you still have further questions, post the if statement syntax you're trying and we'll take it from there!
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Ross McManus wrote:
if roomNumber = 201 to 203
{
rate = 35

}


I don't know whether I understood you question properly. But my suggestion:



Is this you want?


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Ross McManus
Greenhorn

Joined: Jul 28, 2010
Posts: 28
Abimaran Kugathasan wrote:
Ross McManus wrote:
if roomNumber = 201 to 203
{
rate = 35

}


I don't know whether I understood you question properly. But my suggestion:



Is this you want?


Yes that is exactly what I needed thanks for the reply.

Also David Newton thanks for the link as well.
Ross McManus
Greenhorn

Joined: Jul 28, 2010
Posts: 28
I have another question if someone could help.

On the sheet I have it says.

"If a room is not booked, the customer is null"

I guess I have to write an if statement somewhere to check if the room has been booked or not and then set the customer to null?

Does anyone know where I would write this code?

I have a bookRoom(String); Method would it be in there?

Here is the room code again. In the if statements that I wrote before I have added customer = null; Because on the sheet it said "All rooms may have a customer, Initially the customer will be null."

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Abimaran Kugathasan wrote:
(a complete answer)

Please do not hand out answers on a plate; our goal at JavaRanch is to be something other than a code mill--please see NotACodeMill.

Since it's too late, I have not removed your solution.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I have a bookRoom(String); Method would it be in there?
No, that would be backwards. When a customer checks out the room would no longer have a customer.
I don't understand the purpose of "n".

Here's something else to consider.

Is a customer an intrinsic property of a room? Or is a customer something that occasionally occupies a room? What if a room has more than one person in it? What if the same person pays for multiple rooms? My initial reaction is that I'd have a map of rooms to customers in the room, rather than a room having a customer. (Or a customer having a room.)

In addition, is room booking something that a Room class should know anything about? Or is room booking something that whatever *contains* the rooms should know something about? And why should a room understand pricing rules? What if they change? Why should a room know number ranges of *other* rooms? In other words, if I'm room 235, should I really know about room 240?
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

David Newton wrote:
Abimaran Kugathasan wrote:
(a complete answer)

Please do not hand out answers on a plate; our goal at JavaRanch is to be something other than a code mill--please see NotACodeMill.

Since it's too late, I have not removed your solution.


Really sorry. apologize me! Won't happen anymore!
Ross McManus
Greenhorn

Joined: Jul 28, 2010
Posts: 28
David Newton wrote:
I have a bookRoom(String); Method would it be in there?
No, that would be backwards. When a customer checks out the room would no longer have a customer.
I don't understand the purpose of "n".

Here's something else to consider.

Is a customer an intrinsic property of a room? Or is a customer something that occasionally occupies a room? What if a room has more than one person in it? What if the same person pays for multiple rooms? My initial reaction is that I'd have a map of rooms to customers in the room, rather than a room having a customer. (Or a customer having a room.)

In addition, is room booking something that a Room class should know anything about? Or is room booking something that whatever *contains* the rooms should know something about? And why should a room understand pricing rules? What if they change? Why should a room know number ranges of *other* rooms? In other words, if I'm room 235, should I really know about room 240?


I am not sure, On the sheet I got it has a UML diagram and I just created the class's off what was specified in the UML diagram.

Here is what I got.




David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Oh, well, if you're coding to a spec it doesn't matter then. If you changed your code and want feedback on it, post a new message rather than editing the original.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: if statement