Latihan Java

5
[Latihan Java – Pemrograman Visual Akuntansi I] 1. Buat Tampilan Form Seperti Berikut 2. Ketentuan Soal a. Nama Kamar Nama kamar didapat ketika Combo Box Kode Kamar di Pilih. Kode Kamar Nama Kamar M001 Mawar P001 Poppy T001 Tulip b. Lama Inap Lama Inap Didapat Ketika Tanggal Cek Out di Input dan ditekan tombol Enter. Lama Inap = Tanggal Cek Out – Tanggal Cek In c. Tipe Kamar Type Kamar Tarif Supperio r Rp. 1.000.000 Deluxe Rp. 750.000 Suite Rp 500.000 d. Fasilitas Fasilita s Harga Internet Rp. 200.000,00 TV Kabel Rp. 150.000,00 e. Hitung Ketika Tombol Hitung di Klik Maka Akan Tampil Total Bayar. Total Bayar = Tarif Tipe Kamar *Lama Inap+Harga Fasilitas f. Uang Kembali Ketika uang bayar di Input dan di Tekan tombol enter maka Jika Uang Bayar Kurang dari Total Bayar maka akan Tampil Messege Box Seperti Berikut: [Created By. DCP-Aisyah-Maya] Page 1

description

- Percabangan- Option Button- Check Box- Message Box- Perhitungan Selisih Tanggal

Transcript of Latihan Java

Page 1: Latihan Java

[Latihan Java – Pemrograman Visual Akuntansi I]

1. Buat Tampilan Form Seperti Berikut

2. Ketentuan Soal a. Nama Kamar

Nama kamar didapat ketika Combo Box Kode Kamar di Pilih.Kode Kamar Nama KamarM001 MawarP001 PoppyT001 Tulip

b. Lama InapLama Inap Didapat Ketika Tanggal Cek Out di Input dan ditekan tombol Enter.Lama Inap = Tanggal Cek Out – Tanggal Cek In

c. Tipe Kamar

Type Kamar TarifSupperior Rp. 1.000.000Deluxe Rp. 750.000

Suite Rp 500.000d. Fasilitas

Fasilitas HargaInternet Rp. 200.000,00TV Kabel Rp. 150.000,00

e. HitungKetika Tombol Hitung di Klik Maka Akan Tampil Total Bayar.Total Bayar = Tarif Tipe Kamar *Lama Inap+Harga Fasilitas

f. Uang KembaliKetika uang bayar di Input dan di Tekan tombol enter maka Jika Uang Bayar Kurang dari Total Bayar maka akan Tampil Messege Box Seperti Berikut:

Jika tidak kurang maka akan tampil Uang KembaliUang Kembali= Uang Bayar – Total Bayar

g. Tombol BersihKetika Tombol Bersih di Klik Maka Semua Object Akan Kosong.

h. Tombol KeluarKetika Tombol Keluar di Klik Maka akan Tampil Messeage Box Seperti Berikut:

[Created By. DCP-Aisyah-Maya] Page 1

Page 2: Latihan Java

[Latihan Java – Pemrograman Visual Akuntansi I]

3. Code Programa. Combo Boxprivate void cKodeActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: if (cKode.getSelectedItem().equals("M001")) { tNamaKamar.setText("Mawar"); } else if (cKode.getSelectedItem().equals("T002")) { tNamaKamar.setText("Tulip"); } else { tNamaKamar.setText("Poppy"); } }

b. Lama Inapprivate void tCekOutKeyPressed(java.awt.event.KeyEvent evt) { // TODO add your handling code here: if (evt.getKeyCode()==KeyEvent.VK_ENTER) { DateFormat df=new SimpleDateFormat("dd/MM/yyyy"); try{ Date tgl1=df.parse(tCekIn.getText()); Date tgl2=df.parse(tCekOut.getText());

long hari1=tgl1.getTime(); long hari2=tgl2.getTime();

long diff=hari2-hari1; long lama=diff/(24*60*60*1000);

tLamaInap.setText(Long.toString(lama)); }catch (ParseException e) { e.printStackTrace(); } } }

c. Option Button private void rSuiteActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: tTipe.setText("500000");}

private void rSupperiorActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: tTipe.setText("1000000"); }

private void rDeluxeActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: tTipe.setText("750000"); }

[Created By. DCP-Aisyah-Maya] Page 2

Page 3: Latihan Java

[Latihan Java – Pemrograman Visual Akuntansi I]

d. Check Boxprivate void cInternetActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: if (cInternet.isSelected()== true) { Integer fas= Integer.parseInt(tFasilitas.getText()); Integer inet=fas+200000; tFasilitas.setText(Integer.toString(inet)); }else { Integer fas= Integer.parseInt(tFasilitas.getText()); Integer inet1=fas-200000; tFasilitas.setText(Integer.toString(inet1)); } }

private void tTvActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: if (tTv.isSelected()== true) { Integer fas= Integer.parseInt(tFasilitas.getText()); Integer tv=fas+150000; tFasilitas.setText(Integer.toString(tv)); }else { Integer fas= Integer.parseInt(tFasilitas.getText()); Integer tv1=fas-150000; tFasilitas.setText(Integer.toString(tv1)); }

}

e. Hitungprivate void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: Integer lama=Integer.parseInt(tLamaInap.getText()); double fasilitas=Double.parseDouble(tFasilitas.getText()); double tipe=Double.parseDouble(tTipe.getText()); double total=lama*tipe+fasilitas; tTotal.setText(Double.toString(total)); }

f. Bersihprivate void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: cKode.setSelectedIndex(0); tNama.setText(""); tNamaKamar.setText(""); tCekIn.setText(""); tCekOut.setText(""); tLamaInap.setText(""); buttonGroup1.clearSelection(); cInternet.setSelected(false); tTv.setSelected(false); tFasilitas.setText("0"); tTipe.setText("0"); tUbay.setText("0"); tUkem.setText("0"); tTotal.setText("0"); }

[Created By. DCP-Aisyah-Maya] Page 3

Page 4: Latihan Java

[Latihan Java – Pemrograman Visual Akuntansi I]

g. Uang Kembaliprivate void tUbayKeyPressed(java.awt.event.KeyEvent evt) { // TODO add your handling code here: if (evt.getKeyCode()==KeyEvent.VK_ENTER) { double Total= Double.parseDouble(tTotal.getText()); double Ubay=Double.parseDouble(tUbay.getText()); if (Total>Ubay) { JOptionPane.showMessageDialog(this,"Uang Bayar Kurang","Informasi", JOptionPane.INFORMATION_MESSAGE); }else { double Ukem=Ubay-Total; tUkem.setText(Double.toString(Ukem)); } } }

h. Keluarprivate void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: if (JOptionPane.showConfirmDialog(null,"Keluar dari Aplikasi?", "^_^ Informasi",JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION) { System.exit(0); } }

[Created By. DCP-Aisyah-Maya] Page 4