-1

the actual question is: Develop a client/server application that calculates the pay for employees. Some employees are permanent and others are casual.

Permanent employees have a set annual salary and are eligible for sick leave and annual leave.

Casual employees are paid an hourly rate for the actual hours they worked.

Employees are paid fortnightly.

Client side of the application is to gather information about the employee and send it to the server that will calculate the gross pay, tax paid and net pay.

This information will be sent back to the client to be displayed.

Client side interface GUI that allows the user to choose between permanent or casual. If permanent then the user is asked to enter the employee’s name, id number, annual salary and have drop down list for leave taken that defaults to none but annual or sick can be chosen. If either is chosen then the user will be asked how many days.

If casual then the employee’s name, id number, pay rate and hours worked are entered. The formula to calculate tax is the same for both categories of employees. These figures are per fortnight.

First $700 is tax free anything earned over $700 up to $1500 is taxed at 19c per dollar and any amount over $1500 is taxed 38c per dollar. Application is to include data validation. This should be done before the data is sent to the server. All number entries should be greater than 0 and hours worked for casuals must be five or more and less than 72. A message should be shown to the user and the user should be then able to re-enter the data.

I did the best i could, does anyone or can anyone make this real simple as I have spent hours and hours and hours and more hours and it has issues:

SERVER:

 package com.test;    
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import java.awt.*;
    import javax.swing.*;

    public class PizzaPayServer extends JFrame
    {
        /**
         * 
         */
        private static final long serialVersionUID = 1L;
        //Text area for displaying contents
        private JTextArea jta = new JTextArea();

        public PizzaPayServer()
        {
            //Place text area on the frame
            getContentPane().setLayout(new BorderLayout());
            getContentPane().add(new JScrollPane(jta), BorderLayout.CENTER);

            setTitle("PizzaPayServer");
            setSize(500, 300);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setVisible(true); // It is necessary to show the frame here!
        }

        public static void main(String[] args) 
        {
            ServerSocket serverSocket;
            Socket socket;
            DataInputStream inputFromClient;
            DataOutputStream outputToClient;

            String  empname;


            int empid;
            double hours;
            double payrate;
            double salary;
            double grossPay;
            double netPay;
            double tax;

            PizzaPayServer theServer = new PizzaPayServer();

            try
            {
                // Create a server socket
                serverSocket = new ServerSocket(8010);
                theServer.jta.append("Server started at " + new Date() + '\n');

                //Listen for a connection request
                socket = serverSocket.accept();

                //Create data input and output streams
                inputFromClient = new DataInputStream(socket.getInputStream());
                outputToClient = new DataOutputStream(socket.getOutputStream());



                while (true)
                {

                    hours=0;
                    payrate=0;
                    //Receive employee name from client
                    empname = inputFromClient.readUTF();
                    //Receive employee id from client
                    empid = inputFromClient.readInt();
                    //Receive payrate from client

                    //Receive hours from client
                    tax=0;
                    netPay=0;
                    salary=0;

                    String[] parts = empname.split(",");
                    String part1 = parts[0]; 
                    String part2 = parts[1]; 

                    if (part2.equals("c")){
                        payrate = inputFromClient.readDouble();
                        hours = inputFromClient.readDouble();
                    //Compute pay
                    grossPay = payrate * hours;
                    if(grossPay<=700)
                        tax=0;
                    else
                        if(grossPay<=1500)
                            tax=(grossPay-700) *0.19;
                            else
                                tax=((grossPay-1500) *0.38) + (800 *0.19);
                    netPay= grossPay-tax;
                    //Send pay back to client
                    outputToClient.writeDouble(netPay);
                    outputToClient.writeUTF(empname);

                    outputToClient.writeInt(empid);



                    theServer.jta.append("Employee Name recieved from client: " + part1 + '\n');
                    theServer.jta.append("Employee ID recieved from client: " + empid + '\n');
                    theServer.jta.append("Payrate recieved from client: " + payrate + '\n');
                    theServer.jta.append("Hours recieved from client: " + hours + '\n');
                    theServer.jta.append("Pay Calculated and Sent: " + netPay + '\n');
                    }

                    //perminPayClient Method
                    if (part2.equals("p")){
                        payrate = inputFromClient.readDouble();

                        //Compute pay

                        salary=payrate;

                        if(salary<=700)
                            tax=0;
                        else
                            if(salary<=1500)
                                tax=(salary-700) *0.19;
                                else
                                    tax=((salary-1500) *0.38) + (800 *0.19);
                        netPay= salary/26 -tax;

                        //Send pay back to client
                        outputToClient.writeDouble(salary);
                        outputToClient.writeUTF(empname);

                        outputToClient.writeInt(empid);



                        theServer.jta.append("Employee Name recieved from client: " + part1 + '\n');
                        theServer.jta.append("Employee ID recieved from client: " + empid + '\n');
                        theServer.jta.append("Salary recieved from client: " + salary + '\n');
                        theServer.jta.append("Pay Calculated and Sent: " + netPay + '\n');

                        }
                    }



            }


            catch(IOException ex)
            {
                System.err.println("Catch While");
            }

            System.exit(0);

                }}

MAIN:

 package com.test;
 import java.awt.EventQueue;
 import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.border.EmptyBorder;
    import javax.swing.JButton;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import javax.swing.JLabel;
    import java.awt.Font;
    import java.awt.Color;
    import javax.swing.ImageIcon;

    public class Main extends JFrame {

        /**
         * 
         */
        private static final long serialVersionUID = 1L;
        private JPanel contentPane;

        /**
         * Launch the application.
         */
        public static void main(String[] args) {
            EventQueue.invokeLater(new Runnable() {
                public void run() {
                    try {
                        Main frame = new Main();
                        frame.setVisible(true);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
        }

        /**
         * Create the frame.
         */
        public Main() {
            setTitle("Casey Pizza Pay System");
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setBounds(100, 100, 276, 406);
            contentPane = new JPanel();
            contentPane.setBackground(new Color(255, 255, 153));
            contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
            setContentPane(contentPane);

            JButton btnCasEmp = new JButton("Casual Employee");
            btnCasEmp.setFont(new Font("Tahoma", Font.BOLD, 12));
            btnCasEmp.setBounds(34, 207, 197, 32);
            btnCasEmp.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent arg0) 
                {
                    PizzaPayClient nw = new PizzaPayClient();
                    nw.setVisible(true); //Opens new screen place order
                }
            });
            contentPane.setLayout(null);
            contentPane.add(btnCasEmp);

            JButton btnPerEmp = new JButton("Permament Employee");
            btnPerEmp.setFont(new Font("Tahoma", Font.BOLD, 12));
            btnPerEmp.setBounds(34, 262, 197, 32);
            btnPerEmp.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent arg0) 
                {
                    PerminPayClient nw1 = new PerminPayClient();
                    nw1.setVisible(true); //Opens new screen place order
                }
            });
            contentPane.add(btnPerEmp);

            JLabel lblCaseysPizza = new JLabel("  Casey's Pizza");
            lblCaseysPizza.setBackground(new Color(255, 255, 153));
            lblCaseysPizza.setForeground(Color.RED);
            lblCaseysPizza.setFont(new Font("Algerian", Font.BOLD, 24));
            lblCaseysPizza.setBounds(24, 11, 207, 32);
            contentPane.add(lblCaseysPizza);

            JLabel lblNewLabel = new JLabel("New label");
            lblNewLabel.setIcon(new ImageIcon("C:\\Users\\Little Beast\\workspace\\PizzaPaySystem\\pizzaplace2.jpg"));
            lblNewLabel.setBounds(34, 66, 197, 105);
            contentPane.add(lblNewLabel);

            JLabel lblGreet = new JLabel("  Pay System v1.0");
            lblGreet.setFont(new Font("Algerian", Font.PLAIN, 12));
            lblGreet.setBounds(69, 41, 116, 14);
            contentPane.add(lblGreet);

            JLabel lblSelect = new JLabel("Please Select...");
            lblSelect.setForeground(Color.RED);
            lblSelect.setFont(new Font("Algerian", Font.PLAIN, 12));
            lblSelect.setBounds(82, 182, 103, 14);
            contentPane.add(lblSelect);

            JButton btnHelp = new JButton("");
            btnHelp.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent arg0) 
                {
                    HelpMenu nw3 = new HelpMenu();
                    nw3.setVisible(true); //Opens new screen place order
                }
            });
            btnHelp.setBackground(Color.PINK);
            btnHelp.setIcon(new ImageIcon("C:\\Users\\Little Beast\\workspace\\PizzaPaySystem\\help.png"));
            btnHelp.setBounds(34, 325, 197, 32);
            contentPane.add(btnHelp);
        }
    }

