Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The Technology is Java Practice: You are required to design and implement an app

ID: 3805914 • Letter: T

Question

The Technology is Java

Practice:

You are required to design and implement an application that keeps track of a meeting scheduling system (MSS). Your MSS keeps track of meetings schedule and which people are in what meeting in which room. The program is not required to perform scheduling, rather is is responsible for maintaining the schedule. For simplicity, assume your application is maintaining the schedule for only one day and a meeting can only fall in traditional 9-5 business hours.

Following are general guidelines:

1. Each room has a number. A room should keep track of all meetings held in it.

2. Each meeting has a name, time and room. A meeting should keep track of all people people attending the meeting.

3. A person has a first name, a last name and a phone number.

4. A person cannot be attending more than one meeting in any one-hour slot.

5. A room cannot hold more than one meeting at any one-hour slot.

Your application should be able to provide the following functionaries:

1. When the application starts, the user can specify the number of rooms available for meetings.

2. Rooms can be added and deleted by the user. (To delete a room, no meetings should be scheduled in this room).

3. Participants can be added and deleted by the user. (To delete a participant, he should not be assigned to any meeting).

4. A meeting can be added and deleted by the user. (To delete a meeting, no participant should be assigned to any meeting).

5. The user can create meetings by specifying a room number and the participants.

6. Upon request the system should display all meetings in the day.

7. Upon request the system should display all meetings in a room.

8. Upon request the system should display all meetings being attended by a single user.

9. Upon request the system should display all meetings at a specific time slot.

Explanation / Answer

Here is the code for the question. Please do rate the answer if it helped. Thank you very much.

Participant.java


public class Participant {
   private String firstName;
   private String lastName;
   private String phone;
   public Participant(String fname,String lname)
   {
       firstName=fname.toUpperCase();
       lastName=lname.toUpperCase();
   }
   public String getFirstName() {
       return firstName;
   }
     
   public String getLastName() {
       return lastName;
   }
     
   public String getPhone() {
       return phone;
   }
   public void setPhone(String phone) {
       this.phone = phone;
   }
   public String getName()
   {
       return firstName+" "+lastName;
   }
}

Room.java

import java.util.ArrayList;

public class Room {
   private int roomNo;
   private Meeting meetings[];
   private int count;
   public Room(int num)
   {
       roomNo=num;
       //9 slots for meetings starting from 9:00 hr , 10:00....5:00hr
      
       meetings=new Meeting[9];
       count=0;
   }
   public int getRoomNum()
   {
       return roomNo;
   }
   public boolean addMeeting(Meeting meeting)
   {
       int startHour=meeting.getStartHour();
       //meetings can be from 9 to 5
       if(startHour<9 || startHour>17)
           return false;
       int index=startHour-9; //caluclate what this meeting index is. 9:00 will be at index 0, 10:00 at index 1 and so on
       if(meetings[index]==null) //if no other meetings is assigned already
       {
           meetings[index]=meeting;
           count++;
           return true;
      
       }
       else
           return false;      
   }
  
   public boolean isSlotAvailable(int startHour)
   {
       if(startHour<9 || startHour>17)
           return false;
       int index=startHour-9; //caluclate what this meeting index is. 9:00 will be at index 0, 10:00 at index 1 and so on
       return (meetings[index]==null);
   }
  
   public boolean cancelMeeting(int startHour)
   {
       //meetings can be from 9 to 5
       if(startHour<9 || startHour>17)
           return false;
       int index=startHour-9; //caluclate what this meeting index is. 9:00 will be at index 0, 10:00 at index 1 and so on
       if(meetings[index]==null)
       {
           return false;
       }
       else
       {
           meetings[index]=null;
           count--;
           return true;
       }
   }
  
   public int getNumMeetings()
   {
       return count;
   }
  
   public Meeting getMeeting(int startHour)
   {
       //meetings can be from 9 to 5
       if(startHour<9 || startHour>17)
           return null;
       int index=startHour-9; //caluclate what this meeting index is. 9:00 will be at index 0, 10:00 at index 1 and so on
       return meetings[index];  
   }
  
   public boolean isAttending(Participant p)
   {
       Meeting m;
       for(int i=0;i<meetings.length;i++)
       {
           m=meetings[i];
           if(m!=null)
               if(m.hasParticipant(p))
                   return true;
              
       }
       return false;
   }
  
