pbl kerja

Embed Size (px)

Citation preview

  • 8/18/2019 pbl kerja

    1/3

    /* * Main.java * * Created on April 2, 2016, 9:45 PM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */

    package grr;import javax.swing.JOptionPane;/** * * @author Dell */public class Main { 

    /** Creates a new instance of Main */  public Main() {  } 

    /**  * @param args the command line arguments  */

      public static void main(String[] args) {  // TODO code application logic here  String output1 ,output2 ,output3 ,output4 ,output5;  int choice; 

    output1 = JOptionPane.showInputDialog( null, "Enter customer name"); 

    output2= JOptionPane.showInputDialog( null, "Enter your customer ID"); 

    output3= JOptionPane.showInputDialog( null, "Enter your address");  {  choice =Integer.parseInt(JOptionPane.showInputDialog ("What do you want to calculate? \n[1] Water Bill \n[2] Electricity Bill"));

      switch(choice)  {  case 1:  int w_units,water_input;  double water_bill=0;  String water = JOptionPane.showInputDialog( null, "Water consumed:"); 

    {water_input = Integer.parseInt(water);

     if (water_input>0 &&water_input20 && water_input30)  {  w_units=water_input-30;  water_bill=(0.6*20)+(10*0.7)+(w_units*0.8);

  • 8/18/2019 pbl kerja

    2/3

      }  else  {  JOptionPane.showMessageDialog(null,"Wrong Unit Consumed Entered","ERROR",JOptionPane.ERROR_MESSAGE);  } 

    JOptionPane.showMessageDialog(null,"Hello,\n"+output1+"\n"+output2+"\n"+output3+"\n\nAmount of Electricity Bill is RM"+water_bill,"BILL CALCULATOR",JOptionPane.INFORMATION_MESSAGE);  break;

    }  case 2:  int e_units,elec_input;  double elec_bill=0;  String elec = JOptionPane.showInputDialog( null, "Electric consumed:"); 

    {elec_input = Integer.parseInt(elec);

     if (elec_input>0 &&elec_input200 && elec_input300 && elec_input600)  {

      e_units=elec_input-600;  elec_bill=(0.21*200)+(0.33*100)+(0.51*300)+(e_units*0.54);  }  else  {  JOptionPane.showMessageDialog(null,"Wrong Unit Consumed Entered","ERROR",JOptionPane.ERROR_MESSAGE);  } 

    JOptionPane.showMessageDialog(null,"Hello,\n"+output1+"\n"+output2+"\n"+output3+"\n\nAmount of Electricity Bill is RM"+elec_bill,"BILL CALCULATOR",JOptionPane.INFORMATION_MESSAGE);  break;

    default:  JOptionPane.showMessageDialog(null,"Invalid Choice!","ERROR",JOptionPa

    ne.ERROR_MESSAGE);  break;}

      }  }}

  • 8/18/2019 pbl kerja

    3/3