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));
             }
avatar chrrriann
@chrrriann

15 Kontribusi 2 Poin

Diperbarui 2 tahun yang lalu

2 Jawaban:

<div>hai <a href="https://sekolahkoding.com/user/chrrriann">@chrrriann</a><br><br>coba pada bagian&nbsp;</div><pre>outjumlah.setText("Jumlah Porsi : " + jumlah);</pre><div><br>diganti menjadi&nbsp;</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(&quot;&quot;); // del text input

    outNama.setText(&quot;Nama Pemesan : &quot;);

    cbS.setSelected(false);

    cbL.setSelected(false);

    cbB.setSelected(false);

    cbSp.setSelected(false);

    tfjml1.setText(&quot;&quot;);

    tfjml2.setText(&quot;&quot;);

    tfjml3.setText(&quot;&quot;);

    tfjml4.setText(&quot;&quot;);

    outjumlah.setText(&quot;Jumlah porsi  : &quot;);

    tajenis.setText(&quot;&quot;);

    outtotal.setText(&quot;&quot;);

    tfbayar.setText(&quot;&quot;);

    outkembali.setText(&quot;&quot;);

}

private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {                                     

    if (cbS.isSelected() == false &amp;amp;&amp;amp; cbL.isSelected()==false &amp;amp;&amp;amp; cbB.isSelected()==false &amp;amp;&amp;amp; cbSp.isSelected()==false){

        JOptionPane.showMessageDialog(null, &quot;Makanan Belum Dipesan&quot;,&quot;Warning&quot;,JOptionPane.WARNING_MESSAGE);
    
    } else { //Tanpa Perlu Else IF

        isJenis = &quot;&quot;;
        
        //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 += &quot;\n&quot; + cbL.getText();
            total += (hL * Integer.parseInt(tfjml2.getText())); //Hitung Field Lasagna * Jumlah Porsi Lasagna
            jumlah += Integer.parseInt(tfjml2.getText())
        }

        if(cbB.isSelected()) {
            isJenis += &quot;\n&quot; + cbB.getText();
            total += (hB * Integer.parseInt(tfjml3.getText())); //Hitung Field Burger * Jumlah Porsi Burger
            jumlah += Integer.parseInt(tfjml3.getText())
        }

        if(cbSp.isSelected()) {
            isJenis += &quot;\n&quot; + cbSp.getText();
            total += (hSp * Integer.parseInt(tfjml4.getText())); //Hitung Field Spagetti * Jumlah Porsi Spagetti
            jumlah += Integer.parseInt(tfjml4.getText())
        }

        //menampilkan nama pemesan
        outNama.setText(&quot;Nama Pemesan : &quot;  +tfNama.getText());
        
        //menampilkan jumla porsi
        outjumlah.setText(&quot;Jumlah Porsi  : &quot; + String.valueOf(jumlah));
        
        //Tampilkan Jenis
        tajenis.setText(isJenis);
            
        //menampilkan total bayar
        outtotal.setText(String.valueOf(total));

        //Script Hitung Kembalian Silahkan dilanjutkan sendiri
    }
}

}</pre>

avatar tantootnat
@tantootnat

14 Kontribusi 11 Poin

Dipost 2 tahun yang lalu

<div>udah dicoba tapi tetep gabisa muncul kalo milih 3 tapi kalo milih semua muncul :)</div>

avatar chrrriann
@chrrriann

15 Kontribusi 2 Poin

Dipost 2 tahun yang lalu

Tanggapan

sudah saya edit jawabannya saya, dicoba lagi

okayy makasih yaaa :)

Login untuk ikut Jawaban