   public ArrayList<Meeting> getMeetings(Participant p)
   {
       ArrayList<Meeting> ms=new ArrayList<Meeting>();
       Meeting m;
       for(int i=0;i<9;i++)
       {
           m=meetings[i];
           if(m!=null && m.hasParticipant(p))
           {
               ms.add(m);
          
           }
       }
       return ms;
      
          
   }
  
   public void displayMeetings()
   {
       Meeting m;
       System.out.println("Room No.:"+roomNo);
       for(int i=0;i<9;i++)
       {
           m=meetings[i];
           if(m!=null)
               System.out.println(" "+m.getStartHour()+" Hrs: "+m.getName());
       }
   }
}

Meeting.java

import java.util.ArrayList;

public class Meeting {
   private String name;
   private Room room;
   private int startHour;
   private ArrayList<Participant> participants;
  
   public Meeting(String mname)
   {
       name=mname;
       participants=new ArrayList<Participant>();
   }
  
   public void setRoom(Room r)
   {
       room=r;
   }
  
   public Room getRoom()
   {
       return room;
   }
  
   public boolean setStartHour(int hour)
   {
       if(hour<9 || hour>17)
           return false;
       startHour=hour;
       return true;
   }
  
   public int getStartHour()
   {
      
       return startHour;
   }
   public String getName()
   {
       return name;
   }
   public void addParticipant(Participant p)
   {
       String name=p.getName();
       for(int i=0;i<participants.size();i++)
           if(participants.get(i).getName().equalsIgnoreCase(name))
               return;
       participants.add(p);
              
   }
  
   public boolean hasParticipant(Participant p)
   {
       String name=p.getName();
       for(int i=0;i<participants.size();i++)
           if(participants.get(i).getName().equalsIgnoreCase(name))
               return true;
      
       return false;
   }
  
   public int getNumParticipants()
   {
       return participants.size();
   }
  
   public Participant getParticipant(int i)
   {
       return participants.get(i);
   }
  
   public boolean removeParticipant(Participant p)
   {
       String name=p.getName();
       for(int i=0;i<participants.size();i++)
       {
           if(participants.get(i).getName().equalsIgnoreCase(name))
           {
               participants.remove(i);
               return true;
           }
       }
       return false;
   }
}

