Results 1 to 2 of 2
  1. #1
    sssss is offline Member
    Join Date
    Jan 2011
    Posts
    12
    Rep Power
    0

    Default GUI AND INHERITANCE program help

    Hi. I have this program where I am using inheritance, to get the values for CPP and EI. The program works fine but everytime I try to calculate net pay, which is cpp- charity - ei, a new clank GUI keeps opening up and I have no idea why...
    here is the code. any help will be appreciated:

    Java Code:
    //CPP CLASS: 
    public class CanadaPensionPlanDeduction extends Payrollclear{
      public double CanadaPensionPlanDeduction(double x){ 
      double cppAmount = 0;
      if (x >= 1513.10 && x <=1523.09) {
        cppAmount = 59.49;
        
      } else if (x >= 1523.10 && x <=1533.09) {
        cppAmount = 59.92;
        
      } else if (x >= 1533.10 && x <=1543.09 ){
        cppAmount = 60.35;
        
      } else if (x >= 1543.10 && x <=1553.09 ){
        cppAmount = 60.78;
        
      } return(cppAmount);
    }
    }
    Java Code:
    //EI class
    public class EmploymentInsuranceDeduction extends Payrollclear{
      public double EmploymentInsuranceDeduction(double s){
        double ei = 0.0;
        if (s >=2176.23 && s <=2176.66 ) {
          ei = 48.97;
        }else if (s >= 2167.67&& s <= 2177.11) {
          ei = 48.98;
        }else if (s >= 2177.12&& s <=2177.55 ) {
          ei = 48.99;
        }else if (s >= 2177.56&& s <=2177.99 ) {
          ei = 49.00;
        }return(ei);
    }
    }

    Java Code:
    //Main Program
    
    //Gross and Net biweekely salary
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;  
    import java.lang.String; 
    import java.io.*;
    //Net = after
    //gross = before
    public class Payrollclear {
      JFrame frame;
      JPanel contentPane;
      JLabel prompt1, prompt2, prompt3, prompt4, prompt5, stat;
      JTextField name, wageT, hoursT, charityT;
      JButton gross, net, cpp, eI, charityB, save;
      
      public Payrollclear(){
        /* Create and set up the frame */
        frame = new JFrame("Payroll Calculator");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        /* Create a content pane with a GridLayout and empty borders */
        contentPane = new JPanel();
        contentPane.setLayout(new GridLayout(0, 2, 10, 5));
        contentPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
        contentPane.setBackground(Color.white);
        
        /* Create and add a prompt and then a text field */
        prompt1 = new JLabel("Enter the employee name: ");
        contentPane.add(prompt1);
        name = new JTextField(10);
        contentPane.add(name);
        
        /* Create and add a prompt and then a text field */
        prompt1 = new JLabel("Enter the hourly wage: ");
        contentPane.add(prompt1);
        
        wageT = new JTextField(10);
        contentPane.add(wageT);
        
        /* Create and add a second prompt and then a text field */
        prompt2 = new JLabel("Enter the hours worked: ");
        contentPane.add(prompt2);
        
        hoursT = new JTextField(10);
        contentPane.add(hoursT);
        
        /* Create and add a third prompt and then a text field */
        prompt3 = new JLabel("Enter the charity percentage: ");
        contentPane.add(prompt3);
        
        charityT = new JTextField(10);
        contentPane.add(charityT);
        
        /* Create and add button that will display the gross pay */
        gross = new JButton("Gross Pay");
        gross.addActionListener(new PayCalculator());
        contentPane.add(gross);
        
        /*Create and add button that will display the net pay*/
        net = new JButton("Net Pay");
        net.addActionListener(new NetPay());
        contentPane.add(net);
        
        
        /* Create and add a label that will display stats(whatever is selected) */
        stat = new JLabel(" ");
        stat.setBorder(BorderFactory.createEmptyBorder(15, 0, 15, 0));
        contentPane.add(stat);
        
        /* Add content pane to frame */
        frame.setContentPane(contentPane);
        /* Size and then display the frame. */
        frame.pack();
        frame.setVisible(true);
      }
      
      
      /*
       * PayCalculator class that calculates the gross pay
       */ 
      class PayCalculator implements ActionListener {
        public void actionPerformed(ActionEvent event) {
          String g1 = name.getText();
          String g2 = wageT.getText();
          String g3 = hoursT.getText();
          String g4 = charityT.getText();
          
          double gross = 0;
     
          gross = (Double.parseDouble(g2) * Double.parseDouble(g3))*2.00;
          stat.setText(" Gross Pay = $" + Double.toString(gross));
        }
      }
    
    
       /* 
       * NetPay class that calculates and displays the Net Pay
       */
      class NetPay implements ActionListener {
        public void actionPerformed(ActionEvent event) {
          String g5 = wageT.getText();
          String g6 = hoursT.getText();
          String g7 = charityT.getText();
    
          double net = 0.0;
          double charity = 0.0;
          double x = (Double.parseDouble(g5) * Double.parseDouble(g6)) * 2.00;
          
          //Call CPP class to calculate CPP amount;
          CanadaPensionPlanDeduction cppAmount = new CanadaPensionPlanDeduction();
          double cppa = cppAmount.CanadaPensionPlanDeduction(x);
           
          //Call EI class to calculate EI amount;
          double s = x * 2.00;
          EmploymentInsuranceDeduction eiAmount = new EmploymentInsuranceDeduction();
          double ei = eiAmount.EmploymentInsuranceDeduction(x);
          
          charity = (Double.parseDouble(g7)/100) * x;
          net = (x - charity);
          net = net - cppa;
          net = net - ei;
          stat.setText(" Net Pay = $" + Double.toString(net));
        }
      }
    
       
    
    private static void runGUI() {
      JFrame.setDefaultLookAndFeelDecorated(true);
      Payrollclear myGrade = new Payrollclear();
    }
    
    
      public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
          public void run() {
            runGUI();
          }
        });
      }
    }

  2. #2
    aspire1 is offline Member
    Join Date
    Jan 2011
    Posts
    13
    Rep Power
    0

    Default

    Java Code:
    EmploymentInsuranceDeduction eiAmount = new EmploymentInsuranceDeduction();
    EmploymentInsuracnceDeduction extends Payrollclear which is your GUI bit as does CanadaPensionPlanDeduction class.
    Last edited by aspire1; 01-19-2011 at 06:58 PM. Reason: more info

Similar Threads

  1. JPA Inheritance
    By videanuadrian in forum New To Java
    Replies: 1
    Last Post: 01-10-2011, 06:44 AM
  2. Replies: 4
    Last Post: 07-22-2010, 11:22 AM
  3. Inheritance
    By gpio in forum Advanced Java
    Replies: 14
    Last Post: 11-20-2009, 10:41 AM
  4. inheritance
    By itaipee in forum New To Java
    Replies: 6
    Last Post: 01-20-2009, 08:18 PM
  5. Inheritance Program
    By Schaput in forum New To Java
    Replies: 6
    Last Post: 11-14-2008, 12:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •