Anda di halaman 1dari 44

Ujian Akhir Praktikum

Pemrograman Berorientasi Objek

Disusun oleh :

Qory Aprilarita
1317051049

Jurusan Ilmu Komputer


Fakultas Matematika dan Ilmu Pengetahuan Alam
Universitas Lampung

Aplikasi Reservasi Hotel GG


Penjelasan program :
Pertama kita harus melakukan login pada form login dengan memasukkan
username dan password, jika sukses maka akan masuk ke form input data, jika gagal
maka akan muncul pemberitahuan bahwa username atau password tidak sesuai dan
harus memasukkan username dan password lagi. Tombol cancel digunakan untuk
memformat username dan password yang diinputkan sedangkan tombol keluar
digunakan untuk mengeluarkan/memberhentikan program.
Pada form input data, kita akan diwajibkan untuk mengisi nama, nomor telepon,
jenis kelamin, lama menginap, tanggal check in, tanggal check out, tipe kamar, dan
nomor kamar. Jika tombol save diklik maka data yang diinputkan akan diexport dan
disave menjadi database.txt, lalu akan muncul pemberitahuan total biaya yang harus
dibayarkan. Jika tombol cancel diklik maka semua data yang diinputkan akan
terformat dan jika tombol exit diklik maka program akan exit. Tombol search
digunakan untuk mencari daftar tamu.
Pada form pencarian kita harus memasukkan nama tamu lalu diklik tombol search
maka akan tampil informasi tamu hotel yang ingin dicari. Tombol home pada form
pencarian digunakan untuk kembali ke form input data.

Flowchart program :
Start

Input
Username

Input
Password

Tidak
If (login==
diklik)
Ya
Input nama

Tidak

Input nomor
telepon

Input jenis
kelamin

Input tipe
kamar

Input tanggal
check out

Input nomor
kamar

Input lama
menginap

Input tanggal
check in

If (cari
data==diklik)

Tidak

Ya
If
(save==diklik)

Input nama

Proses
pencarian data

Ya
Export data ke
database.txt

Output total Harga


pembayaran

Output hasil
pencarian

Finish

Screenshot program :

Tampilan login program

Tampilan jika username atau password tidak sesuai

Jika sudah berhasil login akan masuk ke form input data, berikut ini tampilan dari
kalendar pada pilihan check out

Tampilan saat semua data telah diinputkan

Jika tombol save diklik maka muncul total biaya yang harus dibayarkan

Jika diklik tombol search maka akan muncul form pencarian

Jika nama diinputkan dan diklik tombol search maka akan muncul informasi
mengenai tamu hotel yang ingin dicari

Jika tombol home diklik maka akan kembali ke form input data

Lampiran

/*
Coding program pada class Tamu
*/
package aplikasihotel;

