
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.

Where are you having trouble?


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 [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.
}

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?

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 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;
}

[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.

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();