Help with java gui and inheritance
Hi. I am trying to use inheritance in my payroll program. I want to calculate the CPP amount in a different class, and send it back to the main program. But I keep getting th error:
1 error found:
File: E:\Payroll Program\Payrollclear.java [line: 146]
Error: E:\Payroll Program\Payrollclear.java:146: cannot find symbol
symbol : class CandaPensionPlanD
location: class Payrollclear.NetPay
Here is my code:
Code:
//CPP class
public class CandaPensionPlanDeduction {
public double CandaPensionPlanD(double x, double cppAmount){
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;
} return(cppAmount);
}
}
//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 button that will display the charity */
charityB = new JButton("Charity");
charityB.addActionListener(new Charity());
contentPane.add(charityB);
/* 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));
}
}
/*
* Charity class that calculates and displays the Charity
*/
class Charity implements ActionListener {
public void actionPerformed(ActionEvent event) {
String g8 = wageT.getText();
String g9 = hoursT.getText();
String g10 = charityT.getText();
double charity = 0.0;
double y = (Double.parseDouble(g8) * Double.parseDouble(g9)) * 2.00;
charity = (Double.parseDouble(g10)/100) * y;
stat.setText(" Charity = $" + Double.toString(charity));
}
}
/*
* 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 cppAmount = 0;
double charity = 0.0;
double x = (Double.parseDouble(g5) * Double.parseDouble(g6)) * 2.00;
cppAmount = new CandaPensionPlanD(x, cppAmount);
//Calculate EI
double s = x * 2.00;
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;
}else if (s >= 2178.00&& s <=2178.44 ) {
ei = 49.01;
}
charity = (Double.parseDouble(g7)/100) * x;
net = (x - charity);
net = (net - cppAmount);
net = (net - ei);
stat.setText(" Net Pay = $" + Double.toString(net));
}
}
/**
* Create and show the GUI.
*/
private static void runGUI() {
JFrame.setDefaultLookAndFeelDecorated(true);
Payrollclear myGrade = new Payrollclear();
}
/*
* main method of the program
*/
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
runGUI();
}
});
}
}