/**
*
* @author Qory
*/
public class Tamu {
private String nama;
private String noTelepon;
private String jenisKelamin;
private String lamaInap;
private String checkIn;
private String checkOut;
private String tipeKamar;
private String noKamar;

public Tamu(String nama,String noTelepon,String jenisKelamin,String


lamaInap,
String checkIn, String checkOut, String tipeKamar, String noKamar) {
this.nama = nama;
this.noTelepon = noTelepon;

this.jenisKelamin = jenisKelamin;
this.lamaInap = lamaInap;
this.checkIn = checkIn;
this.checkOut = checkOut;
this.tipeKamar = tipeKamar;
this.noKamar = noKamar;
}

public String getNama() {


return nama;
}

public void setNama(String nama) {


this.nama = nama;
}

public String getNoTelepon() {


return noTelepon;
}

public void setNoTelepon(String noTelepon) {


this.noTelepon = noTelepon;
}

public String getJenisKelamin() {


return jenisKelamin;
}

public void setJenisKelamin(String jenisKelamin) {


this.jenisKelamin = jenisKelamin;
}

public String getLamaInap() {


return lamaInap;
}

public void setLamaInap(String lamaInap) {


this.lamaInap = lamaInap;
}

public String getCheckIn() {


return checkIn;
}

public void setCheckIn(String checkIn) {


this.checkIn = checkIn;

public String getCheckOut() {


return checkOut;
}

public void setCheckOut(String checkOut) {


this.checkOut = checkOut;
}

public String getTipeKamar() {


return tipeKamar;
}

public void setTipeKamar(String tipeKamar) {


this.tipeKamar = tipeKamar;
}

public String getNoKamar() {


return noKamar;
}

public void setNoKamar(String noKamar) {

this.noKamar = noKamar;
}
}

/*
Coding program pada class DataTamu
*/
package aplikasihotel;

import java.io.*;
import java.util.*;

/**
*
* @author Qory
*/

public class DataTamu {


FileOutputStream output;
List<Tamu> list;
String path = "database.txt";

public DataTamu() throws FileNotFoundException {

list = new ArrayList<Tamu>();


}

public void hapusEntry(){

public void buatDatabase() throws FileNotFoundException{


output=new FileOutputStream("database.txt",true);
}

public void simpanData(String data) throws IOException {


File file = new File(path);
FileWriter fileWriter = new FileWriter(file,true);
BufferedWriter bufferFileWriter = new BufferedWriter(fileWriter);
fileWriter.append(data);
bufferFileWriter.newLine();
bufferFileWriter.close();
}

public void bacaData() throws FileNotFoundException{


char data;
int temp;

BufferedReader br = new BufferedReader(new FileReader(path));


String word="";
try {
do{
temp = br.read();
data = (char) temp;
if (temp != 10) {
word+=data;
}

else{
String words []=word.split("#");
this.list.add(new Tamu(words[0], words[1], words[2], words[3],
words[4], words[5], words[6], words[7]));
word="";
}
} while (temp != -1);
} catch (IOException ex) {
}
}

public String cariData(String input){


Tamu guest=null;
String result ="";

for(int i=0;i<list.size();i++){
if(list.get(i).getNama().equals(input))
guest=list.get(i);
}
if(guest==null){
result+="Data Tidak Ditemukan";
}
else{
result+="Nama \t: "+guest.getNama()+"\n";
result+="No Telepon \t : "+guest.getNoTelepon()+"\n";
result+="Jenis Kelamin \t : "+guest.getJenisKelamin()+"\n";
result+="Lama Menginap : "+guest.getLamaInap()+" hari\n";
result+="Check In \t : "+guest.getCheckIn()+"\n";
result+="Check Out \t : "+guest.getCheckOut()+"\n";
result+="Tipe Kamar \t : "+guest.getTipeKamar()+"\n";
result+="No Kamar \t : "+guest.getNoKamar();
}
return result;
}
}

/*
Coding program pada class FrameLogin

*/
package aplikasihotel;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import javax.swing.*;

/**
*
* @author Qory
*/
public class FrameLogin extends JFrame {
private JPanel contentPane;
private JLabel title;
private JLabel lbBackground;
private JLabel lbNama;
private JLabel lbPassword;
private JButton login;
private JButton cancel;
private JButton exit;

private JTextField nama;


private JPasswordField password;
int x,y;
boolean mousePress;

public FrameLogin(){
addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(MouseEvent me) {
if (mousePress = true) {
int tX = FrameLogin.this.getLocation().x + me.getX();
int tY = FrameLogin.this.getLocation().y + me.getY();
int X = tX - x;
int Y = tY - y;
FrameLogin.this.setLocation(X, Y);
}
}
});
addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent me) {
mousePress = true;
x = me.getX();

y = me.getY();
}
@Override
public void mouseReleased(MouseEvent e) {
mousePress = false;
}
});
setUndecorated(true);
setBounds(200, 200, 400, 259);
setLocationRelativeTo(null);
setShape(new
java.awt.geom.RoundRectangle2D.Double(0,0,getWidth(),getHeight(),40,40));
contentPane = new JPanel();
setContentPane(contentPane);
contentPane.setLayout(null);

title = new JLabel("Login Aplikasi Reservasi Hotel GG");


title.setBounds(30,25,400,25);
title.setFont(new Font("Comic Sans MS", Font.BOLD, 20));
title.setForeground(Color.white);
contentPane.add(title);

lbNama = new JLabel("Username");


lbNama.setBounds(70,100,100,20);

lbNama.setForeground(Color.white);
contentPane.add(lbNama);

nama = new JTextField();


nama.setBounds(150,100,170,20);
contentPane.add(nama);

lbPassword = new JLabel("Password");


lbPassword.setBounds(70,150,100,20);
lbPassword.setForeground(Color.white);
contentPane.add(lbPassword);

password = new JPasswordField();


password.setBounds(150,150,170,20);
contentPane.add(password);

login = new JButton("Login");


login.setBounds(165,200,70,30);
contentPane.add(login);
login.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
String user = nama.getText();

String pw = password.getText();
FrameInputData ah = new FrameInputData();
if(user.equals("Qory")&&pw.equals("soshi")){
ah.setVisible(true);
setVisible(false);}
else JOptionPane.showMessageDialog(null,"Username atau password
tidak sesuai","Pesan",JOptionPane.INFORMATION_MESSAGE);
nama.setText("");
password.setText("");
nama.requestFocus();
}
});

cancel = new JButton ("Cancel");


cancel.setBounds(65,200,73,30);
contentPane.add(cancel);
cancel.addMouseListener(new MouseAdapter(){
@Override
public void mouseClicked(MouseEvent e){
nama.setText("");
password.setText("");
nama.requestFocus();
}
});

exit = new JButton("Exit");


exit.setBounds(265,200,70,30);
contentPane.add(exit);
exit.addMouseListener(new MouseAdapter(){
@Override
public void mouseClicked(MouseEvent e){
dispose();
}
});

lbBackground = new JLabel();


lbBackground.setBounds(0,0,400,259);
lbBackground.setIcon(new
ImageIcon(FrameLogin.class.getResource("/gambar/bg2.png")));
contentPane.add(lbBackground)
}

public static void main(String[] args) {


FrameLogin main = new FrameLogin();
main.setVisible(true);
}}

/*

Coding program pada class FrameInputData


*/
package aplikasihotel;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.util.Locale;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import org.kazao.calendar.KazaoCalendarDate;

/**
*
* @author Qory
*/
public class FrameInputData extends JFrame {
private JPanel contentPane;
private JPanel panel;

private JLabel background;


private JLabel lbNama;
private JLabel lbTelepon;
private JLabel lbKelamin;
private JLabel lbInap;
private JLabel lbHari;
private JLabel lbIn;
private JLabel lbOut;
private JLabel lbTipe;
private JLabel lbKamar;
private JTextField nama;
private JTextField noTelepon;
private JRadioButton pria = new JRadioButton("Pria");
private JRadioButton wanita = new JRadioButton("Wanita");
private JComboBox lamaInap;
private KazaoCalendarDate checkIn;
private KazaoCalendarDate checkOut;
private JRadioButton single = new JRadioButton("Single");
private JRadioButton doble = new JRadioButton("Double");
private JRadioButton family = new JRadioButton("Family");
private JTextField noKamar;
private JButton save;
private JButton cancel;

private JButton exit;


private JButton search;
private ButtonGroup group1 = new ButtonGroup();
private ButtonGroup group2 = new ButtonGroup();
public static final String[] day = {"","1","2","3","4","5","6","7"};
int x,y;
boolean mousePress;

public FrameInputData() {
addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(MouseEvent me) {
if (mousePress = true) {
int tX = FrameInputData.this.getLocation().x + me.getX();
int tY = FrameInputData.this.getLocation().y + me.getY();
int X = tX - x;
int Y = tY - y;
FrameInputData.this.setLocation(X, Y);
}
}
});
addMouseListener(new MouseAdapter() {
@Override

public void mousePressed(MouseEvent me) {


mousePress = true;
x = me.getX();
y = me.getY();
}
@Override
public void mouseReleased(MouseEvent e) {
mousePress = false;
}
});

setUndecorated(true);
setBounds(200, 200, 400, 550);
setLocationRelativeTo(null);
setShape(new
java.awt.geom.RoundRectangle2D.Double(0,0,getWidth(),getHeight(),40,40));
contentPane = new JPanel();
setContentPane(contentPane);
contentPane.setLayout(null);

search = new JButton();


search.setBounds(340,17,40,38);
contentPane.add(search);
search.setIcon(new ImageIcon(FrameInputData.class

.getResource("/gambar/search.png")));
search.addMouseListener(new MouseAdapter(){
@Override
public void mouseClicked(MouseEvent e){
setVisible(false);
FramePencarian fp = new FramePencarian();
fp.setVisible(true);
}
});

lbNama = new JLabel("Nama");


lbNama.setBounds(20,90,100,20);
lbNama.setFont(new Font("Comic Sans MS", Font.PLAIN, 16));
lbNama.setForeground(Color.white);
contentPane.add(lbNama);

