AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

plz help me

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
sese
Guest





PostPosted: Fri Oct 21, 2005 3:16 pm    Post subject: plz help me Reply with quote



i want to ask about the container class

The Hotel class must also contain some methods which initialise the
collection of rooms. Specifically your Hotel class should have the
following methods:

• A default constructor. This must instantiate the Room array. We will
assume that there are 20 rooms in the hotel and so the array needs to have
length 20. The constructor then needs to do several other initialisation
tasks for the rooms. Each of these tasks can be defined in its own
separate method. The constructor can then call these methods. The tasks
are described in the following bulleted points...
• A method which traverses the array and instantiates a default Room
object referenced by each array cell. From this point onwards, we will
assume that each room in the hotel has a number which is the same as its
index in the array - room number 6 will be in cell 6 of the array, etc.
• A method which traverses the array and sets the tariff of all the even
numbered rooms to $58 (these all have views of the city); and sets the
tariff of all the other rooms to $78.50 (these have water views). This
method should also set the tariff of room 0 (the first cell in the array)
to $1480 (it’s the penthouse suite!).
• A method which sets the number of beds to 4, in the last 5 rooms. This
method should also set the number of beds to 1 for rooms 1 though 5
inclusive.

The Hotel class will contain several methods which do tasks associated
with hotel management.

• A method which accepts an integer argument representing a room number
and returns a reference to the Room object in that cell of the array. If
the argument is illegal, a null reference should be returned. Call this
method ‘getRoom’.
• A method which returns the number of rooms which are booked.
• A method which returns the number of rooms which are not booked.
• A method which returns the total value of all the tariffs of all the
booked rooms. This simulates one day’s income for the hotel.
• A method called ‘getAvailableRooms’ which accepts an integer
representing a number of guests which need a room. This method should
return a String in which there is a list of all the unbooked rooms which
have enough beds for the prospective guests.
• A method which accepts a String holding the first few characters of a
guest’s name and searches through all the rooms looking for the first
guest whose name starts with those characters. The method should return
the number of the room when a match is found. If the name cannot be found,
the method should return -1. Call this method ‘findGuestRoomNumber’.


Quote:
public class Hotel
{
private final int SIZE = 20;
private Room[] rooms;
private int numberOfRooms;

public Hotel()
{
rooms = new Room[SIZE];
numberOfRooms = 0;
}

public Hotel(int size)
{
if (size <= 0) // invalid size
rooms = new Room[SIZE];
else
rooms = new Room[size];
numberOfRooms = 0;
}


public void nom(Room roomNum)
{
rooms[numberOfRooms] = roomNum;
}

public void cost()
{
for(int i = 2;i<=rooms.length;i+=2)
{
rooms.setTariff(58.0);
}

for(int i = 1;i<=rooms.length;i+=2)
{
rooms.setTariff(78.50);
}

for(int i = 0;i<=rooms.length;i+=0)
{
rooms.setTariff(1480.0);
}
}

public void numberBed()
{
for(int i = 15;i<=rooms.length;i++)
{
rooms.setNumOfBeds(4);
}

for(int i = 1;i<=5;i++)
{
rooms.setNumOfBeds(1);
}
}

public String getRoom()
{
String msg = "All roomsn";
for(int i = 0;i<=numberOfRooms;i++)
{
msg=rooms.toString();
return msg;
}
return null;
}

public double totalTariff()
{
int tariff = 0;
int total = 0;
for(int i=0;i {
total+=rooms.getTariff();
}
return total;
}
}

above is the container class
who can teach me how to write?
below is the class file :
Quote:

public class Room
{
private int NumOfBeds;
private boolean bookingStatus;
private double tariff;
private String name;

public Room()
{
NumOfBeds = 2;
bookingStatus = false;
tariff = 0.0;
name = "nobody";
}

public int getNumOfBeds()
{
return NumOfBeds;
}

public boolean isBooked()
{
return bookingStatus;
}

public double getTariff()
{
return tariff;
}

public String getName()
{
return name;
}

public void setNumOfBeds(int inNumOfBeds)
{
if(inNumOfBeds<=5 && inNumOfBeds>=0)
NumOfBeds = inNumOfBeds;
}

public void setTariff(double inTariff)
{
if(inTariff>0.0)
tariff = inTariff;
else
tariff = 0.0;
}

public String book(String bookedName)
{
bookingStatus = true;
name = bookedName;
return name;
}

public String unbook()
{
bookingStatus = false;
name = "nobody";
return name;
}

public String toString()
{
return "Number of beds are : "+NumOfBeds+"n"+"Booking Status is :
"+bookingStatus+"n"+"Tariff is : "+tariff+"n"+"Name is : "+name;
}
}



Back to top
Andrew Thompson
Guest





PostPosted: Fri Oct 21, 2005 3:35 pm    Post subject: Re: plz help me Reply with quote



sese wrote:

Quote:
i want to ask about the container class

(big snip)

Quote:
above is the container class
who can teach me how to write?

Aha! A question! I had to copy the entire text into a text
editor and search on '?' before I found it buried between the
code samples.

Quote:
below is the class file :

OK.. Goodo..

The answer to your question is

"A number of people who read this usenet news group are
capable of helping you, but they would need more information
to do that, as well as more direct questions from you."

Your questions should come one at a time, and be very
specific to an immediate problem.

You are not likely to get 'hold my hand and show me exactly'
type help, here.

Back to top
HalcyonWild
Guest





PostPosted: Fri Oct 21, 2005 7:47 pm    Post subject: Re: plz help me Reply with quote




sese wrote:
Quote:
above is the container class
who can teach me how to write?


Yes, good to see you working hard to post so much, but can you clarify
your question. What do you want to write. What problem are you facing.


Back to top
Roedy Green
Guest





PostPosted: Fri Oct 21, 2005 9:03 pm    Post subject: Re: plz help me Reply with quote

On Fri, 21 Oct 2005 11:16:33 -0400, "sese" <xiaoyuer66 (AT) hotmail (DOT) com>
wrote or quoted :

Quote:
i want to ask about the container class

How come then did not say so in your subject line?

How come you then asked no questions about Containers, but instead
posted your homework assignment. See
http://mindprod.com/jgloss/homework.html

--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.