MeetingScheduler.java

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class MeetingScheduler {
  
   private static int getMeetingsCount(HashMap<Integer, Room> rooms,Participant p,int slot)
   {
       Room r;
       Meeting m;
       ArrayList<Meeting> meetings=new ArrayList<Meeting>();
  
       for(Integer k:rooms.keySet())
       {
           r=rooms.get(k);
           m=r.getMeeting(slot);
           if(m!=null && m.hasParticipant(p))
               meetings.add(m);
       }
              
       return meetings.size();
              
   }
  
   public static void main(String[] args) {
       int choice,num,slot,room;
       String fname,lname,phone,mname,ans="";
       Participant p;
       Room r;
       Meeting m;
       Scanner scanner=new Scanner(System.in);
       HashMap<Integer, Room> rooms= new HashMap<Integer,Room>();
       HashMap<String, Participant> participants=new HashMap<String ,Participant>();
       HashMap<String, Meeting> meetings=new HashMap<String,Meeting>();
       System.out.println("Enter the number of rooms:");
       num=scanner.nextInt();
       for(int i=1;i<=num;i++)
       {
           rooms.put(new Integer(i),new Room(i));
       }
      
       do
       {
          
           System.out.println("1. Add Participant");
           System.out.println("2. Delete Participant");
           System.out.println("3. Add Meeting");
           System.out.println("4. Delete Meeting");
           System.out.println("5. Add Room");
           System.out.println("6. Delete Room");
           System.out.println("7. Display all meetings ");
           System.out.println("8. Display meetings in a room");
           System.out.println("9. Display meetings by participant");
           System.out.println("10. Exit");
           System.out.println("Enter your choice: ");
           choice=scanner.nextInt();
           switch (choice)
           {
               case 1: //add participant
                   System.out.println("Enter first name: ");
                   fname=scanner.next();
                   System.out.println("Enter last name: ");
                   lname=scanner.next();
                   System.out.println("Enter phone number: ");
                   phone=scanner.next();
                   p=new Participant(fname,lname);
                   p.setPhone(phone);
                   participants.put(p.getName(),p);
                   break;
               case 2: //delete participant
                   System.out.println("Enter the details of the participant to be deleted");
                   System.out.println("Enter first name: ");
                   fname=scanner.next();
                   System.out.println("Enter last name: ");
                   lname=scanner.next();
                   p=participants.get(fname.toUpperCase()+" "+lname.toUpperCase());
                   if(p==null)
                       System.out.println("Participant "+fname+" "+lname+" does not exist!");
                   else
                   {
                       for(int i=0;i<rooms.size();i++)
                       {
                           r=rooms.get(i);
                           if(r.getNumMeetings()==0)
                               continue;
                           else
                           {
                               if(r.isAttending(p))
                               {
                                   System.out.println("Participant "+p.getName()+" is participating in 1 or more meetings and can not be deleted!");
                                  
                               }
                               else
                               {
                                   participants.remove(p.getName());
                                   System.out.println("Deleted participant successfully.");                                  
                               }
                           }
                       }
                   }
                   break;
               case 3: //add meeting
                   System.out.println("Which slot hour do you want to schedule (9-17 hrs): ");
                   slot=scanner.nextInt();
                   System.out.println("Which room? : ");
                  
                   room=scanner.nextInt();
                   System.out.println("Meeting name: ");
                   mname=scanner.next();
                              
                   if((r=rooms.get(room)).isSlotAvailable(slot))
                   {
                       m=new Meeting(mname);
                       m.setRoom(r);
                       m.setStartHour(slot);
                       r.addMeeting(m);
                       meetings.put(m.getName(), m);
                      
                       System.out.println("Wish to add participants yes/no ? : ");
                       ans=scanner.next();
                      
                      
                      
                       while(ans.equalsIgnoreCase("yes"))
                       {
                           System.out.println("First name: ");
                           fname=scanner.next();
                           System.out.println("Last name: ");
                           lname=scanner.next();
                           p=participants.get(fname.toUpperCase()+" "+lname.toUpperCase());
                           if(p==null)
                           {
                               System.out.println("No such participant!");
                               continue;
                              
                           }
                           else
                           {
                              
                               if(getMeetingsCount(rooms, p, slot)==0)
                                   m.addParticipant(p);
                               else
                               {
                                   System.out.println("Participant "+p.getName()+" has to attend another meeting at time "+slot+" hours.");
                               }
                              
                           }
                           System.out.println("Add another participant yes/no ? : ");
                           ans=scanner.next();
                          
                       }
                      
                      
                      
                       System.out.println("Meeting "+m.getName()+" added successfully");
                   }
                   else
                   {
                       System.out.println("Room No. "+room+" is not available for "+slot+" hours");
                   }
                  
                   break;
               case 4: //delete meeting
                   System.out.println("Enter meeting name: ");
                   mname=scanner.next();
                   m=meetings.get(mname);
                   if(m==null)
                   {
                       System.out.println("No such meeting !");
                   }
                   else
                   {
                       if(m.getNumParticipants()==0)
                       {
                           r=rooms.get(m.getRoom().getRoomNum());
                           r.cancelMeeting(m.getStartHour());
                           meetings.remove(m.getName());                          
                           System.out.println("Meeting "+m.getName()+" successfully deleted!");
                          
                       }
                       else
                       {
                           System.out.println("Meeting "+m.getName()+" has some participants ! Cannont delete! ");
                       }
                   }
                   break;
               case 5: //add room
                   System.out.println("Enter room no: ");
                   room=scanner.nextInt();
                   if(rooms.get(room)==null)
                   {
                       r=new Room(room);
                       rooms.put(room,r);
                       System.out.println("Room no."+room+" successfully created.");
                   }
                   else
                   {
                       System.out.println("Already room exists!");
                   }
                      
                   break;
               case 6: //delete room
                   System.out.println("Enter room no: ");
                   room=scanner.nextInt();
                   if((r=rooms.get(room))==null)
                   {
                         
                       System.out.println("Room no."+room+" does not exist!");
                   }
                   else
                   {
                       if(r.getNumMeetings()!=0)
                       {
                           System.out.println("Room "+room+" cannot be deleted as some meetings are scheduled!");                          
                       }
                       else
                       {  
                           rooms.remove(room);
                           System.out.println(" ");
                       }
                   }
                   break;
               case 7: //meetins for the day
                   System.out.println("Meetings for the day:");
                   for(Integer k:rooms.keySet())
                   {
                       r=rooms.get(k);
                       if(r.getNumMeetings()!=0)
                           r.displayMeetings();
                   }                  
                  
                   break;
               case 8: //meetings in a room
                   System.out.println("Enter room no: ");
                   room=scanner.nextInt();
                   r=rooms.get(room);
                   if(r==null)
                   {
                       System.out.println("No such room");
                   }
                   else
                   {
                       r.displayMeetings();
                   }
                     
                   break;
               case 9: //meetings by a participant
                   System.out.println("Enter participant first name: ");
                   fname=scanner.next();
                   System.out.println("Enter participant last name: ");
                   lname=scanner.next();
                   p=participants.get(fname.toUpperCase()+" "+lname.toUpperCase());
                   if(p==null)
                       System.out.println("No such participant!");
                   else
                   {
                       System.out.println("Meeting by participant : "+p.getName());  
                       ArrayList<Meeting> ms;
                       for(Integer k:rooms.keySet())
                       {
                           r=rooms.get(k);
                                  
                           if(r.getNumMeetings()!=0)
                           {
                               ms=r.getMeetings(p);
                               if(!ms.isEmpty())
                               {
                                   System.out.println("Room No: "+r.getRoomNum());
                                   for(int i=0;i<ms.size();i++)
                                       System.out.print(" "+ms.get(i).getName()+" at "+ms.get(i).getStartHour()+" hours");
                               }
                           }
                       }
                   }
                     
                   break;
               case 10:
                   break;
               default:
                   System.out.println("Invalid menu choice!");
           }
           System.out.println("_______________");
          
          
       }while(choice!=10);
      
       scanner.close();
   }

}