Casual:

package com.test;

import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

    public class PizzaPayClient extends JFrame implements ActionListener 
    {
        /**
         * 
         */
        //Variables

        private static final long serialVersionUID = 1L;
        //Text fields for receiving employee name, employee id, payrate, hours
        private  JTextField jtfEname = new JTextField();
        private JTextField jtfEid = new JTextField();
        private JTextField jtfPayRate = new JTextField();
        //Buttons for onClick Listeners
        private JButton calculate = new JButton("Calculate Pay");
        private JButton clear = new JButton("Clear");
        private JButton exit = new JButton("Exit");

        // IO Streams
        private DataOutputStream outputToServer;
        private DataInputStream inputFromServer;
        private Socket sock;
        private LayoutManager FlowLayout;
        private final JTextField jtfHours = new JTextField();
        private final JTextArea jta = new JTextArea();
        private final JLabel lblNewLabel = new JLabel("New label");

        public PizzaPayClient()
        {
            // Panel p to hold the label and text field
            jtfHours.setHorizontalAlignment(SwingConstants.LEFT);
            jtfHours.setBounds(134, 84, 140, 20);
            jtfHours.setColumns(10);
            JPanel p = new JPanel();
            p.setBackground(new Color(255, 255, 102));
            p.setBounds(0, 0, 501, 453);
            p.setLayout(FlowLayout);
            p.setLayout(null);
            p.setLayout(null);
            p.setLayout(null);
            p.setLayout(null);
            p.setLayout(null);
            JLabel lblEmpName = new JLabel("Employee Name:");
            lblEmpName.setFont(new Font("Tahoma", Font.BOLD, 12));
            lblEmpName.setBounds(9, 9, 103, 14);
            p.add(lblEmpName);
            exit.setFont(new Font("Tahoma", Font.BOLD, 12));
            exit.setBounds(376, 126, 108, 23);
            p.add(exit);
            exit.addActionListener(this);
            JLabel lblEmpId = new JLabel("Employee ID:");
            lblEmpId.setFont(new Font("Tahoma", Font.BOLD, 12));
            lblEmpId.setBounds(10, 37, 102, 14);
            p.add(lblEmpId);
            jtfEid.setBounds(134, 34, 140, 20);
            p.add(jtfEid);
            JLabel lblPayRate = new JLabel("Enter PayRate:");
            lblPayRate.setFont(new Font("Tahoma", Font.BOLD, 12));
            lblPayRate.setBounds(9, 62, 103, 14);
            p.add(lblPayRate);
            jtfPayRate.setBounds(133, 59, 141, 20);
            p.add(jtfPayRate);
            jtfPayRate.setHorizontalAlignment(SwingConstants.LEFT);
            jtfPayRate.addActionListener(this);
            jtfEname.setBounds(134, 6, 140, 20);
            p.add(jtfEname);
            jtfEname.setHorizontalAlignment(SwingConstants.LEFT);

            // Register Listener/s
            jtfEname.addActionListener(this);
            getContentPane().setLayout(null);
            JLabel lblHours = new JLabel("Enter Hours:");
            lblHours.setFont(new Font("Tahoma", Font.BOLD, 12));
            lblHours.setBounds(9, 87, 103, 14);
            p.add(lblHours);
            calculate.setFont(new Font("Tahoma", Font.BOLD, 12));
            calculate.setBounds(73, 126, 180, 23);
            p.add(calculate);
            clear.setFont(new Font("Tahoma", Font.BOLD, 12));
            clear.setBounds(263, 126, 103, 23);
            p.add(clear);
            jtfEid.setHorizontalAlignment(SwingConstants.LEFT);
            getContentPane().add(p);

            p.add(jtfHours);
            jta.setLineWrap(true);
            jta.setRows(20);
            jta.setBounds(10, 160, 480, 282);

            p.add(jta);
            lblNewLabel.setIcon(new ImageIcon("C:\\Users\\Little Beast\\workspace\\PizzaPaySystem\\pizzaplace2.jpg"));
            lblNewLabel.setBounds(298, 9, 192, 106);

            p.add(lblNewLabel);
            jtfEid.addActionListener(this);
            calculate.addActionListener(this);
            clear.addActionListener(this);
            setTitle("Casual Pay Entry");
            setSize(517, 491);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setVisible(true); // It is necessary to show the frame here!

            try
            {
                //Create a socket to connect to the server
                sock = new Socket("localhost", 8010);

                //Create an input stream to receive data from the server
                inputFromServer = new DataInputStream(sock.getInputStream());

                //Create an output stream to send data to the server
                outputToServer = new DataOutputStream(sock.getOutputStream());
            }
            catch (IOException ex)
            {
                jta.append(ex.toString() + '\n');
            }
        }

        /**
         * @param args
         */
        public static void main(String[] args) 
        {
            new PizzaPayClient();
        }

        public void actionPerformed(ActionEvent e) {

            //String actionCommmand = e.getActionCommand();
            if (e.getSource().equals(calculate)) {
                try {
                    //Get the employee name, employee id, payrate, hours from the text fields

                    String empname = jtfEname.getText();
                    //If no name is entered display pop up dialog box.
                    if(empname.length()==0)
                        JOptionPane.showMessageDialog(null, "Please Enter Your Name");


                    int empid = 0; 
                    try {
                        empid = Integer.parseInt(jtfEid.getText().trim());
                      //If no employee Id is entered display pop up dialog box
                    } catch(NumberFormatException nfe) {
                        JOptionPane.showMessageDialog(null, "Please Enter Your Id");
                    }

                    double payrate = 0;
                    try {
                        payrate = Double.parseDouble(jtfPayRate.getText().trim());
                      //If no payrate is entered display pop up dialog box
                    } catch (NumberFormatException nfe) {
                        JOptionPane.showMessageDialog(null, "Please Enter Your Pay Rate");
                    }

                    double hours = 0;
                    try {
                        hours = Double.parseDouble(jtfHours.getText().trim());
                    //If hours are less than 5 or over 72 display pop up dialog box
                    if(hours <5)
                        JOptionPane.showMessageDialog(null, "Must be 5 hours or greater");
                    if(hours >72)
                        JOptionPane.showMessageDialog(null, "Hours must be less than 72");
                    //If no hours are entered display pop up dialog box
                    } catch (NumberFormatException nfe) {
                        JOptionPane.showMessageDialog(null, "Please Enter Your Hours");
                    }

                    String oldName=empname;

                    //send the employee name, employee id, payrate, hours to the server
                    outputToServer.writeUTF(empname+",c");
                    outputToServer.writeInt(empid);
                    outputToServer.writeDouble(hours);
                    outputToServer.writeDouble(payrate);
                    outputToServer.flush();

                    //Get pay from the server
                    double pay = inputFromServer.readDouble();
                    empname = inputFromServer.readUTF();


                    //Display to the text area
                    jta.append("Name " + oldName + '\n');
                    jta.append("ID " + empid + '\n');
                    jta.append("PayRate is " + payrate + '\n');
                    jta.append("Hours is " + hours + '\n');
                    jta.append("Total Pay "
                            + pay + '\n');
                    jtfEname.setText("");
                    jtfEid.setText("");
                    jtfPayRate.setText("");
                    jtfHours.setText("");


                }
                catch (IOException ex) {
                    System.err.println(ex);
                }
            }
            //Clear the fields - reset
            else if (e.getSource() == clear)    
            {


                jta.setText("");
            }

            else if (e.getSource() == exit)
            {
                try
                {
                    System.exit(0);
                    sock.close();
                }
                catch (Exception ex)
                {
                    System.out.println("Client: exception " + ex);
                }

                }
            }

    }

Permin:

package com.test;

import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

    public class PerminPayClient extends JFrame implements ActionListener 
    {
        /**
         * 
         */
        //Variables

        private static final long serialVersionUID = 1L;
        //Text fields for receiving employee name, employee id, payrate, hours
        private  JTextField jtfEname = new JTextField();
        private JTextField jtfEid = new JTextField();
        private JTextField jtfPayRate = new JTextField();
        //Buttons for onClick Listeners
        private JButton calculate = new JButton("Calculate Pay");
        private JButton clear = new JButton("Clear");
        private JButton exit = new JButton("Exit");

        // IO Streams
        private DataOutputStream outputToServer;
        private DataInputStream inputFromServer;
        private Socket sock;
        private LayoutManager FlowLayout;
        private final JTextArea jta = new JTextArea();
        private final JLabel lblNewLabel = new JLabel("New label");

        public PerminPayClient()
        {
            JPanel p = new JPanel();
            p.setBackground(new Color(255, 255, 102));
            p.setBounds(0, 0, 501, 453);
            p.setLayout(FlowLayout);
            p.setLayout(null);
            p.setLayout(null);
            p.setLayout(null);
            p.setLayout(null);
            p.setLayout(null);
            JLabel lblEmpName = new JLabel("Employee Name:");
            lblEmpName.setFont(new Font("Tahoma", Font.BOLD, 12));
            lblEmpName.setBounds(9, 9, 103, 14);
            p.add(lblEmpName);
            exit.setFont(new Font("Tahoma", Font.BOLD, 12));
            exit.setBounds(376, 126, 108, 23);
            p.add(exit);
            exit.addActionListener(this);
            JLabel lblEmpId = new JLabel("Employee ID:");
            lblEmpId.setFont(new Font("Tahoma", Font.BOLD, 12));
            lblEmpId.setBounds(10, 37, 102, 14);
            p.add(lblEmpId);
            jtfEid.setBounds(134, 34, 140, 20);
            p.add(jtfEid);
            JLabel lblPayRate = new JLabel("Enter Salary:");
            lblPayRate.setFont(new Font("Tahoma", Font.BOLD, 12));
            lblPayRate.setBounds(9, 62, 103, 14);
            p.add(lblPayRate);
            jtfPayRate.setBounds(133, 59, 141, 20);
            p.add(jtfPayRate);
            jtfPayRate.setHorizontalAlignment(SwingConstants.LEFT);
            jtfPayRate.addActionListener(this);
            jtfEname.setBounds(134, 6, 140, 20);
            p.add(jtfEname);
            jtfEname.setHorizontalAlignment(SwingConstants.LEFT);

            // Register Listener/s
            jtfEname.addActionListener(this);
            getContentPane().setLayout(null);
            calculate.setFont(new Font("Tahoma", Font.BOLD, 12));
            calculate.setBounds(73, 126, 180, 23);
            p.add(calculate);
            clear.setFont(new Font("Tahoma", Font.BOLD, 12));
            clear.setBounds(263, 126, 103, 23);
            p.add(clear);
            jtfEid.setHorizontalAlignment(SwingConstants.LEFT);
            getContentPane().add(p);
            jta.setLineWrap(true);
            jta.setRows(20);
            jta.setBounds(10, 160, 480, 282);

            p.add(jta);
            lblNewLabel.setIcon(new ImageIcon("C:\\Users\\Little Beast\\workspace\\PizzaPaySystem\\pizzaplace2.jpg"));
            lblNewLabel.setBounds(298, 9, 192, 106);

            p.add(lblNewLabel);
            jtfEid.addActionListener(this);
            calculate.addActionListener(this);
            clear.addActionListener(this);
            setTitle("Casual Pay Entry");
            setSize(517, 491);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setVisible(true); // It is necessary to show the frame here!

            try
            {
                //Create a socket to connect to the server
                sock = new Socket("localhost", 8010);

                //Create an input stream to receive data from the server
                inputFromServer = new DataInputStream(sock.getInputStream());

                //Create an output stream to send data to the server
                outputToServer = new DataOutputStream(sock.getOutputStream());
            }
            catch (IOException ex)
            {
                jta.append(ex.toString() + '\n');
            }
        }

        /**
         * @param args
         */
        public static void main(String[] args) 
        {
            new PerminPayClient();
        }

        public void actionPerformed(ActionEvent e) {

            //String actionCommmand = e.getActionCommand();
            if (e.getSource().equals(calculate)) {
                try {
                    //Get the Employee Name, Employee Id, Pay Rate(Salary) from the text fields

                    String empname = jtfEname.getText();
                    //If no Employee Name is entered display pop up dialog box.
                    if(empname.length()==0)
                        JOptionPane.showMessageDialog(null, "Please Enter Your Name");


                    int empid = 0; 
                    try {
                        empid = Integer.parseInt(jtfEid.getText().trim());
                      //If no Employee Id is entered display pop up dialog box
                    } catch(NumberFormatException nfe) {
                        JOptionPane.showMessageDialog(null, "Please Enter Your Id");
                    }   


                    double payrate = 0;
                    try {
                        payrate = Double.parseDouble(jtfPayRate.getText().trim());
                    //If no pay rate is entered display pop up dialog box
                    } catch (NumberFormatException nfe) {
                        JOptionPane.showMessageDialog(null, "Please Enter Your Annual Salary");
                    }

                    //send the Employee Name, Employee Id, Pay Rate to the server
                    String oldName=empname;

                    outputToServer.writeUTF(empname+",p");
                    outputToServer.writeInt(empid);
                    outputToServer.writeDouble(payrate);
                    outputToServer.flush();

                    //Get pay from the server
                    double pay = inputFromServer.readDouble();
                    empname = inputFromServer.readUTF();


                    //Display to the text area
                    jta.append("Name " + oldName + '\n');
                    jta.append("ID " + empid + '\n');
                    jta.append("Salary is " + payrate + '\n');
                    jta.append("Total Pay "
                            + pay + '\n');

                }
                catch (IOException ex) {
                    System.err.println(ex);
                }
            }
            //Clear the fields - reset
            else if (e.getSource() == clear)    
            {
                jtfEname.setText("");
                jtfEid.setText("");
                jtfPayRate.setText("");

                jta.setText("");
            }

            //Button exit function to exit program
            else if (e.getSource() == exit)
            {
                try
                {
                    System.exit(0);
                    sock.close();
                }
                catch (Exception ex)
                {
                    System.out.println("Client: exception " + ex);
                }

                }
            }

    }
braX
  • 11,506
  • 5
  • 20
  • 33
CaseyT
  • 15
  • 1
  • 7
  • Did I understand it right? You have a clear button that clears the input fields? But when clicking it in the designer view, it shows the above code? – lxcky Sep 01 '14 at 09:57
  • when I double click the clear button in designer view to code the action performed it takes me to this part of the source code. I manually added the clear code down the bottom near the exit code and it does clear the fields however when i re enter name, id, etc and click calculate again it crashes freezes – CaseyT Sep 01 '14 at 10:05
  • Does this mean you only have a single method for three buttons? – lxcky Sep 01 '14 at 10:09
  • Yes also for some reason when no data is entered in the textfields for calculation to the jta(JtextArea) the validation comes up no worries in a messageDialog however when you press ok the data is still there and calculation it does not reset the textfields and jtextarea to blank – CaseyT Sep 01 '14 at 10:13

3 Answers3

0

I'm not really sure what's wrong but one of the things I see is your condition:

if (e.getSource() == calculate) {
    ...
} else if (e.getSource() == clear) { //change it to else if since every click only comes from one source.
    ...
} else if (e.getSource() == exit)

And are calculate, clear, and exit variables? If no, then it should not be like that.

lxcky
  • 1,668
  • 2
  • 13
  • 26
  • yes and I tried this still for some reason this is the output screen the first time works correctly; Name chris ID 76 PayRate is 10.0 Hours is 10.0 Total Pay 100.0 I click clear it resets the fields to blank then re enter and this is the second output and program crashes:Name tom ID 88 PayRate is 12.0 Hours is 13.0 Total Pay 1.6180540078E-312 Then I press clear again re enter details click calculate and it crashes – CaseyT Sep 01 '14 at 10:20
  • Please add the stack trace to your question so that I'll know we're exactly it went wrong. – lxcky Sep 01 '14 at 10:24
  • It just freezes nothing here is all the stack trace: java.io.UTFDataFormatException: malformed input around byte 2 – CaseyT Sep 01 '14 at 11:23
0

it's hard to tell without seeing the rest of your code but there could be an issue with your comparison statements? sounds weird but I have had issues where if you use == over .equals() you can have some weird stuff happen in your IF statements.

try:

if (e.getSource().equals(calculate)) {

I've been told that == is very weak and only good for comparing int values. In most other cases you should always use .equals()

  • thank you I have posted my full code however still having trouble. Basically I enter details click calculate and it works fine then i click clear to clear the textfields and textarea, reenter details click calculate and it gives me a strange total pay number. Then finally I click clear again it clears the fields, i re enter details and click calculate and it freezes / crashes. – CaseyT Sep 01 '14 at 22:59
  • I reposted the question and my codes if anyone can make this work awesome as i keep experiencing problems – CaseyT Sep 02 '14 at 11:11
0

Sorry but I can't write a comment reply because I'm too new to this site. It looks like in your actionPerformed for calculate it checks validation but still appends the data. I think you might need to wrap validation code around appending of the data. from what I can see you check if user input is entered and prompt the user accordingly if they haven't and then after all the checks it just appends any way.

  • Thank you I will check it someone else has suggested that you cant append more than one to a socket hence why it is crashing. How do you do a wrap validation? – CaseyT Sep 02 '14 at 05:29
  • yay I can post comments now! hehe it's all good. I read some of your coding wrong and your try/catch should catch any missing inputs. – user3126322 Sep 02 '14 at 08:50
  • Its crazy it has been fustrating me badly...I even tried to re create it from scratch. I have tried my hardest, I know code after code but implementing it all together is kind of confusing. I think also it is lack of socket knowledge. I have done ok though it is for a class project and we were given limited information, knowledge and asked to outsource. – CaseyT Sep 02 '14 at 10:53
  • I have reposted the actual question perhaps that could be of help, all i know this sucks I have tried and tried with the knowledge i know and got this far but yeah sure there is a easier way...if anyone can recreate this or make it simple as that would be greatly appreciated – CaseyT Sep 02 '14 at 11:10