Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

if statement

 
Ross McManus
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ross McManus
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic