Download as pdf or txt
Download as pdf or txt
You are on page 1of 43

UNIVERSITI TEKNOLOGI MARA

CAWANGAN PAHANG, KAMPUS RAUB


27600 Raub, Pahang

FACULTY OF COMPUTER AND MATHEMATICAL SCIENCES


Fakulti Sains Komputer dan Matematik

OBJECT ORIENTED
PROGRAMMING
(CSC238)

MINI PROJECT – FINAL REPORT

Team Members:

Class/Group: CS1103A

Student ID Name
2018209898 Nur Najihah Binti Muhamad Farid
2018205058 Nur Sabrina Batrisyia Binti Ahmad Azua
2018214482 Aliya Syaffaa binti Jamaludin

Date Submitted: 2 9 1 2 2 0 1 9
Table of Contents
ACKNOWLEDGEMENT 2

1. EXECUTIVE SUMMARY 3

2. OBJECT DESIGN 4

3. SOURCE CODES 5-3

3.1. Class Definition of Hotel 5

3.2. Class Definition of Hall 6-7

3.3. Class Definition of Room 8-9

3.4. Class Definition of Food 10-11

3.5. Class Application of Hotel 12-30

4. DETAILS OF INPUT AND OUTPUT FILE 31-32

5. SAMPLE INPUT/OUTPUT(SNAPSHOT) 33-37

6. REFERENCES 38

1
Acknowledgement
We would like to convey our deepest gratitude to those who helped us to complete this
project. A special appreciation to Sir Roslan Bin Sadjirin, our beloved lecturer whose
contribution in stimulating suggestions, encouragement and guidance has helped us to
complete our project especially in writing this report.

Furthermore, many thanks go to the head of the project, Nur Najihah Binti Muhamad
Farid, who has invested her time and effort in guiding this group to achieve the program’s
objectives. Last but not least, we would like to appreciate the comment and advices given by
classmates and lecturer particularly in our project’s presentation that has improve our
presentation skills and program’s output.

2
1. Executive Summary

To summarize, our group decided to create a top-notch Hotel Booking System that
helps the staffs to make room/hall bookings for the customers because in this era of
technology, everything is on our fingertips. Our system provided a menu which consists of
the function add, update, searching and exit. The add function is to allow the staffs to enter
the details of the customers, check-in and check-out date, varieties of room/hall type to be
chosen from and customer’s choice of food and beverages. Meanwhile for the searching
function, it allows the staffs to search about the customer’s personal information and
booking details just by inserting customer’s ID number. Next, update function is to allow
changes on customer’s personal details like phone number to be made and exit function is
to exit the Hotel Booking System.
In conclusion, our well programmed Hotel Booking System will make the life of the
hotel staffs and guest easier so that none of the staff will manage and inputting the bookings
manually thus allows the staffs to escape the back office and focus more on interacting with
the guests physically.

3
2. Object Design

4
3. Source Codes
1. Class Definition of Hotel

public abstract class Hotel


{
protected String bookType;
protected double price;
protected String payMethod;
protected String custName;
protected String icNo;
protected int age;
protected String phoneNo;
public Hotel(String bookType, String custName, String
icNo, int age, String phoneNo, double price, String pm)
{
this.setBookType(bookType);
this.setCustName(custName);
this.setICNo(icNo);
this.setAge(age);
this.setPhoneNo(phoneNo);
this.setPrice(price);
this.setPayMethod(pm);
}

public void setBookType(String bt) { this.bookType = bt;


}
public void setPrice(double p) { this.price = p; }
public void setPayMethod(String pm) { this.payMethod =
pm; }
public void setCustName(String cn) { this.custName = cn;
}
public void setICNo(String ic) { this.icNo = ic; }
public void setAge(int a) { this.age = a; }
public void setPhoneNo(String pn) { this.phoneNo = pn; }

public String getBookType() { return this.bookType; }


public String getCustName() { return this.custName; }
public String getICNo() { return this.icNo; }
public String getPhoneNo() { return this.phoneNo; }
public int getAge() { return this.age; }
public double getPrice() { return this.price; }
public String getPayMethod() { return this.payMethod; }

public abstract double calcFee();

public abstract String toString();


}

5
2. Class Definition of Hall

import java.text.DecimalFormat;
public class Hall extends Hotel
{
private String hallType;
private double reserveHour;
private String date;
private String time;
DecimalFormat df= new DecimalFormat("#,###.00");

//normal constructor
public Hall(String bookType, String custName, String
icNo, int age, String phoneNo, double p, String pm,
String hallType, double reserveHour, String date, String
time)
{
super(bookType, custName, icNo, age, phoneNo, p,pm);
this.setHallType(hallType);
this.setReserveHour(reserveHour);
this.setDate(date);
this.setTime(time);
}

//mutator
public void setHallType(String hallType){this.hallType =
hallType;}
public void setReserveHour(double
reserveHour){this.reserveHour = reserveHour;}
public void setDate(String d){this.date = d;}
public void setTime(String t){this.time = t;}

//accessor
public String getHallType(){return this.hallType;}
public double getReserveHour(){return this.reserveHour;}
public String getDate(){return this.date;}
public String getTime(){return this.time;}

//proccessor
public double calcFee(){
return super.getPrice() * this.getReserveHour();
}

//output toString
public String toString(){
return
"===================================================
=====================================" +
"\n\t\t\t\tCUSTOMER DETAILS" +

"\n=================================================
=======================================" +
"\nName : " +
super.getCustName() +

6
"\t\tIdentity Card Number : " +
super.getICNo() +
"\nAge : " +
super.getAge() +
"\t\t\tPhone Number : " +
super.getPhoneNo() +
"\nHall Type : " +
this.getHallType() +
"\t\tDate : " +
this.getDate() +
"\nReserved Hours : " +
this.getReserveHour() +
"\t\t\tStart Time : " +
this.getTime() +
"\nTotal Fee : RM" +
df.format(this.calcFee());
}
}

7
3. Class Definition of Room
import java.text.DecimalFormat;
public class Room extends Hotel
{
private String room;
private String roomNo;
private int night;
private String checkIn; //DD-MM-YY
private String checkOut; //DD-MM-YY
DecimalFormat df= new DecimalFormat("#,###.00");

public Room(String bookType, String custName, String


icNo, int age, String phoneNo, double p, String pm,
String room, String roomNo,int night, String ci, String
co)
{
super(bookType, custName, icNo, age, phoneNo, p,pm);
this.setRoom(room);
this.setRoomNo(roomNo);
this.setNight(night);
this.setCheckIn(ci);
this.setCheckOut(co);
}

public void setRoom(String r) { this.room = r; }


public void setRoomNo(String rn) { this.roomNo = rn; }
public void setNight(int n) { this.night = n; }
public void setCheckIn(String ci) { this.checkIn = ci; }
public void setCheckOut(String co) { this.checkOut = co;
}

public String getRoom() { return this.room; }


public String getRoomNo() { return this.roomNo; }
public int getNight() { return this.night; }
public String getCheckIn() { return this.checkIn; }
public String getCheckOut() { return this.checkOut; }

public double calcFee()


{
double fee = 0.00;

fee = super.getPrice() * this.getNight();

return fee;
}

8
public String toString()
{
return
"===================================================
===================================" +
"\n\t\t\t\tCUSTOMER DETAILS" +

"\n=================================================
=====================================" +
"\nName : " + super.getCustName()
+ "\nIdentity Card Number : " + super.getICNo() +
"\nAge : " + super.getAge() +
"\nPhone Number : " + super.getPhoneNo()
+ "\nRoom Type : " + this.getRoom() +
"\nRoom Number : " + this.getRoomNo() +
"\nCheck-in Date : " + this.getCheckIn()+
"\tCheck-out Date : " + this.getCheckOut()+
"\nDuration : " + this.getNight() +
" night(s)" +
"\nPayment Method : " +
super.getPayMethod() +
"\nPrice per night : RM" +
df.format(super.getPrice()) +
"\nGrand Total : RM" +
df.format(this.calcFee());

}
}

9
4. Class Definition of Food
import java.text.DecimalFormat;

public class Food extends Room


