Create a class roomoccupancy that can be used to record the


1. We created in class a Person class to represent a person. The class has instance variables for a person's name, which is a string, and an integer age. These variables are name and age, respectively.

a. Write a default constructor for Person that sets name to the string "No name yet" and age to zero.

b. Write a second constructor for Person that sets name to a given string and age to a given age.

c. Write a static method createAdult() for Person that returns a special instance of this class. The instance represents a generic adult and has the name "An adult" and the age 21.

2. Create a class RoomOccupancy that can be used to record the number of people in the rooms of a building. The class has the attributes

• numberInRoom-the number of people in a room
• totalNumber-the total number of people in all rooms as a static variable

The class has the following methods:

• addOneToRoom-adds a person to the room and increases the value of totalNumber

• removeOneFromRoom-removes a person from the room, ensuring that numberInRoom does not go below zero, and decreases the value of totalNumber as needed

• getNumber-returns the number of people in the room

• getTotal-a static method that returns the total number of people

3. Define a class called Counter. An object of this class is used to count things, so it records a count that is a nonnegative whole number. Include methods to set the counter to 0, to increase the count by 1, and to decrease the count by 1. Be sure that no method allows the value of the counter to become negative. Also include an accessor method that returns the current count value, as well as a method that displays the count on the screen. Do not define an input method. The only method that can set the counter is the one that sets it to zero.

Solution Preview :

Prepared by a verified Expert
Database Management System: Create a class roomoccupancy that can be used to record the
Reference No:- TGS01187991

Now Priced at $45 (50% Discount)

Recommended (99%)

Rated (4.3/5)

A

Anonymous user

3/28/2016 6:27:42 AM

Read all the questions illustrated properly and on the requisite of the problem, respond to the following questions. 1) We create a class Person class to represent the person. The class consists of instance variables for person's name that is a string and an integer age. Such variables are name and age, correspondingly. a) Write down a default constructor for Person which sets name to string "No name yet" and age to zero. b) Write second constructor for Person which sets name to particular string and age to given age. 2) Define class called Counter. The object of this class is employed to count things; therefore it records a count which is a non-negative whole number. Comprise methods to set counter to 0, to raise the count by 1 and to reduce the count by 1. Ensure that no method permits the value of counter to become negative.