Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-22-2007, 06:51 PM
Member
 
Join Date: Nov 2007
Posts: 33
dirtycash is on a distinguished road
mutator method
getBill has one parameter, an integer value representing a room number, and returns an
integer value representing the bill in pounds for the occupier in that room. The constant
values in the Hotel class define the appropriate values to use when computing the bill.
Here is how to compute the bill:

(a) Let total initially be zero.

(B) Let lengthOfStay be the number of nights the occupier has stayed at the hotel.

© Let numInGroup be the number of people occupying the room.

(d) If the room has a sea view, increment total by the lengthOfStay multiplied by the
SEAVIEW SUPPLEMENT.

(e) If there is only one person in the group occupying the room, increment total by the
lengthOfStay multiplied by SINGLE OCCUPIER SUPPLEMENT.

(f) Increment total by the lengthOfStay multiplied by the ROOM PRICE multiplied by
the numInGroup.

(g) Increment total by the number of dinners eaten by the occupiers multiplied by the
DINNER PRICE.

(h) Return the total.

Code:
/** get bill method to calculate the final bill of one room/group of customers **/ public double getBill(int roomnum) { if(rooms[roomnum] != null) { double bill = rooms[roomnum].getNumberOfDinners() * dinnerPrice + rooms[roomnum].getLengthOfStay() * roomPrice; return bill; } else { return 0; } }
my code is completely wrong.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-22-2007, 06:56 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,144
hardwired is on a distinguished road
Where are you having trouble?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-22-2007, 06:58 PM
Member
 
Join Date: Nov 2007
Posts: 33
dirtycash is on a distinguished road
it doesnt return a bill
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 11-22-2007, 07:39 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,144
hardwired is on a distinguished road
You can just about write the method by reading the requirements.
Code:
public double getBill(int roomNum) { // Let total initially be zero double total = 0; // Let lengthOfStay be the number of nights the occupier has stayed at the hotel // What class will keep this information for you, Room, Occupier... // Wherever you have this information you get it for the value that we need // here: int lengthOfStay // Let numInGroup be the number of people occupying the room // Get this information from whatever class that you keep it in and assign // its value to this variable: int numInGroup // If the room has a sea view, increment total by the // lengthOfStay multiplied by the SEAVIEW_SUPPLEMENT // write a statement to do this... ...
the genral idea for the method, as gleaned from the requirements posted above is
Code:
public double getBill(int roomNum) { total = zero assemble info needed for calculations add charges to the bill according to the inforamtion we have in various classes return total; }
Code:
public double getBill(int roomnum) { // If this block doesn't execute execution passes by to the default // return below (with the else {} part commented out below if(rooms[roomnum] != null) { double bill = rooms[roomnum].getNumberOfDinners() * dinnerPrice + rooms[roomnum].getLengthOfStay() * roomPrice; return bill; } // else // { return 0; // } // this method needs a return of type double here // so no matter what happens above a double is returned. // Getting rid of the else and curley braces above will work. }
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 11-22-2007, 08:13 PM
Member
 
Join Date: Nov 2007
Posts: 33
dirtycash is on a distinguished road
Code:
public double getBill(int roomnum) { if(arrayNewRoom[roomnum] != null) { double bill = arrayNewRoom[roomnum].getNumDinners() * dinnerPrice + arrayNewRoom[roomnum].getLengthOfStay() * roomPrice; return bill; } else { return 0; } // this method needs a return of type double here // so no matter what happens above a double is returned. // Getting rid of the else and curley braces above will work. }
error message - cannot find symbol - method getNumDinners()

how do i fix this?


edit - plus is this one

(e) If there is only one person in the group occupying the room, increment total by the
lengthOfStay multiplied by SINGLE_OCCUPIER_SUPPLEMENT

covered?

Last edited by dirtycash : 11-22-2007 at 08:19 PM. Reason: need to
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 11-22-2007, 08:35 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,144
hardwired is on a distinguished road
cannot find symbol - method getNumDinners()
Code:
arrayNewRoom[roomnum].getNumDinners()
Here you are looking for a getNewDinners method in the Room class (arrayNewRoom[roomnum] is a Room). Does the Room class have this method? The compiler say it cannot find it. Same with the next method getLengthOfStay.

is this one covered
Code:
public double getBill(int roomnum) { double bill = 0; if(arrayNewRoom[roomnum] != null) { // modify bill, don't re-define it // if the if condition doesn't evalutate to true we won't // come in here and bill will remain zero. Let that be returned // after this block bill += arrayNewRoom[roomnum].getNumDinners() * dinnerPrice + arrayNewRoom[roomnum].getLengthOfStay() * roomPrice; if(only one occupier) bill += SINGLE_OCCUPIER_SUPPLEMENT; ... next charge... etc } return bill; }
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 11-22-2007, 08:56 PM
Member
 
Join Date: Nov 2007
Posts: 33
dirtycash is on a distinguished road
[code]
/**
* Return the number of nights the group has stayed at the hotel
*/
public int getLengthOfStay()
{
return Amountofnights;
}


/**
* Return the amount of times the group have eaten dinner
*/
public int getNumDinners()
{
return Numberofdinners;
}


these are in the occupier class.
the sheet that i have to follow told me to put them there, not in the room class.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 11-22-2007, 11:29 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,144
hardwired is on a distinguished road
these are in the occupier class
Then that's where we should look for them. Your code was looking for them in the room class:
Code:
double bill = arrayNewRoom[roomnum].getNumDinners() * dinnerPrice + arrayNewRoom[roomnum].getLengthOfStay()
To look for them in the Occupier class you use the room to get the occupier:
Code:
public int getBill(int roomNumber) { int total = 0; int roomIndex = roomNumber -1; Room room = arrayNewRoom[roomIndex]; Occupier occupier = room.getOccupier(); int lengthOfStay = occupier.getLengthOfStay(); int numOfDinners = occupier.getNumDinners();
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Method Help pringle New To Java 4 04-16-2008 02:23 PM
method not abstract, does not override actionperformed method. Theman New To Java 1 05-08-2007 07:13 AM


All times are GMT +3. The time now is 09:37 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org