{
private String food;
private String drink;
private int foodQty;
private int drinkQty;
private double priceF;
private double priceD;
DecimalFormat df= new DecimalFormat("#,###.00");

//normal constructor
public Food(String bookType, String custName, String
icNo, int age, String phoneNo, double p, String pm,
String room, String roomNo,int night, String ci, String
co, String food,String drink, int foodQty, int drinkQty,
double pf, double pd){
super(bookType, custName,icNo,age,phoneNo,p, pm,
room, roomNo, night, ci, co);
this.setFood(food);
this.setDrink(drink);
this.setFoodQty(foodQty);
this.setDrinkQty(drinkQty);
this.setPriceF(pf);
this.setPriceD(pd);
}

//retriever method
public String getFood(){return this.food;}
public String getDrink(){return this.drink;}
public int getFoodQty(){return this.foodQty;}
public int getDrinkQty(){return this.drinkQty;}
public double getPriceF() {return this.priceF; }
public double getPriceD() {return this.priceD; }

//mutator method
public void setFood(String f ){this.food=f;}
public void setDrink(String d) {this.drink=d;}
public void setFoodQty(int fq) {this.foodQty=fq;}
public void setDrinkQty(int dq) {this.drinkQty=dq;}
public void setPriceF(double pf) { this.priceF = pf; }
public void setPriceD(double pd) { this.priceD = pd; }
//processing method

public double calcFee(){


return (this.getPriceF()*this.getFoodQty()) +
(this.getPriceD()*this.getDrinkQty());
}

public String toString()


{
return
"===================================================

10
===================================" +
"\n\t\t\t\tCUSTOMER DETAILS" +

"\n=================================================
=====================================" +
"\nName : " +
super.getCustName() +
"\nIdentity Card Number : " + super.getICNo() +
"\nAge : " + super.getAge() +
"\nPhone Number : " + super.getPhoneNo()
+ "\nRoom Type : " + this.getRoom() +
"\nRoom Number : " + this.getRoomNo() +
"\nCheck-in Date : " + this.getCheckIn() +
"\nCheck-out Date : " + this.getCheckOut()
+ "\nDuration : " + this.getNight() +
" night(s)" +
"\nRoom Fee : RM" +
df.format(super.calcFee()) +
"\nFood : " + this.getFood() +
"\nQuantity : " + this.getFoodQty() +
"\nBeverage : " + this.getDrink() +
"\nQuantity : " + this.getDrinkQty()
+ "\nPayment Method : " +
super.getPayMethod() +
"\nFood & Beverage Fee : RM" +
df.format(this.calcFee()) +
"\nGrand Total : RM" +
df.format(this.calcFee() + super.calcFee()) ;
}

11
5. Class Application of Hotel
import java.util.*;
import java.io.*;
import java.text.*;
import java.util.concurrent.TimeUnit;
import javax.swing.*;

public class HotelApp


{
public static Scanner in = new Scanner(System.in);
public static Scanner inline = new Scanner(System.in);
public static JFrame f = new JFrame();
public static ImageIcon icon = new
ImageIcon("like2.png");
public static int index = 0;
public static DecimalFormat df = new
DecimalFormat("####0.00");

public static void addCust(Hotel[] h) throws Exception{

System.out.print("\f");
System.out.print("\n--------------------------------
-------------------------------------------");
System.out.print("\n
CUSTOMER DETAILS ");
System.out.print("\n--------------------------------
-------------------------------------------");
System.out.print("\n|ENTER CUSTOMER'S NAME
--> ");
String name = inline.nextLine();
System.out.print("\n|ENTER CUSTOMER'S NRIC
--> ");
String icno = inline.nextLine();
System.out.print("\n|ENTER CUSTOMER'S AGE
--> ");
int age = in.nextInt();
System.out.print("\n|ENTER CUSTOMER'S PHONE NUMBER
--> ");
String pno = inline.nextLine();
System.out.print("\n|CUSTOMER'S BOOKING TYPE");
System.out.print("\n| [ R ] - ROOM |\n| [ H ] - HALL
|");
System.out.print("\nCHOOSE ONE --> ");
String type = in.next();
boolean checkAvail = false; //false - not avail,
true - avail
double price=0.00;
double priceF=0.00;
double priceD=0.00;
String fmenu="";
String bmenu="";
String room="";
int qtyf=0;
int qtyb=0;
String payM="Cash";

12
Set<String> hsBlk = new HashSet<String>();
Set<String> hsDate = new HashSet<String>();
Set<String> hsHallDay = new HashSet<String>();
Set<String> hsHallHour = new HashSet<String>();
Set<String> hsHall = new HashSet<String>();

for(int i=0; i<h.length; i++){


if(h[i] instanceof Room){
hsBlk.add(((Room)h[i]).getRoomNo());
hsDate.add(((Room)h[i]).getCheckIn());
}
else if(h[i] instanceof Hall){
hsHall.add(((Hall)h[i]).getHallType());
hsHallHour.add(((Hall)h[i]).getTime());
hsHallDay.add(((Hall)h[i]).getDate());
}
}

try{
if(type.equalsIgnoreCase("r")){
while(!checkAvail){
String bt = "Room";
type="Room";
System.out.print("\f");

System.out.print("\n~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~");
System.out.print("\n| ROOM
DETAILS |");

System.out.print("\n~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~");
System.out.print("\nROOM TYPES");
System.out.print("\n----------");
System.out.print("\n[ DR ] -
DELUXE ROOM");
System.out.print("\n[ ER ] -
EXECUTIVE ROOM");
System.out.print("\n[ GS ] - GRAND
EXECUTIVE SUITE");
System.out.print("\n[ PS ] -
PRESIDENTIAL SUITE");
System.out.print("\n\n|CHOOSE ROOM
TYPE -->
");
String r = inline.nextLine();
System.out.print("\nROOM NUMBER");
System.out.print("\n-----------");
if(r.equalsIgnoreCase("dr")){

System.out.print("\n- 2 0 1
-");
System.out.print("\n- 2 0 2
-");
System.out.print("\n- 2 0 3
-");

13
System.out.print("\n- 2 0 4
-");

System.out.print("\n- 2 0 5
-");
price = 668.00;
room = "Deluxe Room";
}
else if(r.equalsIgnoreCase("er")){

System.out.print("\n- 3 0 1
-");
System.out.print("\n- 3 0 2
-");
System.out.print("\n- 3 0 3
-");
System.out.print("\n- 3 0 4
-");
System.out.print("\n- 3 0 5
-");
price=792.00;
room = "Executive Room";
}
else if(r.equalsIgnoreCase("gs")){

System.out.print("\n- 4 0 1
-");
System.out.print("\n- 4 0 2
-");
System.out.print("\n- 4 0 3
-");
System.out.print("\n- 4 0 4
-");
price = 998.00;
room = "Grand Executive
Suite";
}
else if(r.equalsIgnoreCase("ps")){

System.out.print("\n- 5 0 1
-");
System.out.print("\n- 5 0 2
-");
System.out.print("\n- 5 0 3
-");
price = 5324.00;
room = "Presidential Suite";
}

System.out.print("\n\n|CHOOSE ROOM
NUMBER --
> ");
String roomno = inline.nextLine();

System.out.print("\nBOOKING
DATES");

14
System.out.print("\n-------------
");
System.out.print("\n|ENTER CHECK IN
DATE (DD/MM/YYYY) -->
");
String ci = inline.nextLine();
System.out.print("\n|ENTER CHECK
OUT DATE (DD/MM/YYYY) --
> ");
String co = inline.nextLine();
SimpleDateFormat sdf = new
SimpleDateFormat("DD/mm/yyyy",
Locale.ENGLISH);
Date firstDate = sdf.parse(ci);
Date secondDate = sdf.parse(co);

long diffInMillies =
Math.abs(secondDate.getTime() -
firstDate.getTime());

int night = (int)


TimeUnit.MILLISECONDS.toDays(diffIn
Millies);
System.out.print("\n---------------
-------------------");
System.out.print("\n| KEY |
PAYMENT METHOD |");
System.out.print("\n---------------
-------------------");
System.out.print("\n[ C ] -
CASH");
System.out.print("\n[ CC ] -
CREDIT/DEBIT CARD");
System.out.print("\n\nENTER PAYMENT
METHOD --
> ");
String keyp = inline.nextLine();
if(keyp.equalsIgnoreCase("C")){
payM = "Cash";
}
else
if(keyp.equalsIgnoreCase("CC")){
payM = "Credit/Debit Card";
}

if(hsBlk.contains(roomno) &&
hsDate.contains(ci)){
JOptionPane.showMessageDialog(
f, "Room is not available!",
"Booking",
JOptionPane.ERROR_MESSAGE);
checkAvail = false;
}
else{
hsBlk.add(roomno);
hsDate.add(ci);

15
checkAvail = true;

int decsn =
JOptionPane.showOptionDialog(n
ull, "Total Fee is RM" +
df.format((price*night)) +
"\nConfirm?",
"Booking",JOptionPane.YES_NO_O
PTION,
JOptionPane.QUESTION_MESSAGE,
null, null, null);

checkAvail = true;

JOptionPane.showMessageDialog(
null, "Confirmed!", "Room",
JOptionPane.INFORMATION_MESSAG
E, icon);
int nakmakan =
JOptionPane.showOptionDialog(n
ull, "Do you want to order
food?", "Food Delivery",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null, null, null);
if(nakmakan ==
JOptionPane.YES_NO_OPTION){
System.out.print("\f");

System.out.print("\n
KEY\t FOOD
\t\t\t PRICE (RM)");
System.out.print("\n----
-\t-------------------
\t\t----------");
System.out.print("\n[ F1
]\tNASI LEMAK
\t\t 15.00");
System.out.print("\n[ F2
]\tBUTTER MILK
PANCAKE\t\t 30.00");
System.out.print("\n[ F3
]\tFISH & CHIPS
\t\t 45.00");
System.out.print("\n[ F4
]\tCHICKEN KATSU
\t\t 45.00");
System.out.print("\nENTE
R MENU
--> ");
String food =
inline.nextLine();
System.out.print("\nENTE
R QUANTITY
--> ");
qtyf = in.nextInt();

16
System.out.print("\n
KEY\t BEVERAGES
\t\tPRICE (RM)");
System.out.print("\n----
--\t-------------------
\t\t----------");
System.out.print("\n[ B1
]\tCOCA COLA
\t\t 10.00");
System.out.print("\n[ B2
]\tSPRITE
\t\t 10.00");
System.out.print("\n[ B3
]\tMANGO JUICE
\t\t 20.00");
System.out.print("\n[ B4
]\tAPPLE JUICE
\t\t 20.00");
System.out.print("\nENTE
R MENU
--> ");
String drink =
inline.nextLine();
System.out.print("\n\t\t
ENTER QUANTITY
--> ");
qtyb = in.nextInt();

if(food.equalsIgnoreCase
("f1")){
priceF = 15.00;

fmenu = "Nasi
Lemak";
}

else
if(food.equalsIgnoreCase
("f2")){
priceF=30.00;

fmenu = "Butter
Milk Pancake";
}

else
if(food.equalsIgnoreCase
("f3")){
priceF = 45.00;

fmenu = "Fish &


Chips";
}

17
else
if(food.equalsIgnoreCase
("f4")){
priceF = 45.00;

fmenu = "Chicken
Katsu";
}
if(drink.equalsIgnoreCas
e("b1")){
priceD = 10.00;

bmenu = "Coca
Cola";
}

else
if(drink.equalsIgnoreCas
e("b2")){
priceD=10.00;
bmenu = "Sprite";
}

else
if(drink.equalsIgnoreCas
e("b3")){
priceD = 20.00;

bmenu = "Mango
Juice";
}

else
if(drink.equalsIgnoreCas
e("b4")){
priceD = 20.00;

bmenu = "Apple
Juice";
}

double totp =
(priceF*qtyf) + (priceD
* qtyb);

int cfmmakan =
JOptionPane.showOptionDi
alog(null, "Total Fee is
RM" + df.format(totp) +
"\nConfirm?", "Food &
Beverage",
JOptionPane.YES_NO_OPTIO
N,
JOptionPane.QUESTION_MES
SAGE, null, null, null);

18
h[index++] = new
Food(bt,name,icno,age,pn
o,price,payM,room,roomno
,night,ci,co,fmenu,bmenu
,qtyf,qtyb,priceF,priceD
);
break;
}
else{

h[index++] = new
Room(bt,name,icno,age,pn
o,price,payM,room,roomno
,night,ci,co);
break;
}
}
}
}
else if(type.equalsIgnoreCase("h")){
String hallt = "";
String bt = "Hall";
while(!checkAvail){
System.out.print("\f");

System.out.print("\n~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~");
System.out.print("\n| HALL
DETAILS |");

System.out.print("\n~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~");
System.out.print("\nHALL TYPES");
System.out.print("\n----------");
System.out.print("\n[ CH ] - CONFERENCE
HALL");
System.out.print("\n[ BR ] - BALLROOM");
System.out.print("\n[ GH ] – GARDEN
HALL");
System.out.print("\n[ EH ] - EXHIBITION
HALL");
System.out.print("\n[ DH ] - DINING
HALL");
System.out.print("\n\nENTER HALL TYPE
--> ");
String keyh = inline.nextLine();
System.out.print("\nBOOKING DATES");
System.out.print("\n-------------");

System.out.print("\n\nENTER RESERVATION
DATE (DD/MM/YYYY) --> ");
String date = inline.nextLine();

System.out.print("\nBOOKING TIME (24


HRS)");

19
System.out.print("\n---------------------
");
System.out.print("\nFROM (HH:MM)
--> ");
String strtHour = inline.nextLine();

System.out.print("\nUNTIL (HH:MM)
--> ");
String endHour = inline.nextLine();
SimpleDateFormat format = new
SimpleDateFormat("HH:mm");
Date date1 = format.parse(strtHour);
Date date2 = format.parse(endHour);

double hour = date2.getTime() -


date1.getTime();

hour = hour/3600000;

if(keyh.equalsIgnoreCase("CH")){
if(hour >= 1 && hour <= 5)
price = 130.00;
else if(hour > 5 && hour <=8)
price = 150.00;
else
price = 200.00;
hallt = "Conference Hall";
}
else if(keyh.equalsIgnoreCase("br")){
if(hour >= 1 && hour <= 5)
price = 200.00;
else if(hour > 5 && hour <=8)
price = 220.00;
else
price = 250.00;
hallt = "Ballroom";
}
else if(keyh.equalsIgnoreCase("gh")){
if(hour >= 1 && hour <= 5)
price = 400.00;
else if(hour > 5 && hour <=8)
price = 450.00;
else
price = 500.00;
hallt = "Garden Hall";
}
else if(keyh.equalsIgnoreCase("eh")){
if(hour >= 1 && hour <= 5)
price = 120.00;
else if(hour > 5 && hour <=8)
price = 150.00;
else
price= 200.00;
hallt = "Exhibition Hall";
}

20
else if(keyh.equalsIgnoreCase("dh")){
if(hour >= 1 && hour <= 5)
price = 200.00;
else if(hour > 5 && hour <=8)
price = 210.00;
else
price = 240.00;
hallt = "Dining Hall";
}

if(hsHallDay.contains(date) &&
hsHall.contains(hallt) &&
hsHallHour.contains(strtHour))
{

JOptionPane.showMessageDialog(f,
"Hall is not available!",
"Booking",
JOptionPane.ERROR_MESSAGE);

System.out.println("Hall is not
available!");
System.out.print("\nPress any key
to continue...");
String pop = inline.nextLine();
checkAvail = false;
}
else{
hsHallDay.add(date);
hsHallHour.add(strtHour);
checkAvail = true;

hsHall.add(hallt);

System.out.print("\n---------------
-------------------");
System.out.print("\n| KEY |
PAYMENT METHOD |");
System.out.print("\n---------------
-------------------");
System.out.print("\n[ C ] -
CASH");
System.out.print("\n[ CC ] -
CREDIT/DEBIT CARD");
System.out.print("\n\nENTER PAYMENT
METHOD --
> ");
String keyp = inline.nextLine();
if(keyp.equalsIgnoreCase("C")){
payM = "Cash";
}
else
if(keyp.equalsIgnoreCase("CC")){
payM = "Credit/Debit Card";
}

21
int decsn =
JOptionPane.showOptionDialog(null,
"Total Fee is RM" +
df.format((price*hour)) +
"\nConfirm?", "Booking",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE, null,
null, null);
if(decsn ==
JOptionPane.YES_OPTION){
h[index++] = new
Hall(bt,name,icno,age,pno,pric
e,payM,hallt,hour,date,strtHou
r);
break;
}
}
}
}

}catch(Exception e1) {
System.err.println(e1.getMessage()); }

22
public static void searchCust(Hotel[] h) throws Exception{
try{
System.out.print("\f");
System.out.print("SEARCH CUSTOMER");
System.out.print("\n---------------");
System.out.print("\nENTER CUSTOMER'S NRIC =>
");
String key = inline.nextLine();
int a=0;
boolean found=false;

for(int i=0; i<h.length; i++){


if(h[i].getICNo().equals(key)){
if(h[i] instanceof Food){
System.out.print("\f");
System.out.println(h[i].toStri
ng());
found = true;
break;
}
else if(h[i] instanceof Hall){
System.out.print("\f");
System.out.println(h[i].toStri
ng());
found = true;
break;
}
else if(h[i] instanceof Room){

System.out.print("\f");
System.out.println(h[i].toStri
ng());
found = true;
break;
}
}
}

if(found == false){
System.out.println("DATA NOT FOUND IN
DATABASE !!!");
}

System.out.print("\nPress any key to continue


> ");
String pop = inline.nextLine();
}
catch(Exception e) {
System.err.println(e.getMessage()); }
}

23
public static void updateCust(Hotel[] h) throws Exception{
BufferedReader br = new BufferedReader(new
FileReader(new File("List of Customers.txt")));
int index = 0;
try{
System.out.print("\f");
System.out.print("\nUPDATING DATA");
System.out.print("\n-------------");
System.out.print("\nEnter Customer NRIC
> ");
String pk = inline.nextLine();
String nwci = "";
String nwco = "";
for(int i=0; i<h.length; i++){
if(h[i].getICNo().equals(pk)){
if(h[i] instanceof Room){

System.out.print("\nEnter New
Check-in Date > ");
nwci = inline.nextLine();

System.out.print("\nEnter New
Check-out Date > ");
nwco = inline.nextLine();
break;
}
else if(h[i] instanceof Food){

System.out.print("\nEnter New
Check-in Date > ");
nwci = inline.nextLine();

System.out.print("\nEnter New
Check-out Date > ");
nwco = inline.nextLine();
break;
}
else if(h[i] instanceof Hall){

System.out.print("\nEnter New
Reservation Date > ");
nwci = inline.nextLine();
break;
}
}
}
String str = br.readLine();
while(str!= null){
StringTokenizer st = new
StringTokenizer(str, ",");
String name = st.nextToken();
String ic = st.nextToken();
int yr =
Integer.parseInt(st.nextToken());
String no = st.nextToken();
String bt = st.nextToken();

24
if(bt.equalsIgnoreCase("Room")){
String rt = st.nextToken();
String rn = st.nextToken();
double perone =
Double.parseDouble(st.nextToken());
String start = st.nextToken();
String end = st.nextToken();
int dur =
Integer.parseInt(st.nextToken());
String pm = st.nextToken();
if(ic.equals(pk)){
start = nwci;
end = nwco;

SimpleDateFormat sdf = new


SimpleDateFormat("DD/mm/yyyy",
Locale.ENGLISH);

Date firstDate =
sdf.parse(start);

Date secondDate =
sdf.parse(end);

long diffInMillies =
Math.abs(secondDate.getTime()
- firstDate.getTime());

dur = (int)
TimeUnit.MILLISECONDS.toDays(d
iffInMillies);
}
if(st.hasMoreTokens()){
String f = st.nextToken();
int qf =
Integer.parseInt(st.nextToken(
));
double prcef =
Double.parseDouble(st.nextToke
n());
String d = st.nextToken();
int qd =
Integer.parseInt(st.nextToken(
));
double prced =
Double.parseDouble(st.nextToke
n());
h[index] = new
Food(bt,name,ic,yr,no,perone,p
m,rt,rn,dur,start,end,f,d,qf,q
d,prcef,prced);
}

25
else

h[index] = new
Room(bt,name,ic,yr,no,perone,p
m,rt,rn,dur,start,end);
}
else if(bt.equalsIgnoreCase("Hall")){
String ht = st.nextToken();
double perone =
Double.parseDouble(st.nextToken());
String start = st.nextToken();
double dur =
Double.parseDouble(st.nextToken());
String day = st.nextToken();
String pm = st.nextToken();
if(ic.equals(pk)){
day = nwci;

h[index] = new
Hall(bt,name,ic,yr,no,perone,p
m,ht,dur,day,start);
}
else

h[index] = new
Hall(bt,name,ic,yr,no,perone,p
m,ht,dur,day,start);
}
index++;
str = br.readLine();
}
br.close();

JOptionPane.showMessageDialog(null, "Update is
successful!", "UPDATE",
JOptionPane.INFORMATION_MESSAGE, icon);

}
catch(Exception e) {
System.err.println(e.getMessage()); }
}

26
public static void main(String[] args) throws Exception
{
BufferedReader br = new BufferedReader(new
FileReader(new File("List of Customers.txt")));

PrintWriter pwHall = new PrintWriter (new


FileWriter(new File("Customers' Details for
Hall.txt")));

PrintWriter pwRoom = new PrintWriter (new


FileWriter(new File("Customers' Details for
Room.txt")));

try{
String choice;
final int SIZE = 10;
Hotel[] h = new Hotel[SIZE];
String str="";
while(true){
System.out.print("\f");

System.out.println("\t\t\t_______________
____________________");
System.out.println("\t\t\t|\tWELCOME TO
HOTEL DEL LUNA\t|");
System.out.println("\t\t\t---------------
--------------------");
System.out.println("\t\t\t[ A ] - ADD NEW
CUSTOMER");
System.out.println("\t\t\t[ S ] - SEARCH
CUSTOMER");
System.out.println("\t\t\t[ U ] - UPDATE
BOOKING DATE(S)");
System.out.println("\t\t\t[ E ] - EXIT");

System.out.print("\n\t\t\tENTER YOUR
CHOICE --> ");
choice = in.next();

str = br.readLine();

while(str!= null){
StringTokenizer st = new
StringTokenizer(str, ",");
String name = st.nextToken();
String ic = st.nextToken();
int yr =
Integer.parseInt(st.nextToken());
String no = st.nextToken();
String bt = st.nextToken(); //
if(bt.equalsIgnoreCase("Room")){
String rt = st.nextToken();
String rn = st.nextToken();
double perone =
Double.parseDouble(st.nextToke
n());

27
String start = st.nextToken();
String end = st.nextToken();
int dur =
Integer.parseInt(st.nextToken(
));
String pm = st.nextToken();
if(st.hasMoreTokens()){

String f =
st.nextToken();
int qf =
Integer.parseInt(st.next
Token());
double prcef =
Double.parseDouble(st.ne
xtToken());
String d =
st.nextToken();
int qd =
Integer.parseInt(st.next
Token());
double prced =
Double.parseDouble(st.ne
xtToken());
h[index] = new
Food(bt,name,ic,yr,no,pe
rone,pm,rt,rn,dur,start,
end,f,d,qf,qd,prcef,prce
d);
}
else

h[index] = new
Room(bt,name,ic,yr,no,pe
rone,pm,rt,rn,dur,start,
end);
}
else
if(bt.equalsIgnoreCase("Hall")){
String ht = st.nextToken();
double perone =
Double.parseDouble(st.nextToke
n());
String start = st.nextToken();
double dur =
Double.parseDouble(st.nextToke
n());
String day = st.nextToken();
String pm = st.nextToken();

h[index] = new
Hall(bt,name,ic,yr,no,perone,p
m,ht,dur,day,start);
}
index++;
str = br.readLine();

28
}

if(choice.equalsIgnoreCase("A")){
addCust(h);
}

else if(choice.equalsIgnoreCase("S")){
searchCust(h);
}
else if(choice.equalsIgnoreCase("U")){
updateCust(h);
}
else if(choice.equalsIgnoreCase("E")){
break;
}
}
br.close();
PrintWriter pw = new PrintWriter (new FileWriter(new
File("List of Customers.txt")));
for(int i=0; i<h.length; i++){
if(h[i] instanceof Hall){

pw.println(h[i].getCustName() + "," +
h[i].getICNo() + "," + h[i].getAge() +
"," + h[i].getPhoneNo() + "," +
h[i].getBookType() + "," +
((Hall)h[i]).getHallType() + "," +
df.format(h[i].getPrice()) + "," +
((Hall)h[i]).getTime() + "," +
((Hall)h[i]).getReserveHour() + "," +
((Hall)h[i]).getDate() + "," +
h[i].getPayMethod());

pwHall.println(h[i].toString());
}
else if(h[i] instanceof Food){
pw.println(h[i].getCustName() + "," +
h[i].getICNo() + "," + h[i].getAge() +
"," + h[i].getPhoneNo() + "," +
h[i].getBookType() + "," +
((Food)h[i]).getRoom() +
"," + ((Food)h[i]).getRoomNo() + "," +
df.format(h[i].getPrice()) + "," +
((Food)h[i]).getCheckIn() + "," +
((Food)h[i]).getCheckOut() + "," +
((Food)h[i]).getNight() +
"," + h[i].getPayMethod() + "," +
((Food)h[i]).getFood()+ "," +
((Food)h[i]).getFoodQty()+ "," +
df.format(((Food)h[i]).getPriceF())+ ","
+ ((Food)h[i]).getDrink()+ ","
+ ((Food)h[i]).getDrinkQty()+ "," +
df.format(((Food)h[i]).getPriceD()));

pwRoom.println(h[i].toString());
}

29
else if(h[i] instanceof Room){

pw.println(h[i].getCustName() + "," +
h[i].getICNo() + "," + h[i].getAge() +
"," + h[i].getPhoneNo() + "," +
h[i].getBookType() + "," +
((Room)h[i]).getRoom() +
"," + ((Room)h[i]).getRoomNo() + "," +
df.format(h[i].getPrice()) + "," +
((Room)h[i]).getCheckIn() + "," +
((Room)h[i]).getCheckOut() + "," +
((Room)h[i]).getNight() +
"," + h[i].getPayMethod());

pwRoom.println(h[i].toString());
}
}
pw.close();
pwHall.close();
pwRoom.close();
}
catch (Exception e1) {
System.err.println(e1.getMessage()); }
}
}

30
4. Details of Input and Output File

Input File

List of Customers.txt

Input File (after adding new customer & updating existing customer)

1. Add new customer


a. Koko
b. Ochi
2. Update booking date(s)
a. Najihah’s booking dates.

List of Customers.txt

Output File for Hall Tenants

Customers' Details for Hall.txt

31
Output File for Hotel Guests

Customers' Details for Room.txt

32
5. Sample Input/Output (Snapshot)

1. Add New Customer

33
34
Error Message Box will appear if room is not available at desired date.

35
2. Search Customer

36
3. Update Booking Date(s)

37
6. References

1. Chavez, M., Mark, C., Boyle, J., & Stark, T. (2016, November 26). Java Swing –
JOptionPane showMessageDialog example. Retrieved from
https://www.mkyong.com/swing/java-swing-how-to-make-a-simple-dialog/.
2. LenkaCheck, C., & Lenka, C. (2018, November 26). HashSet contains() Method in
Java. Retrieved from https://www.geeksforgeeks.org/hashset-contains-method-in-
java/.
3. LenkaCheck, C., & Lenka, C. (2018, November 26). HashSet add() Method in Java.
Retrieved from https://www.geeksforgeeks.org/hashset-add-method-in-java/.

38
CSC238 - Peer Work Group Evaluation Forms
Instruction: Evaluate the work of the team members in your group:
✓ By answering YES or NO and
✓ By using a Likert Scale from 1 to 3, where 1 being POOR, 2 being AVERAGE, 3 being GOOD

Evaluator’s Name: Nur Najihah Binti Muhamad Farid Class: CS1103A

Project’s Title: Hotel Booking System

Group Member 1: Nur Sabrina Batrisyia Binti Ahmad Azua

1. Did this group member complete his/her assigned tasks for the group? Yes No

2. Did this group member gives a good cooperation for the group? Yes No

3. Overall, how would you rank this group member’s performance in the group? 1 2 3

4. Would you like to work with this person again? Yes No

Explain why.
…………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………
Group Member 2: Aliya Syaffaa binti Jamaludin

1. Did this group member complete his/her assigned tasks for the group? Yes No

2. Did this group member gives a good cooperation for the group? Yes No

3. Overall, how would you rank this group member’s performance in the group? 1 2 3

4. Would you like to work with this person again? Yes No

Explain why.
…………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………
CSC238 - Peer Work Group Evaluation Forms
Instruction: Evaluate the work of the team members in your group:
✓ By answering YES or NO and
✓ By using a Likert Scale from 1 to 3, where 1 being POOR, 2 being AVERAGE, 3 being GOOD

Evaluator’s Name: Nur Sabrina Batrisyia Binti Ahmad Azua Class: CS1103A

Project’s Title: Hotel Booking System

Group Member 1: Nur Najihah Binti Muhamad Farid

1. Did this group member complete his/her assigned tasks for the group? Yes No

2. Did this group member gives a good cooperation for the group? Yes No

3. Overall, how would you rank this group member’s performance in the group? 1 2 3

4. Would you like to work with this person again? Yes No

Explain why.
…………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………
Group Member 2: Aliya Syaffaa binti Jamaludin

1. Did this group member complete his/her assigned tasks for the group? Yes No

2. Did this group member gives a good cooperation for the group? Yes No

3. Overall, how would you rank this group member’s performance in the group? 1 2 3

4. Would you like to work with this person again? Yes No

Explain why.
…………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………
CSC238 - Peer Work Group Evaluation Forms
Instruction: Evaluate the work of the team members in your group:
✓ By answering YES or NO and
✓ By using a Likert Scale from 1 to 3, where 1 being POOR, 2 being AVERAGE, 3 being GOOD

Evaluator’s Name: Aliya Syaffaa binti Jamaludin Class: CS1103A

Project’s Title: Hotel Booking System

Group Member 1: Nur Sabrina Batrisyia Binti Ahmad Azua

1. Did this group member complete his/her assigned tasks for the group? Yes No

2. Did this group member gives a good cooperation for the group? Yes No

3. Overall, how would you rank this group member’s performance in the group? 1 2 3

4. Would you like to work with this person again? Yes No

Explain why.
…………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………
Group Member 2: Nur Najihah Binti Muhamad Farid

1. Did this group member complete his/her assigned tasks for the group? Yes No

2. Did this group member gives a good cooperation for the group? Yes No

3. Overall, how would you rank this group member’s performance in the group? 1 2 3

4. Would you like to work with this person again? Yes No

Explain why.
…………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………
CSC238 MINI PROJECT (10%) SEPT 2019

CSC238 – OBJECT ORIENTED PROGRAMMING

Scoring Rubric 29
Name Student ID
Nur Najihah Binti Muhamad Farid 2018209898
Nur Sabrina Batrisyia Binti Ahmad Azua 2018205058
Aliya Syaffaa binti Jamaludin 2018214482

Group : CS1103A
Project Title : Hotel Booking System
Marking Scheme

Remarks
Category
Weak Moderate Good Very Good
1 2 3 4
Proposal
Include all the necessary information and it is well documented.

Clarity of 1 2 3 4
program’s
The program is clearly written as well as easy to understand. Each
presentation
of the process is documented.
Structure and 1 2 3 4
algorithm of a The algorithm of the program is capable of solving the problem
program completely. There is no syntax error, logic error and run-time error.
1 2 3 4
OOP concept and
File IO Apply a clearly OOP concepts and File IO within the algorithm of
the program.
1 2 3 4
Result The program produced expected output with correct and
presentable format.
1 2 3 4
Report quality The report is well written and documented. Clearly explains what
the project is all about.
1 2 3 4
Presentation Presentation is clear, logical and organized. Information is well
communicated.

Peer Work Group Evaluations: 1 mark

You might also like