java problem
Room.java
This file defines a class of Room objects. The objects have the following instance variables:
number of beds in the room, of type integer;
guest?s name, of type String;
booking status of a room ? if the room has been booked, the status is 'true', otherwise it is
'false';
room tariff, i.e. cost of using the room for one night, of type double;
The methods of class Room should include:
· A default constructor which does not accept any arguments. This constructor should
initialise a Room object with the number of beds as two, the guest's name as "Nobody",
the booking status as false, and the room cost to 100.00. This is the default state of a
Room object.
· A writer method for the number of beds. This method accepts one argument which is used
to set the number of beds. It must ensure that the number of beds stored in the Room
object remains in the range 1..4 inclusive.
· A writer method for the room tariff. This method accepts one argument representing a
new tariff value and must ensure that the tariff is never negative.
· A method called book which accepts a String argument representing a guest?s name. It
sets the booking state to true and assigns the parametric string to the guest's name
variable.
· A method called unbook which sets the booking state to false and sets the guest's name
variable back to "Nobody".
· A reader method for each of the number of beds, the tariff and the guest's name - these
return the appropriate value.
A boolean method called isBooked which returns the booking status.
A 'toString' method which return a single String containing the details of a room with
format as described below:
Room with <numOfBeds> beds, tariff <roomTariff>, and guest
named <guestName>.
or
Room with <numOfBeds> beds, tariff <roomTariff>, and is
vacant.
Example:
Room with 2 beds, tariff 100.00, and guest named James Bond.
or
Room with 2 beds, tariff 100.00, and is vacant.
It is recommended that once you have written the Room class, you create a tiny program to
test it. The testing program should be placed in the same working directory as the Room class
and be used to create one or two Room objects and call some of the Room methods. Compile
the Room class and compile and run the test program to check your work.
Hotel.java
This file declares a class of object which maintains a collection of Room objects. It will
contain methods which enable the collection to show the appropriate behaviours as required
by the menu. This file should be saved into the same working directory as Room.java.
The Hotel class should declare only an array of Room objects, no additional attribute is
allowed.
The Hotel class must also contain some methods which allow the collection of rooms to be
managed. These methods should include:
· A constructor which accepts an integer which is used to set the size of the Room array. If
the integer value passed in is invalid, then an array of Room objects of size 50 is to be
created. If the parametric integer is valid, that is between 20 and 100, inclusive, then a
Room array of the specific parametric value will be created. Next you need to perform
some initialisation tasks for the rooms as described below. Each task can be defined as
private method, and the constructor will then invoke these methods to complete the task:
First task is to traverse the array and instantiates a default Room object referenced by
each array cell. After each Room has been instantiated, we will assume that the array
index will represent the room number in the hotel. For example room numbered 2 will
be in array cell with index 2, room numbered 5 will be in array cell with index 5, etc.
Second task is to traverse the array and set the room tariff of all the even numbered
rooms to $150.00, except room numbered 0, which is set to $1500.00 as it is the
penthouse suite.
Third task is to set the number of beds to 1 for the last 5 rooms, and set the number of
beds to 4 for rooms 1 though 5 inclusive.
· A method named getRoom which accepts an integer parameter representing a room
number and returns a reference to the Room object in that cell of the array. If the
parametric integer is illegal, a null reference should be returned.
· A method named numOfBookedRooms which does not accept any parameter, and returns
the number of rooms which are booked.
· A method named numOfVacantRooms which does not accept any parameter, and returns
the number of rooms which are not booked.
· A method named totalTariff which does not accept any parameter, and returns the total
value of all the tariffs of all the booked rooms. This simulates one day's income for the
hotel.
· A method named 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 named findGuestRoomNumber which accepts a String representing a guest's
name and searches through all the rooms looking for the first guest whose name is the
same as the parametric name. 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.
When you have written the Hotel class - test it by creating a Hotel object and invoking the
methods from a small Java program.
HotelMain.java
The aim of this class is to provide a user-interface for a modest application which uses a
Hotel container class and should be saved in the same working directory as the previous
files. It is recommended that this user-interface be written as a 'console' application using the
normal screen and keyboard to interact with a user via a simple text-based menu.
The user-interface should create a single Hotel object and provide a menu of choices to the
user with the following choices:
1 See available rooms for 'n' guests
~ 4 ~
The operator enters the number of guests needing accommodation. This value should then be
passed to the getAvailableRooms method of the Hotel object, the returned String captured
and displayed. This tells the operator which rooms can be booked.
2 Book a room
The operator enters name of the guest, then fetches the Room object of an appropriate empty
room (using the 'getRoom' method) and books it with the guest's name.
3 Unbook a room
The operator enters the number of the room to be unbooked, the Room object with that
number is obtained using 'getRoom' and unbooked. If the room is not booked, display an
appropriate message.
4 Find which room a guest is in.
The operator enters a guest's name and this is passed to the 'findGuestRoomNumber' method
and the room number is displayed. If no such guest is found, display an appropriate message.
5 Print a report
Display
· the number of booked rooms
· the number of empty rooms
· the total tariff of all booked rooms
6 Other options
You may add any other options you like to this list and you will be given credit for those
which are implemented correctly.
7 Quit the program.
Each time the user selects one of the previous options, and the program does that task,
View Answers
Related Tutorials/Questions & Answers:
java Problemjava Problem I want to create a binary tree for displaying members in Downline. i am creating a site for MLM(Multi-Level MArketing). tree must be dynamically populated from database. is there any help for me.
Thanks in advance
JAVA ProblemJAVA Problem Write a program that takes two parameters
1. a word
2. an array of words
It should then remove all instances of the word in the array.
For Example:
INPUT
word="ravi"
word_array = ["Chethan Bhagat
Advertisements
resolution problem in javaresolution
problem in java I designed project in
java in my PC when run the same project in some other PC i can't fully view my
java forms.Some said that it is resolution
problem Problem in uploading java applicationProblem in uploading
java application I have uploaded my
java application (folder created under webapps) using Filezilla FtpClient.Application... this
problem for a problem in coading - Java Beginnersfor a
problem in coading what is the problm in following coading...(String[] args)
{
mywindow ();
}
}
Hi Friend,
There is no
problem... mywindows.java
Run :
java mywindows
Thanks
RoseIndia Team
Multiplication problem - Java BeginnersMultiplication problem I am facing a peculiar
problem in
java regarding a multiplication. Please see below:
19300 * 0.001 = 19.3
19400 * 0.001 = 19.400000000000002 (why is this ??)
19500 * 0.001 = 19.5
Can anybody help
code problem - Java Beginners
java script
j2ee
j2me
sql
plz help me to sort out this
problem.
thnx
...code problem Dear sir,
I'm havin a
problem that suppose i've got a file that contains the following lines-
java
java script
j2ee
php
sql
Problem on JAVA ProgrammeProblem on
JAVA Programme public class AA {
int add(int i) {
int y = i;
y += 20;
if (y <= 100){ y +=30;add(y);}
System.out.println("Final Value of y : " + y);
return y;
}
public static void main
JAVA CLASSPATH PROBLEMJAVA CLASSPATH PROBLEM hi all Friends
I am stuck using the
java servlets and
problem raise for classpath.
I had a
problem with servlet to call... that it didn't found any
java class (which is
java class calling from servlet).
but i
Java Problem - Java BeginnersJava Problem Write a program 2 input a positive integer n and check wheter n is prime or not and also know the position of that number in the prime...,
Code to solve the
problem :
import java.io.*;
public class PrimeNumber
Java implementation problem/answers/viewqa/
Java-Beginners/28578-java-implementation-
problem-.html...
Java implementation problem I want to implement following in
java...
problem in your post previews.
please consider
1. 2. points just after main
code problem - Java Beginners; Hi friend,
Code to help in solving the
problem :
import java.io.... in
Java visit to :
http://www.roseindia.net/
java/example/
java/io/
Thanks
java implementation problem java implementation
problem I want to implement following in
java code :
Main thread
Create three threads
wait for completion of stage 2 of all three threads
Access all three local variable (LC0, LC1, LC2) of threads
bulid
problem 1 - Java Beginnersproblem 1 Hi,
please help me!!!! How can i code in
java using Two-dimensional Arrays? This question is related to the one i posted before. this is my input data file:
88 90 94 102 111 122 134
75 77 80 86 94 103 113
80
code problem - Java Beginnerscode problem Dear sir,
I have an excel file in D: drive called today.xls, i want to open it thru
java program, what code would be compatible plz help me Hi friend,
Code to help in solving the
problem :
import
Basic problem for Java expertsBasic
problem for
Java experts This assignment will test your knowledge of
Arrays
Array searching
Array sorting
Array processing
Specification
An athletics club require a simple statistical analysis program for analysing lap
problem with main - Java Beginnersproblem with main
import javax.swing.*;
import java.awt.... a
problem. when i compile it appears this message:
java.lang.NoSuchMethodError: main... it with html file.
applet.html:
Java Applet Demo
Thanks
code problem - Java Beginnerscode problem Dear sir,
my
problem is that I've a string value if this String value has "quit" then output should be "bye". i want to make this program using SWITCH CASE statement. how to implement String value in Switch plz
Bid Problem - Java Beginners in this application explain in details :
Code to help in solving the
problem...!");
}
}
}
For more information on
Java visit to :
http://www.roseindia.net/
java/
Thanks
Problem with code - Java BeginnersProblem with code Hi Deepak. Im a newbie here at your forum. I have got a simple code of mine which is having a little
problem. When I compile it, i get an...,identifier expected'...error. Could you help me out? Thank you
Problem in coding - Java BeginnersProblem in coding How many times do you have to roll a pair of dice before they come up snake eyes? You could do the experiment by rolling the dice... friend,
Code to help in solving the
problem.
public class Stimulates
problem - Java Beginners in
java if want something like this using array? Hi friend,
Code to solve the
problem :
import java.io.*;
public class JavaMeanDeviation
problem - Java Beginners in
java if want something like this using array? Hi friend,
Code to solve the
problem :
import java.io.*;
public class JavaMeanDeviation
code problem - Java Beginnerscode problem Dear sir,
My
problem is that i have some string value and in some case i want to remove all the value of this string, i tried this code-
Response.str.clear();
but it shows some error called "response package
code problem - Java Beginnerscode problem Dear sir, my
problem is given below:
suppose a file Carries the following lines-
Name: john
age: 45
Address: goa
phone...; Hi friend,
Code to help in solving the
problem :
import java.io.
Problem with picture - Java BeginnersProblem with picture Hi,
I Develope a School Automated System that takes a details from the user interface and deposited into the database (MSSQL), i make the registrar to be able to upload the student picture from
Problem with picture - Java BeginnersProblem with picture Hi,
I Develope a School Automated System that takes a details from the user interface and deposited into the database (MSSQL), i make the registrar to be able to upload the student picture from
Problem in java 1.6 - Java BeginnersProblem in
java 1.6 Am facing
problem in
java 1.6 . Ex. In a Frame...... Hi friend,
Give source code where you having the
problem
For read more information on
java visit to :
http://www.roseindia.net/
java arraylist problem - Java Beginnersarraylist problem Hello....
I wrote the following code for adding a string array into an array list along with other strings...
and to display the string array...
But there's a
problem with this...
import java.util.
code problem - Java Beginnerscode problem Dear sir,
I've some string called "JohnSon" that has to be crypted first and then decrypted, how to crypt and decrypt data plz tell me. Hi friend,
Code to help in solving the
problem :
public
code problem - Java Beginnerscode problem Dear sir,
my
problem is that, i have two Combobox
one carries the followin value- "india","america".
whereas another carries - "mumbai","dellhi","washingtone","newyork".
when india is selected from one combobox
Java problem - Java BeginnersJava problem what are threads in
java. what are there usage. a simple thread program in java Hi Friend,
Please visit the following link:
http://www.roseindia.net/
java/thread/index.shtml
Thanks
Java problem - Java BeginnersJava problem I have an image in my application and I need to restrict the image path view on the browser. Noone should be able to right click and see the image path. Please help
java problem - Java Beginnersjava problem Write a program to model a simple calculator. Each data... to power of right operand)
q quit
Your calculator should display the accumulator... is 0.23999999999999985
+ 10
Result so far is 10.24
q 0
Final result is 10.24
Java Problem - Java BeginnersJava Problem How to create executable file of a
java program.That is steps to create a Jar File of a
Java Program Hi Friend,
Try the following code:
import java.io.*;
import java.util.jar.*;
public class
java problem - Java Beginnersjava problem Suppose list is an array of five components of the type int.What is stored in list after the following
Java code executes?
for (i = 0; i < 5; i++)
{
list[i] = 2 * i + 5;
if (i % 2 == 0)
list[i] = list[i
JAVA Problem - Java BeginnersJAVA Problem please help me!!!! How can i code in
java using Two-dimensional Arrays?
88 90 94 102 111 122 134
75 77 80 86 94 103 113
80 83 85 94 100 111 121
68 71 76 85 96 110 125
77 84 91 98 105 112 119
81 85 90 96 102
java problem - Java Beginnersjava problem a) Binary numbers is important in computers. Binary number system uses only two digits, 0
and 1. There are pre-defined methods available in
Java that will allow us to convert from
denary integer (base 10
Java Problem - Java BeginnersJava Problem How to create a jar file of a program Hi Friend,
Try the following code:
import java.io.*;
import java.util.jar.*;
public class CreateJar {
public static int buffer = 10240;
protected void
java problem - Java Beginnersjava problem Hotel.java
This file declares a class of object which maintains a collection of Room objects. It will
contain methods which enable... from a small
Java program
java problem - Java Beginnersjava problem Room.java
This file defines a class of Room objects. The objects have the following instance variables:
number of beds in the room... from a small
Java program.
HotelMain.java
The aim of this class is to provide
java problem - Java Beginnersjava problem Write a program that could be used to help children...();
System.out.print("How many problems would you like? ");
double
q = scan.nextDouble();
System.out.println();
double r=0,w=0;
for (int idx = 1; idx <=
q Problem with picture - Java BeginnersProblem with picture Hi,
I Develope a School Automated System that takes a details from the user interface and deposited into the database (MSSQL), i make the registrar to be able to upload the student picture from
java programming problem - Java Beginnersjava programming problem Given a deck of ncards unique cards.Cut the deck iCut cards from the top portion of the deck followed by the bottom card... etc. Alternating the remaining cards go on top. The
problem is to find