Results 1 to 8 of 8
Thread: mutator method
 11222007, 06:51 PM #1Member
 Join Date
 Nov 2007
 Posts
 38
 Rep Power
 0
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.
Java 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; } }
 11222007, 06:56 PM #2
Where are you having trouble?
 11222007, 06:58 PM #3Member
 Join Date
 Nov 2007
 Posts
 38
 Rep Power
 0
it doesnt return a bill
 11222007, 07:39 PM #4
You can just about write the method by reading the requirements.
Java 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... ...
Java 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; }
Java 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 [i]double[/i] here // so no matter what happens above a double is returned. // Getting rid of the else and curley braces above will work. }
 11222007, 08:13 PM #5Member
 Join Date
 Nov 2007
 Posts
 38
 Rep Power
 0
Java 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. }
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; 11222007 at 08:19 PM. Reason: need to
 11222007, 08:35 PM #6
cannot find symbol  method getNumDinners()
Java Code:arrayNewRoom[roomnum].getNumDinners()
is this one covered
Java Code:public double getBill(int roomnum) { double bill = 0; if(arrayNewRoom[roomnum] != null) { // modify bill, don't redefine 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; }
 11222007, 08:56 PM #7Member
 Join Date
 Nov 2007
 Posts
 38
 Rep Power
 0
[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.
 11222007, 11:29 PM #8
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:
Java Code:double bill = arrayNewRoom[roomnum].getNumDinners() * dinnerPrice + arrayNewRoom[roomnum].getLengthOfStay()
Java 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();
Similar Threads

method not abstract, does not override actionperformed method.
By Theman in forum New To JavaReplies: 2Last Post: 03262010, 06:12 PM 
Method Help
By pringle in forum New To JavaReplies: 4Last Post: 04162008, 01:23 PM
Bookmarks