Program Perhotelan berbasis GUI sederhana
Program Perhotelan berbasis GUI atau Java.awt atau biasa disebut AWT (Abstract Window Toolkit) dan java.swing
ketentuan:
-Pelanggan Member yang menginap lebih dari atau sama dengan 4 hari akan memdapakan diskon 20%.
-Pelanggan Member yang menginap lebih dari atau sama dengan 1 minggu akan memdapakan diskon 35%. --Pelanggan bukan member yang menginap lebih dari atau sama dengan 4 hari akan memdapakan diskon 10%.
-Pelanggan Member yang menginap lebih dari 1 minggu akan memdapakan diskon 15%. "
menggunakan JRadioButton
///////////////
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SewaHotel extends JFrame implements ActionListener {
Container konten = getContentPane();
private final JLabel lblIDPelanggan = new JLabel("ID Pelanggan :");
private final JLabel lblNama = new JLabel("Nama :");
private final JLabel lblTgl = new JLabel("Tanggal Cek In :");
private final JLabel lblAlamat = new JLabel("Alamat :");
private final JLabel lblJenisKamar = new JLabel("JenisKamar:");
private final JLabel lblMember = new JLabel("Member :");
private JLabel lbllama = new JLabel("Lama Menginap :");
private JLabel lblTelp = new JLabel("Telp :");
private JTextField txtIDPelanggan = new JTextField();
private JTextField txtNama = new JTextField();
private JTextField txtTgl = new JTextField();
private JTextField txtAlamat = new JTextField();
private final JRadioButton rDeluxeRoom = new JRadioButton("1. Deluxe Room Rp 275.000/hari");
private final JRadioButton rSuiteRoom = new JRadioButton("2. Suite Room Rp 300.000/hari");
private final JRadioButton rPresidentRoom = new JRadioButton("3. President Room Rp 370.000/hari");
private final ButtonGroup btnGrup;
private final JRadioButton rMember = new JRadioButton("Member");
private final JRadioButton rNonMember = new JRadioButton("Non Member");
private final ButtonGroup btGrup = new ButtonGroup();
private JTextField txtlama = new JTextField();
private JTextField txtTelp = new JTextField();
private JButton btnTampil = new JButton("Tampil");
private JButton btnKeluar = new JButton("Keluar");
public SewaHotel(){
super("PERHOTELAN");
this.btnGrup = new ButtonGroup();
setVisible(true);
setSize(500,500);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
konten.setLayout(null);
btnGrup.add(rDeluxeRoom);
btnGrup.add(rSuiteRoom);
btnGrup.add(rPresidentRoom);
rDeluxeRoom.setSelected(true);
btGrup.add(rMember);
btGrup.add(rNonMember);
rMember.setSelected(true);
lblIDPelanggan.setBounds(20,20,100,25);
lblNama.setBounds(20,55,100,25);
lbllama.setBounds(20,90,120,25);
lblJenisKamar.setBounds(20,125,100,25);
lblMember.setBounds(20,160,100,25);
lblTgl.setBounds(20,195,100,25);
lblAlamat.setBounds(20,230,100,25);
lblTelp.setBounds(20,265,100,25);
txtIDPelanggan.setBounds(150,20,100,25);
txtNama.setBounds(150,55,100,25);
txtlama.setBounds(150,90,100,25);
rDeluxeRoom.setBounds(150,125,90,25);
rSuiteRoom.setBounds(250,125,90,25);
rPresidentRoom.setBounds(350,125,90,25);
rMember.setBounds(150,160,90,25);
rNonMember.setBounds(250,160,90,25);
txtTgl.setBounds(150,195,100,25);
txtAlamat.setBounds(150,230,200,25);
txtTelp.setBounds(150,265,100,25);
btnTampil.setBounds(30,300,90,25);
btnKeluar.setBounds(250,300,90,25);
konten.add(lblIDPelanggan);
konten.add(lblNama);
konten.add(lbllama);
konten.add(lblJenisKamar);
konten.add(lblMember);
konten.add(lblTgl);
konten.add(lblAlamat);
konten.add(lblTelp);
konten.add(txtIDPelanggan);
konten.add(txtNama);
konten.add(txtlama);
konten.add(rDeluxeRoom);
konten.add(rSuiteRoom);
konten.add(rPresidentRoom);
konten.add(rMember);
konten.add(rNonMember);
konten.add(txtTgl);
konten.add(txtAlamat);
konten.add(txtTelp);
konten.add(btnTampil);
konten.add(btnKeluar);
btnTampil.addActionListener(this);
btnKeluar.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent act) {
double lama=Double.parseDouble(txtlama.getText());
double tarif=0,diskon=0,bayar=0;
Object obj = act.getSource();
if (obj==btnTampil) {
String JenisKamar="";
String Member="";
{
if (rDeluxeRoom.isSelected()){
tarif = lama*275000;
JenisKamar="Deluxe Room";
}else if (rSuiteRoom.isSelected()){
tarif = lama*300000;
JenisKamar="Suite Room";
}else{
tarif = lama*375000;
JenisKamar="President Room";
}
if (rMember.isSelected()){
Member = " Member";
if(lama>=4 && lama<=7){
diskon = 0.20 * tarif;
}else if (lama>7) {
diskon = 0.35 * tarif;
}
}else if (rNonMember.isSelected()){
Member = "Non Member";
if (lama>=4 && lama<=7){
diskon = 0.10 * tarif;
}else if (lama>7){
diskon = 0.15 * tarif;
}
}
bayar = tarif-diskon;
}
JOptionPane.showMessageDialog(null,"ID Pelanggan \t\t: " + txtIDPelanggan.getText() +
"\nNama \t\t: " + txtNama.getText() +
"\nJenis Kamar \t\t :"+ JenisKamar +
"\nMember \t\t: " + Member +
"\nTanggal CekIn \t: " + txtTgl.getText() +
"\n Tarif \t\t: " + tarif +
" \n diskon \t\t :" + diskon +
"\n bayar \t\t: " +bayar +
"\nAlamat \t\t: " + txtAlamat.getText() +
"\nTelp \t\t: " + txtTelp.getText());
} else if (obj == btnKeluar) {
System.exit(0);
}
}
public static void main (String [] form) {
SewaHotel sewaHotel = new SewaHotel();
}
}
////////
ketentuan:
-Pelanggan Member yang menginap lebih dari atau sama dengan 4 hari akan memdapakan diskon 20%.
-Pelanggan Member yang menginap lebih dari atau sama dengan 1 minggu akan memdapakan diskon 35%. --Pelanggan bukan member yang menginap lebih dari atau sama dengan 4 hari akan memdapakan diskon 10%.
-Pelanggan Member yang menginap lebih dari 1 minggu akan memdapakan diskon 15%. "
menggunakan JRadioButton
///////////////
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SewaHotel extends JFrame implements ActionListener {
Container konten = getContentPane();
private final JLabel lblIDPelanggan = new JLabel("ID Pelanggan :");
private final JLabel lblNama = new JLabel("Nama :");
private final JLabel lblTgl = new JLabel("Tanggal Cek In :");
private final JLabel lblAlamat = new JLabel("Alamat :");
private final JLabel lblJenisKamar = new JLabel("JenisKamar:");
private final JLabel lblMember = new JLabel("Member :");
private JLabel lbllama = new JLabel("Lama Menginap :");
private JLabel lblTelp = new JLabel("Telp :");
private JTextField txtIDPelanggan = new JTextField();
private JTextField txtNama = new JTextField();
private JTextField txtTgl = new JTextField();
private JTextField txtAlamat = new JTextField();
private final JRadioButton rDeluxeRoom = new JRadioButton("1. Deluxe Room Rp 275.000/hari");
private final JRadioButton rSuiteRoom = new JRadioButton("2. Suite Room Rp 300.000/hari");
private final JRadioButton rPresidentRoom = new JRadioButton("3. President Room Rp 370.000/hari");
private final ButtonGroup btnGrup;
private final JRadioButton rMember = new JRadioButton("Member");
private final JRadioButton rNonMember = new JRadioButton("Non Member");
private final ButtonGroup btGrup = new ButtonGroup();
private JTextField txtlama = new JTextField();
private JTextField txtTelp = new JTextField();
private JButton btnTampil = new JButton("Tampil");
private JButton btnKeluar = new JButton("Keluar");
public SewaHotel(){
super("PERHOTELAN");
this.btnGrup = new ButtonGroup();
setVisible(true);
setSize(500,500);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
konten.setLayout(null);
btnGrup.add(rDeluxeRoom);
btnGrup.add(rSuiteRoom);
btnGrup.add(rPresidentRoom);
rDeluxeRoom.setSelected(true);
btGrup.add(rMember);
btGrup.add(rNonMember);
rMember.setSelected(true);
lblIDPelanggan.setBounds(20,20,100,25);
lblNama.setBounds(20,55,100,25);
lbllama.setBounds(20,90,120,25);
lblJenisKamar.setBounds(20,125,100,25);
lblMember.setBounds(20,160,100,25);
lblTgl.setBounds(20,195,100,25);
lblAlamat.setBounds(20,230,100,25);
lblTelp.setBounds(20,265,100,25);
txtIDPelanggan.setBounds(150,20,100,25);
txtNama.setBounds(150,55,100,25);
txtlama.setBounds(150,90,100,25);
rDeluxeRoom.setBounds(150,125,90,25);
rSuiteRoom.setBounds(250,125,90,25);
rPresidentRoom.setBounds(350,125,90,25);
rMember.setBounds(150,160,90,25);
rNonMember.setBounds(250,160,90,25);
txtTgl.setBounds(150,195,100,25);
txtAlamat.setBounds(150,230,200,25);
txtTelp.setBounds(150,265,100,25);
btnTampil.setBounds(30,300,90,25);
btnKeluar.setBounds(250,300,90,25);
konten.add(lblIDPelanggan);
konten.add(lblNama);
konten.add(lbllama);
konten.add(lblJenisKamar);
konten.add(lblMember);
konten.add(lblTgl);
konten.add(lblAlamat);
konten.add(lblTelp);
konten.add(txtIDPelanggan);
konten.add(txtNama);
konten.add(txtlama);
konten.add(rDeluxeRoom);
konten.add(rSuiteRoom);
konten.add(rPresidentRoom);
konten.add(rMember);
konten.add(rNonMember);
konten.add(txtTgl);
konten.add(txtAlamat);
konten.add(txtTelp);
konten.add(btnTampil);
konten.add(btnKeluar);
btnTampil.addActionListener(this);
btnKeluar.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent act) {
double lama=Double.parseDouble(txtlama.getText());
double tarif=0,diskon=0,bayar=0;
Object obj = act.getSource();
if (obj==btnTampil) {
String JenisKamar="";
String Member="";
{
if (rDeluxeRoom.isSelected()){
tarif = lama*275000;
JenisKamar="Deluxe Room";
}else if (rSuiteRoom.isSelected()){
tarif = lama*300000;
JenisKamar="Suite Room";
}else{
tarif = lama*375000;
JenisKamar="President Room";
}
if (rMember.isSelected()){
Member = " Member";
if(lama>=4 && lama<=7){
diskon = 0.20 * tarif;
}else if (lama>7) {
diskon = 0.35 * tarif;
}
}else if (rNonMember.isSelected()){
Member = "Non Member";
if (lama>=4 && lama<=7){
diskon = 0.10 * tarif;
}else if (lama>7){
diskon = 0.15 * tarif;
}
}
bayar = tarif-diskon;
}
JOptionPane.showMessageDialog(null,"ID Pelanggan \t\t: " + txtIDPelanggan.getText() +
"\nNama \t\t: " + txtNama.getText() +
"\nJenis Kamar \t\t :"+ JenisKamar +
"\nMember \t\t: " + Member +
"\nTanggal CekIn \t: " + txtTgl.getText() +
"\n Tarif \t\t: " + tarif +
" \n diskon \t\t :" + diskon +
"\n bayar \t\t: " +bayar +
"\nAlamat \t\t: " + txtAlamat.getText() +
"\nTelp \t\t: " + txtTelp.getText());
} else if (obj == btnKeluar) {
System.exit(0);
}
}
public static void main (String [] form) {
SewaHotel sewaHotel = new SewaHotel();
}
}
////////
Comments
Post a Comment