nama = new JTextField();


nama.setBounds(140,90,220,20);
contentPane.add(nama);

lbTelepon = new JLabel("No. Telepon");


lbTelepon.setBounds(20,130,100,20);
lbTelepon.setFont(new Font("Comic Sans MS", Font.PLAIN, 16));

lbTelepon.setForeground(Color.white);
contentPane.add(lbTelepon);

noTelepon = new JTextField();


noTelepon.setBounds(140,130,220,20);
contentPane.add(noTelepon);

lbKelamin = new JLabel("Jenis Kelamin");


lbKelamin.setBounds(20,170,100,20);
lbKelamin.setFont(new Font("Comic Sans MS", Font.PLAIN, 16));
lbKelamin.setForeground(Color.white);
contentPane.add(lbKelamin);

group1.add(pria);
group1.add(wanita);
pria.setBounds(140,170,70,20);
wanita.setBounds(230,170,70,20);
contentPane.add(pria);
contentPane.add(wanita);

String jk,tk;
if(pria.isSelected()){
jk="Pria";

} else {jk="Wanita";}

if(single.isSelected()){
tk="Single";
} else if (doble.isSelected()){
tk="Double";
}else {tk="Family";}

lbInap = new JLabel("Lama Inap");


lbInap.setBounds(20,210,100,20);
lbInap.setFont(new Font("Comic Sans MS", Font.PLAIN, 16));
lbInap.setForeground(Color.white);
contentPane.add(lbInap);

lamaInap = new JComboBox();


lamaInap.setBounds(140,210,50,20);
contentPane.add(lamaInap);
addItemComboBox(lamaInap,day);

lbHari = new JLabel("Hari");


lbHari.setBounds(200,210,100,20);
lbHari.setFont(new Font("Comic Sans MS", Font.PLAIN, 16));

contentPane.add(lbHari);

lbIn = new JLabel("Check In");


lbIn.setBounds(20,250,100,20);
lbIn.setFont(new Font("Comic Sans MS", Font.PLAIN, 16));
lbIn.setForeground(Color.white);
contentPane.add(lbIn);

checkIn = new KazaoCalendarDate();


checkIn.setBounds(140,250,100,20);
contentPane.add(checkIn);

lbOut = new JLabel("Check Out");


lbOut.setBounds(20,290,100,20);
lbOut.setFont(new Font("Comic Sans MS", Font.PLAIN, 16));
lbOut.setForeground(Color.white);
contentPane.add(lbOut);

checkOut = new KazaoCalendarDate();


checkOut.setBounds(140,290,100,20);
contentPane.add(checkOut);

lbTipe = new JLabel("Tipe Kamar");

lbTipe.setBounds(20,330,100,20);
lbTipe.setFont(new Font("Comic Sans MS", Font.PLAIN, 16));
lbTipe.setForeground(Color.white);
contentPane.add(lbTipe);

group2.add(single);
group2.add(doble);
group2.add(family);
single.setBounds(140,330,70,20);
doble.setBounds(140,360,70,20);
family.setBounds(140,390,70,20);
contentPane.add(single);
contentPane.add(doble);
contentPane.add(family);

lbKamar = new JLabel("Nomor Kamar");


lbKamar.setBounds(20,430,100,20);
lbKamar.setFont(new Font("Comic Sans MS", Font.PLAIN, 16));
lbKamar.setForeground(Color.white);
contentPane.add(lbKamar);

noKamar = new JTextField();


noKamar.setBounds(140,430,50,20);

contentPane.add(noKamar);

save = new JButton("Save");


save.setBounds(65,480,70,35);
contentPane.add(save);
save.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int total=0;
if(single.isSelected()){
total=lamaInap.getSelectedIndex()*1000000;
} else if (doble.isSelected()){
total=lamaInap.getSelectedIndex()*200000;
}else {total=lamaInap.getSelectedIndex()*300000;}
try {
DataTamu dt = new DataTamu();
dt.buatDatabase();
String data="";
data+=nama.getText()+"#"+noTelepon.getText()+"#";
data+=jk+"#"+lamaInap.getSelectedItem()+"#";
data+=checkIn.getKazaoCalendar().getLongDate().toString()+"#";
data+=checkOut.getKazaoCalendar().getLongDate().toString()+"#";
data+=tk+"#"+noKamar.getText()+"#"+total;
dt.simpanData(data);

batal();
}catch(Exception ex) {
}
JOptionPane.showMessageDialog(null, "Total Harga : Rp "+total);
}
});