Output

Enter the number of rooms:
3
1. Add Participant
2. Delete Participant
3. Add Meeting
4. Delete Meeting
5. Add Room
6. Delete Room
7. Display all meetings
8. Display meetings in a room
9. Display meetings by participant
10. Exit
Enter your choice:
1
Enter first name:
john
Enter last name:
smith
Enter phone number:
656757
_______________
1. Add Participant
2. Delete Participant
3. Add Meeting
4. Delete Meeting
5. Add Room
6. Delete Room
7. Display all meetings
8. Display meetings in a room
9. Display meetings by participant
10. Exit
Enter your choice:
3
Which slot hour do you want to schedule (9-17 hrs):
9
Which room? :
2
Meeting name:
Design
Wish to add participants yes/no ? :
no
Meeting Design added successfully
_______________
1. Add Participant
2. Delete Participant
3. Add Meeting
4. Delete Meeting
5. Add Room
6. Delete Room
7. Display all meetings
8. Display meetings in a room
9. Display meetings by participant
10. Exit
Enter your choice:
7
Meetings for the day:
Room No.:2
   9 Hrs: Design
_______________
1. Add Participant
2. Delete Participant
3. Add Meeting
4. Delete Meeting
5. Add Room
6. Delete Room
7. Display all meetings
8. Display meetings in a room
9. Display meetings by participant
10. Exit
Enter your choice:
1
Enter first name:
alice
Enter last name:
h
Enter phone number:
456887
_______________
1. Add Participant
2. Delete Participant
3. Add Meeting
4. Delete Meeting
5. Add Room
6. Delete Room
7. Display all meetings
8. Display meetings in a room
9. Display meetings by participant
10. Exit
Enter your choice:
3
Which slot hour do you want to schedule (9-17 hrs):
10
Which room? :
1
Meeting name:
project1
Wish to add participants yes/no ? :
yes
First name:
alice
Last name:
h
Add another participant yes/no ? :
yes
First name:
john
Last name:
smith
Add another participant yes/no ? :
no
Meeting project1 added successfully
_______________
1. Add Participant
2. Delete Participant
3. Add Meeting
4. Delete Meeting
5. Add Room
6. Delete Room
7. Display all meetings
8. Display meetings in a room
9. Display meetings by participant
10. Exit
Enter your choice:
7
Meetings for the day:
Room No.:1
   10 Hrs: project1
Room No.:2
   9 Hrs: Design
