You are on page 1of 2

class Booking{

private String room;


private String name;
public Booking(String rm, String nm) {
this.room = rm;
this.name = nm;
}
public String getRoom() {
return this.room;
}
public String getName() {
return this.name;
}
}
class TimeTable {
private Booking[][] times;
public TimeTable(int days, int periods) {
times = new Booking[days][periods];
}
public boolean makeBooking(int day, int period, Booking bkg) {
if ((0 < day && day <= times.length)&&(0 < period && period <=
times[1].length)){
times[day-1][period-1] = bkg;
return true;
}
else return false;
}
public boolean isFree(int day, int period){
return (0 < day && day <= times.length)&&(0 < period && period <=
times[1].length)&&(times[day][period] == null);
}
public boolean cancelBooking(int day, int period) {
if ((0 < day && day <= times.length)&&(0 < period && period <=
times[1].length)&&(times[day][period] != null)){
times[day][period] = null;
return true;
}
else return false;
}
public Booking getBooking(int day, int period) {
if ((0 < day && day <= times.length)&&(0 < period && period <=
times[1].length)){
return times[day][period];
}
else return null;
}
public int numberOfDays() {
return times.length;
}
public int numberOfPeriods() {
return times[1].length;
}
public void printTable() {
System.out.println("Day Period Booking");
System.out.println("________________________");
int count = 0;
for (int i = 0; i < times.length; i++) {
for (int j = 0; j < times[1].length; j++) {
if (times[i][j] != null) {
count ++;
Booking book = times[i][j];
System.out.println(i + " |" + j + " |" +
book.getName() + " " + book.getRoom());
}
}
}
int slots = times.length * times[1].length;
System.out.println((slots - count)+ " unbooked slots");
}

}
public class MNWS {
public static void main(String[] args) {
TimeTable tTable = new TimeTable(5,7);
/* Erase this comment block once info. is gotten... I'm creating five
objects with dummy names such as "Shoe"...replace such names with realistic

ones like "Ade"...I have also chosen random slots, replace them too
this is done to ensure diversity and not attract any suspicion
...regards
*/
tTable.makeBooking(1, 5, new Booking("Kilamuwaye", "room9"));
tTable.makeBooking(2, 2, new Booking("HackMan", "room2"));
tTable.makeBooking(5, 1, new Booking("Drake", "room8"));
tTable.makeBooking(4, 4, new Booking("Woody", "room4"));
tTable.makeBooking(3, 7, new Booking("Axis", "room6"));
tTable.printTable();
}
}

You might also like