cancel = new JButton("Cancel");


cancel.setBounds(165,480,73,35);
contentPane.add(cancel);
cancel.addMouseListener(new MouseAdapter(){
@Override
public void mouseClicked(MouseEvent e){
batal();
}
});

exit = new JButton("Exit");


exit.setBounds(265,480,70,35);
contentPane.add(exit);
exit.addMouseListener(new MouseAdapter(){
@Override
public void mouseClicked(MouseEvent e){

dispose();
}
});

background = new JLabel();


background.setBounds(0,0,400,550);
background.setIcon(new ImageIcon(FrameInputData.class

.getResource("/gambar/bg.jpg")));
contentPane.add(background);

public void batal(){


nama.setText("");
noTelepon.setText("");
group1.clearSelection();
lamaInap.setSelectedIndex(0);
group2.clearSelection();
noKamar.setText("");
}

public void addItemComboBox(JComboBox day, Object[] items) {


for (Object item : items) {

day.addItem(item);
}
}
}

/*
Coding program pada class FramePencarian
*/
package aplikasihotel;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.io.FileNotFoundException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import javax.swing.JTextArea;
import javax.swing.JTextField;

/**
*
* @author Qory
*/

public class FramePencarian extends JFrame {


private JPanel contentPane;
private JLabel background;
private JLabel title;
private JLabel nama;
private JTextField name;
private JButton back;
private JButton cari;
private JTextArea hasil;
boolean mousePress;
int x,y;

public FramePencarian() {
addMouseMotionListener(new MouseMotionAdapter() {
@Override

public void mouseDragged(MouseEvent me) {


if (mousePress = true) {
int tX = FramePencarian.this.getLocation().x + me.getX();
int tY = FramePencarian.this.getLocation().y + me.getY();
int X = tX - x;
int Y = tY - y;
FramePencarian.this.setLocation(X, Y);
}
}
});
addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent me) {
mousePress = true;
x = me.getX();
y = me.getY();
}
@Override
public void mouseReleased(MouseEvent e) {
mousePress = false;
}
});

setUndecorated(true);
setBounds(200, 200, 400, 550);
setLocationRelativeTo(null);
setShape(new
java.awt.geom.RoundRectangle2D.Double(0,0,getWidth(),getHeight(),40,40));
contentPane = new JPanel();
setContentPane(contentPane);
contentPane.setLayout(null);

title = new JLabel("Pencarian Data Tamu");


title.setBounds(85,80,250,40);
title.setFont(new Font("Comic Sans MS", Font.BOLD, 22));
title.setForeground(Color.white);
contentPane.add(title);

back = new JButton();


back.setBounds(340,17,40,38);
back.setIcon(new ImageIcon(FramePencarian.class

.getResource("/gambar/home.png")));
contentPane.add(back);
back.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {

FrameInputData fid= new FrameInputData();


fid.setVisible(true);
setVisible(false);
}
});

name = new JTextField();


name.setBounds(65,170,250,25);
name.setText("Enter Name");
name.setFont(new Font("Arial", Font.PLAIN, 12));
name.setForeground(Color.red);
name.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
name.selectAll();
name.setForeground(Color.black);
}
});
contentPane.add(name);

cari = new JButton();


cari.setBounds(315,170,25,25);
cari.setIcon(new ImageIcon(FramePencarian.class

.getResource("/gambar/find.png")));
cari.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
try {
DataTamu dt=new DataTamu();
try {
dt.bacaData();
} catch (FileNotFoundException ex) {
}
String input = name.getText();
String result="";
dt.cariData(input);
hasil.setText(dt.cariData(input));
} catch (FileNotFoundException ex) {

Logger.getLogger(FramePencarian.class.getName()).log(Level.SEVERE, null,
ex);
}
}
});
contentPane.add(cari);

hasil = new JTextArea();


hasil.setBounds(24,250,350,250);
hasil.setFont(new Font("Arial", Font.PLAIN, 12));
hasil.setEditable(false);
contentPane.add(hasil);

background = new JLabel();


background.setBounds(0,0,400,550);
background.setIcon(new ImageIcon(FrameInputData.class

.getResource("/gambar/bg.jpg")));
contentPane.add(background);
}
}