_______________
1. Add Participant
2. Delete Participant
3. Add Meeting
4. Delete Meeting
5. Add Room
6. Delete Room
7. Display all meetings
8. Display meetings in a room
9. Display meetings by participant
10. Exit
Enter your choice:
3
Which slot hour do you want to schedule (9-17 hrs):
10
Which room? :
1
Meeting name:
testingprgress
Room No. 1 is not available for 10 hours
_______________
1. Add Participant
2. Delete Participant
3. Add Meeting
4. Delete Meeting
5. Add Room
6. Delete Room
7. Display all meetings
8. Display meetings in a room
9. Display meetings by participant
10. Exit
Enter your choice:
3
Which slot hour do you want to schedule (9-17 hrs):
10
Which room? :
2
Meeting name:
testing
Wish to add participants yes/no ? :
yes
First name:
john
Last name:
smith
Participant JOHN SMITH has to attend another meeting at time 10 hours.
Add another participant yes/no ? :
no
Meeting testing added successfully
_______________
1. Add Participant
2. Delete Participant
3. Add Meeting
4. Delete Meeting
5. Add Room
6. Delete Room
7. Display all meetings
8. Display meetings in a room
9. Display meetings by participant
10. Exit
Enter your choice:
7
Meetings for the day:
Room No.:1
   10 Hrs: project1
Room No.:2
   9 Hrs: Design
   10 Hrs: testing
_______________
1. Add Participant
2. Delete Participant
3. Add Meeting
4. Delete Meeting
5. Add Room
6. Delete Room
7. Display all meetings
8. Display meetings in a room
9. Display meetings by participant
10. Exit
Enter your choice:
4
Enter meeting name:
testing
Meeting testing successfully deleted!
_______________
1. Add Participant
2. Delete Participant
3. Add Meeting
4. Delete Meeting
5. Add Room
6. Delete Room
7. Display all meetings
8. Display meetings in a room
9. Display meetings by participant
10. Exit
Enter your choice:
7
Meetings for the day:
Room No.:1
   10 Hrs: project1
Room No.:2
   9 Hrs: Design
_______________
1. Add Participant
2. Delete Participant
3. Add Meeting
4. Delete Meeting
5. Add Room
6. Delete Room
7. Display all meetings
8. Display meetings in a room
9. Display meetings by participant
10. Exit
Enter your choice:
6
Enter room no:
2
Room 2 cannot be deleted as some meetings are scheduled!
_______________
1. Add Participant
2. Delete Participant
3. Add Meeting
4. Delete Meeting
5. Add Room
6. Delete Room
7. Display all meetings
8. Display meetings in a room
9. Display meetings by participant
10. Exit
Enter your choice:
6
Enter room no:
3

_______________
1. Add Participant
2. Delete Participant
3. Add Meeting
4. Delete Meeting
5. Add Room
6. Delete Room
7. Display all meetings
8. Display meetings in a room
9. Display meetings by participant
10. Exit
Enter your choice:
7
Meetings for the day:
Room No.:1
   10 Hrs: project1
Room No.:2
   9 Hrs: Design
_______________
1. Add Participant
2. Delete Participant
3. Add Meeting
4. Delete Meeting
5. Add Room
6. Delete Room
7. Display all meetings
8. Display meetings in a room
9. Display meetings by participant
10. Exit
Enter your choice:
9
Enter participant first name:
alice
Enter participant last name:
h
Meeting by participant : ALICE H
Room No: 1
project1, _______________
1. Add Participant
2. Delete Participant
3. Add Meeting
4. Delete Meeting
5. Add Room
6. Delete Room
7. Display all meetings
8. Display meetings in a room
9. Display meetings by participant
10. Exit
Enter your choice:
8
Enter room no:
2
Room No.:2
   9 Hrs: Design
_______________
1. Add Participant
2. Delete Participant
3. Add Meeting
4. Delete Meeting
5. Add Room
6. Delete Room
7. Display all meetings
8. Display meetings in a room
9. Display meetings by participant
10. Exit
Enter your choice:
5
Enter room no:
3
Room no.3 successfully created.
_______________
1. Add Participant
2. Delete Participant
3. Add Meeting
4. Delete Meeting
5. Add Room
6. Delete Room
7. Display all meetings
8. Display meetings in a room
9. Display meetings by participant
10. Exit
Enter your choice:
7
Meetings for the day:
Room No.:1
   10 Hrs: project1
Room No.:2
   9 Hrs: Design
_______________
1. Add Participant
2. Delete Participant
3. Add Meeting
4. Delete Meeting
5. Add Room
6. Delete Room
7. Display all meetings
8. Display meetings in a room
9. Display meetings by participant
10. Exit
Enter your choice:
10
_______________

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote