Postingan lainnya
Kelas Premium!
Belajar Javascript untuk website
Gunakan kupon "mulaijs" untuk diskon 75 ribu!
menambahkan jumlah porsi
hi saya sedang membuat aplikasi menu restoran sederhana menggunakan netabeans tetapi ketika di jumlah porsi mengalami kendala .
Screenshot (362).png
seharusnya jumlah porsi menjadi 3 tetapi tidak terisi.
public class Restoran extends javax.swing.JFrame {
String jns1, jns2, jns3, jns4;
int hS=50000, hL=75000, hB=40000, hSp=45000, total=0, jlh, bayar, uang, kembalian;
/**
* Creates new form Restoran
*/
public Restoran() {
initComponents();
}
private void resetMouseClicked(java.awt.event.MouseEvent evt) {
tfNama.setText(""); // del text input
outNama.setText("Nama Pemesan : ");
cbS.setSelected(false);
cbL.setSelected(false);
cbB.setSelected(false);
cbSp.setSelected(false);
tfjml1.setText("");
tfjml2.setText("");
tfjml3.setText("");
tfjml4.setText("");
outjumlah.setText("Jumlah porsi : ");
tajenis.setText("");
outtotal.setText("");
tfbayar.setText("");
outkembali.setText("");
}
private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {
//menampilkan nama pemesan
outNama.setText("Nama Pemesan : " +tfNama.getText());
//menampilkan jumlah porsi
int jumlah = Integer.parseInt(tfjml1.getText()) + Integer.parseInt(tfjml2.getText()) + Integer.parseInt(tfjml3.getText()) + Integer.parseInt(tfjml4.getText());
outjumlah.setText("Jumlah Porsi : " + jumlah);
if (cbS.isSelected() == false && cbL.isSelected()==false && cbB.isSelected()==false && cbSp.isSelected()==false){
JOptionPane.showMessageDialog(null, "Makanan Belum Dipesan","Warning",JOptionPane.WARNING_MESSAGE);
}
else if(cbS.isSelected()&&cbL.isSelected()&&cbB.isSelected()&&cbSp.isSelected()){
jns1 = cbS.getText();
jns2 = cbL.getText();
jns3 = cbB.getText();
jns4 = cbSp.getText();
tajenis.setText(jns1+"\n"+jns2+"\n"+jns3+"\n"+jns4);
//menghitung total bayar
total = (hS + hL + hB + hSp);
jlh = Integer.parseInt(tfjml1.getText());
bayar = total * jlh;
//menampilkan total bayar
outtotal.setText(String.valueOf(bayar));
}
else if(cbS.isSelected()&&cbL.isSelected()&&cbB.isSelected()){
jns1 = cbS.getText();
jns2 = cbL.getText();
jns3 = cbB.getText();
tajenis.setText(jns1+"\n"+jns2+"\n"+jns3);
//menghitung total bayar
total = (hS + hL + hB );
jlh = Integer.parseInt(tfjml1.getText());
bayar = total * jlh;
//menampilkan total bayar
outtotal.setText(String.valueOf(bayar));
}
2 Jawaban:
<div>hai <a href="https://sekolahkoding.com/user/chrrriann">@chrrriann</a><br><br>coba pada bagian </div><pre>outjumlah.setText("Jumlah Porsi : " + jumlah);</pre><div><br>diganti menjadi </div><pre>outjumlah.setText("Jumlah Porsi : " + String.valueOf(jumlah));</pre><div><br><br>Full Script</div><pre>public class Restoran extends javax.swing.JFrame {
String isJenis;
int hS=50000, hL=75000, hB=40000, hSp=45000, total=0, jlh, bayar, uang, kembalian, jumlah;
/**
* Creates new form Restoran
*/
public Restoran() {
initComponents();
}
private void resetMouseClicked(java.awt.event.MouseEvent evt) {
tfNama.setText(""); // del text input
outNama.setText("Nama Pemesan : ");
cbS.setSelected(false);
cbL.setSelected(false);
cbB.setSelected(false);
cbSp.setSelected(false);
tfjml1.setText("");
tfjml2.setText("");
tfjml3.setText("");
tfjml4.setText("");
outjumlah.setText("Jumlah porsi : ");
tajenis.setText("");
outtotal.setText("");
tfbayar.setText("");
outkembali.setText("");
}
private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {
if (cbS.isSelected() == false &amp;&amp; cbL.isSelected()==false &amp;&amp; cbB.isSelected()==false &amp;&amp; cbSp.isSelected()==false){
JOptionPane.showMessageDialog(null, "Makanan Belum Dipesan","Warning",JOptionPane.WARNING_MESSAGE);
} else { //Tanpa Perlu Else IF
isJenis = "";
//Make It Simple
if(cbS.isSelected()) {
isJenis += cbS.getText();
total += (hS * Integer.parseInt(tfjml1.getText())); //Hitung Field Steak * Jumlah Porsi Steak
jumlah += Integer.parseInt(tfjml1.getText());
}
if(cbL.isSelected()) {
isJenis += "\n" + cbL.getText();
total += (hL * Integer.parseInt(tfjml2.getText())); //Hitung Field Lasagna * Jumlah Porsi Lasagna
jumlah += Integer.parseInt(tfjml2.getText())
}
if(cbB.isSelected()) {
isJenis += "\n" + cbB.getText();
total += (hB * Integer.parseInt(tfjml3.getText())); //Hitung Field Burger * Jumlah Porsi Burger
jumlah += Integer.parseInt(tfjml3.getText())
}
if(cbSp.isSelected()) {
isJenis += "\n" + cbSp.getText();
total += (hSp * Integer.parseInt(tfjml4.getText())); //Hitung Field Spagetti * Jumlah Porsi Spagetti
jumlah += Integer.parseInt(tfjml4.getText())
}
//menampilkan nama pemesan
outNama.setText("Nama Pemesan : " +tfNama.getText());
//menampilkan jumla porsi
outjumlah.setText("Jumlah Porsi : " + String.valueOf(jumlah));
//Tampilkan Jenis
tajenis.setText(isJenis);
//menampilkan total bayar
outtotal.setText(String.valueOf(total));
//Script Hitung Kembalian Silahkan dilanjutkan sendiri
}
}
}</pre>
<div>udah dicoba tapi tetep gabisa muncul kalo milih 3 tapi kalo milih semua muncul :)</div>