-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTiketMotorMabur.java
176 lines (140 loc) · 5.03 KB
/
TiketMotorMabur.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import java.util.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class TiketMotorMabur extends MIDlet implements CommandListener {
Display display;
Command commandExit,commandPesan;
Form formUtama,formKonfirmasi;
TextField txtNik,txtNama,txtUsia,txtJumlahTiket;
ChoiceGroup choiceJenisKelamin,choiceKelas;
DateField dateKeberangkatan;
int jumlah;
double harga,potongan;
double total,subTotal;
StringItem strNik,strNama,strUsia,strJenisKelamin,strKelas,strTanggalBerangkat,strJumlah,strTotal,strPotongan,strSubTotal;
//init constructor
public TiketMotorMabur(){
commandExit = new Command("Exit",Command.EXIT,0);
commandPesan = new Command("Pesan",Command.OK,1);
formUtama = new Form("App Tiket Motor Mabur");
formUtama.setCommandListener(this);
formUtama.addCommand(commandExit);
formUtama.addCommand(commandPesan);
txtNik = new TextField("NIK","",60,TextField.ANY);
txtNama = new TextField("Nama","",60,TextField.ANY);
txtUsia = new TextField("Usia","",60,TextField.NUMERIC);
txtJumlahTiket = new TextField("Jumlah Tiket","",60,TextField.NUMERIC);
formUtama.append(txtNik);
formUtama.append(txtNama);
formUtama.append(txtUsia);
choiceJenisKelamin = new ChoiceGroup("Jenis Kelamin",ChoiceGroup.EXCLUSIVE);
choiceJenisKelamin.append("Laki-Laki",null);
choiceJenisKelamin.append("Perempuan",null);
formUtama.append(choiceJenisKelamin);
choiceKelas = new ChoiceGroup("Kelas",ChoiceGroup.POPUP);
choiceKelas.append("VVIP",null);
choiceKelas.append("VIP",null);
choiceKelas.append("Bisnis",null);
choiceKelas.append("Ekonomi",null);
formUtama.append(choiceKelas);
dateKeberangkatan = new DateField("Tanggal Keberangkatan",DateField.DATE);
formUtama.append(dateKeberangkatan);
formUtama.append(txtJumlahTiket);
formKonfirmasi = new Form("Konfirmasi Order : ");
formKonfirmasi.setCommandListener(this);
formKonfirmasi.addCommand(commandExit);
formKonfirmasi.addCommand(commandPesan);
}
public void startApp(){
if(display == null){
display = Display.getDisplay(this);
}
display.setCurrent(formUtama);
}
public void pauseApp(){
}
public void destroyApp(boolean unconditional){
}
public void commandAction(Command c, Displayable d){
if(c == commandExit){
destroyApp(true);
notifyDestroyed();
}
if(c == commandPesan && d==formKonfirmasi){
clearDisplay();
display.setCurrent(formUtama);
}
if(c == commandPesan && d == formUtama){
if(choiceKelas.getSelectedIndex() == 0){
harga = 2000000;
}else if(choiceKelas.getSelectedIndex() == 1){
harga = 1500000;
}else if(choiceKelas.getSelectedIndex() == 2){
harga = 1000000;
}else{
harga = 500000;
}
jumlah = Integer.parseInt(txtJumlahTiket.getString());
subTotal = harga * jumlah;
if(jumlah > 3){
potongan = subTotal * 0.1;
total = subTotal - potongan;
}else{
potongan = 0;
total = subTotal-potongan;
}
initStringItem();
display.setCurrent(formKonfirmasi);
}
}
private void initStringItem(){
strNik = new StringItem("NIK : " , txtNik.getString());
strNama = new StringItem("Nama : " , txtNama.getString());
strUsia = new StringItem("Usia : ", txtUsia.getString());
strJenisKelamin = new StringItem("Jenis Kelamin : ", choiceJenisKelamin.getString(choiceJenisKelamin.getSelectedIndex()));
strKelas = new StringItem("Kelas : " , choiceKelas.getString(choiceKelas.getSelectedIndex()));
strTanggalBerangkat = new StringItem("Tanggal Keberangkatan : " , formatTanggalOrder());
strJumlah = new StringItem("Jumlah : " , txtJumlahTiket.getString());
strPotongan = new StringItem("Potongan : ", Double.toString(potongan));
strSubTotal = new StringItem("Sub Total : ",Double.toString(subTotal));
strTotal = new StringItem("Total : " , Double.toString(total));
formKonfirmasi.append(strNik);
formKonfirmasi.append(strNama);
formKonfirmasi.append(strUsia);
formKonfirmasi.append(strJenisKelamin);
formKonfirmasi.append(strKelas);
formKonfirmasi.append(strTanggalBerangkat);
formKonfirmasi.append(strJumlah);
formKonfirmasi.append(strSubTotal);
formKonfirmasi.append(strPotongan);
formKonfirmasi.append(strTotal);
}
private void clearDisplay(){
txtNik.setString("");
txtNama.setString("");
txtUsia.setString("");
txtJumlahTiket.setString("");
dateKeberangkatan.setDate(null);
choiceJenisKelamin.setSelectedIndex(0,true);
choiceKelas.setSelectedIndex(0,true);
jumlah = 0;
harga = potongan = total = subTotal = 0;
formKonfirmasi.deleteAll();
}
private String formatTanggalOrder(){
Calendar calendar = Calendar.getInstance();
Date tanggalOrder = dateKeberangkatan.getDate();
calendar.setTime(tanggalOrder);
int hari = calendar.get(Calendar.DAY_OF_MONTH);
int noBulan = calendar.get(Calendar.MONTH);
int tahun = calendar.get(Calendar.YEAR);
String[] namaBulan = {
"Januari","Pebruari","Maret","April","Mei","Juni",
"Juli","Agustus","September","Oktober","Nopember",
"Desember"
};
String bulan = namaBulan[noBulan];
String result = hari + "-" + bulan + "-" + tahun;
return result;
}
}