• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

UML

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
PLEASE HELP

**Member**

//Member(int memberId, String name)

Initialize the memberId and name instance variables appropriately with the values passed to the constructor.
Implement the appropriate getter and setter methods.



**Room**

Room()

Generate the roomNo using the static variable roomCounter. The value of roomNo should start from 500 and should be incremented by 1 for the subsequent values. Initialize the roomNoCounter in static block.

Initialize the capacity instance variable to 4.

Implement the appropriate getter and setter methods.



**Admin**

//assignRoom(Room[] rooms, Member member)

Assign a room to the member using the below conditions:

One room can accommodate 4 members.

Allocate the first room that is empty.

Once a room is fully occupied, only then a new room should be assigned.

Update the capacity of the allocated room accordingly.

Test the functionalities using the provided Tester class.


class Room {
    //Implement your code here
   
    //Uncomment the below method after implementation before verifying
    //DO NOT MODIFY THE METHOD
    /*
    public String toString(){
       return "Room\nroomNo: "+this.roomNo+"\ncapacity: "+this.capacity;
    }
    */
}

class Member {
//Implement your code here

//Uncomment the below method after implementation before verifying
   //DO NOT MODIFY THE METHOD
   /*
   public String toString(){
       return "Member\nmemberId: "+this.memberId+"\nname: "+this.name;
   }
   */
}

class Admin {
//Implement your code here
}


class Tester {
public static void main(String args[]) {
Room room1 = new Room();
Room room2 = new Room();
Room room3 = new Room();
Room room4 = new Room();
Room room5 = new Room();

Room[] totalRooms = { room1, room2, room3, room4, room5 };

Admin admin = new Admin();

Member member1 = new Member(101, "Serena");
Member member2 = new Member(102, "Martha");
Member member3 = new Member(103, "Nia");
Member member4 = new Member(104, "Maria");
Member member5 = new Member(105, "Eva");

Member[] members = { member1, member2, member3, member4, member5 };

for (Member member : members) {
admin.assignRoom(totalRooms, member);
if(member.getRoom()!=null) {
System.out.println("Hi "+member.getName()+"! Your room number is "+member.getRoom().getRoomNo());
}
else {
System.out.println("Hi "+member.getName()+"! No room available");
}
}
}
}


 [1]: https://i.stack.imgur.com/GeAXr.jpg
1.jpeg
[Thumbnail for 1.jpeg]
 
Ranch Hand
Posts: 270
15
Android Angular Framework Spring AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is it you need help with?  Please elaborate.

It is always best to work through problems yourself.  Perhaps what you asked for help with was the "implement your code here" blocks?  If so, think about what the methods are named, and of course the (apparently) requirements list.  Consider how you would make those things happen using Java.  This really is where the fun begins.  You could create something at this point.  Along the way, remember you can always print out the states of things using code like this.   This is an example of how to dump room contents, assuming a room has been declared and has data in it.



One hint I would give: those "toString()" methods have been commented out.    takes code "out of commission".  Removing those from around the code will allow it to be executed again.

Have fun!
 
Saloon Keeper
Posts: 27852
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch, John!

Our message editor has a "Code" button that can be used to wrap special tags around pre-formatted data such as Java code, XML, SQL and the like. If you use it, it will make your code samples much easier to read.
 
reply
    Bookmark Topic Watch Topic
  • New Topic