create an object of a class

I am writing a program that calls two other programs, I have all of the written but I am having trouble getting the main program to get and send the right information from the other programs and I was hoping for some help. I can not seem to get it to send the numbers to the wage program or the commission program and have it the values sent back.

this is the main program:
// Tami Hall
// Case Chapter 9
// EmployeePay.java
// Nov 5, 2004

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.applet.*;
import java.lang.*;
import java.text.DecimalFormat;

public class EmployeePay2 extends JApplet implements ActionListener
{
        JButton nameButton = new JButton("Please enter your name:");
      //creates a JButton to prepair to calculate with the label Calculate Annual Appliance Cost
   JLabel outputLabel = new JLabel ();//sets up new label named outputLabel
      JLabel outputLabel2 = new JLabel();
      JTextField tName = new JTextField(20);
      FlowLayout flow = new FlowLayout();
   Container con = getContentPane();// sets up the container con
      String x = "x";
      String X = "X";

   public void init()
   {
      con.setLayout(flow);// row components positioned to the right
      con.add(nameButton);//this tells it to add the calcButton
      con.add(outputLabel);//container for the outputLabel
            con.add(outputLabel2);
            con.add(tName);
      nameButton.addActionListener(this);
   }

   public void actionPerformed(ActionEvent e)
   {
       Object source = e.getSource();
       if (source == nameButton)
     {
         //Converting input to values
         String hours = JOptionPane.showInputDialog(null,"Please enter hours worked or press x to exit:");
            char cHours = hours.charAt(0);
            
            if(Character.isLetter(cHours))
                  {
                        if(hours.equals(x)||hours.equals(X))
                        {
                              System.exit(0);
                        }
                        else
                        {
                        JOptionPane.showMessageDialog(null, "Invalad Entry! Only numeric values or x is valid!");
                        hours = JOptionPane.showInputDialog(null, "Please enter hours worked or press x to exit:");
                        cHours = hours.charAt(0);
                        }
                  }
                        
                  if(Character.isDigit(cHours))
                  {
                        if(cHours> 12)
                        {
                        JOptionPane.showMessageDialog(null, "Hours worked may not be more than 12. Please reenter hours.");
                        hours = JOptionPane.showInputDialog(null, "Please enter hours worked or press x to exit:");
                        }
                        else
                        {
                        double dHours = Double.parseDouble(hours);//Converts the strings into Doubles
                        }
                  }
                        
            }
                        
         String sales = JOptionPane.showInputDialog(null,"Please enter total amount of sales or press x to exit:");
            char cSales = sales.charAt(0);
            
            if(Character.isLetter(cSales))
                  {
                        if(sales.equals(x)||sales.equals(X))
                        {
                              System.exit(0);
                        }
                        else
                        {
                        JOptionPane.showMessageDialog(null, "Invalad Entry! Only numeric values or x is valid!");
                        sales = JOptionPane.showInputDialog(null,"Please enter total amout of sales or press x to exit:");
                        cSales = sales.charAt(0);
                        }
                  }
            Double tempSales = Double.valueOf(sales);            
            double dSales = Double.parseDouble(sales);//Converts the strings into Doubles
            
            CalculateWage sentWage = new CalculateWage();
            CalculateCommission sentComm = new CalculateCommission();
            //create an object from the CalculateWage class
            
            sentComm.getSales(dSales);
            //to pass the variable dSales to the getSales method in the CalculateCommission class
            
            sentWage.getHours(dHours);
            //to pass the variable dHours to the getHours method in the CalculateWage class
            
          remove (tName);
             remove(nameButton);
             repaint();
             
             FlowLayout flow = new FlowLayout(FlowLayout.LEFT);
             con.setLayout(flow);
             
         outputLabel.setLocation(0,0);    
      //      outputLabel.setText (wageAmt + "\t\t hours worked");
            outputLabel2.setLocation(100,100);

            outputLabel2.setText (sentComm + "\t\t sales");
             
     
   }
}

this is the next program:
//CalculateCommission.java

public class CalculateCommission
{
      double commRate;
      double saleAmt;
      double Sales;

      public void getSales(double s)//method to the the sales amount
      {
            saleAmt = s;
            //gets the sale amount that was passed to it from EmployeePay class
      }


      public double commission()
      {
            if(saleAmt>=750.00)
            commRate = .15;

            else if(saleAmt>100.00)
            commRate = .10;

            else commRate = 0.0;
            
            return commRate;
      }
}
 and the next:
//CalculateWage.java

public class CalculateWage
{
      double rate = 10;
      double Hours;
      double overtimePay;
      double regularPay;
      double calPay;
      double pay;
      
      
      public void getHours(double hours)//method to the the sales amount
      {
            calPay = hours;
            //gets the sale amount that was passed to it from EmployeePay class
      }


      public double wages()
      {
      
            if(calPay > 8)
            {
                  regularPay = 8*rate;
                  overtimePay = (calPay - 8) * 1.5 * rate;
                  //time and a half for hours over 8
            }
            else
            {
                  regularPay = calPay * rate;
                  overtimePay = 0.0;
            }
            
            return wages()
            ;
      }
}
tamihallAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kjayaramanCommented:
Rectify the following errors and check

CalculateWage.java
Change the return statement in wages() to
return regularPay+overtimePay ;

EmployeePay2.java

The main problem is here
if (source == nameButton)
     {
        //Converting input to values
        String hours = JOptionPane.showInputDialog(null,"Please enter hours worked or press x to exit:");
         char cHours = hours.charAt(0);
         
          if(Character.isLetter(cHours))
               {
                    if(hours.equals(x)||hours.equals(X))
                    {
                         System.exit(0);
                    }
                    else
                    {
                    JOptionPane.showMessageDialog(null, "Invalad Entry! Only numeric values or x is valid!");
                    hours = JOptionPane.showInputDialog(null, "Please enter hours worked or press x to exit:");
                    cHours = hours.charAt(0);
                    }
               }
                   
               if(Character.isDigit(cHours))
               {
                    /*** This is the error line **/ if(cHours> 12)
                    {
                    JOptionPane.showMessageDialog(null, "Hours worked may not be more than 12. Please reenter hours.");
                    hours = JOptionPane.showInputDialog(null, "Please enter hours worked or press x to exit:");
                    /** Add return so that further processing is stopped after a validation fails **/
                    }
                    else
                    {

                    /** This is error number 2 **/double dHours = Double.parseDouble(hours);//Converts the strings into Doubles
                    }
               }
                   
          }

You are checking for if (cHours >12). Note cHours is a character and it converts cHours to the ascii value and this would always be greater than 12. Anywayz, convert it to an integer. I dont understand your logic to use a double. If you insist on double use it [hopefully people work 10.875 hrs ;) ] So, convert hours to double, the one you are doing in the else part before the if [to check if hours is greater than 12.] And for the next error. Take the dHours outside the if so that it is accessible by other part of the code. Note if you declare a variable inside a block it becomes local to the block and cannot be accessed ouside the {}/

The fixed code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.applet.*;
import java.lang.*;
import java.text.DecimalFormat;

public class EmployeePay2 extends JApplet implements ActionListener
{
       JButton nameButton = new JButton("Please enter your name:");
     //creates a JButton to prepair to calculate with the label Calculate Annual Appliance Cost
   JLabel outputLabel = new JLabel ();//sets up new label named outputLabel
     JLabel outputLabel2 = new JLabel();
     JTextField tName = new JTextField(20);
     FlowLayout flow = new FlowLayout();
   Container con = getContentPane();// sets up the container con
     String x = "x";
     String X = "X";

   public void init()
   {
      con.setLayout(flow);// row components positioned to the right
      con.add(nameButton);//this tells it to add the calcButton
      con.add(outputLabel);//container for the outputLabel
          con.add(outputLabel2);
          con.add(tName);
      nameButton.addActionListener(this);
   }

   public void actionPerformed(ActionEvent e)
   {
      Object source = e.getSource();
         double dHours = 0;
      if (source == nameButton)
     {
        //Converting input to values
        String hours = JOptionPane.showInputDialog(null,"Please enter hours worked or press x to exit:");
          char cHours = hours.charAt(0);
         
          if(Character.isLetter(cHours))
               {
                    if(hours.equals(x)||hours.equals(X))
                    {
                         System.exit(0);
                    }
                    else
                    {
                    JOptionPane.showMessageDialog(null, "Invalad Entry! Only numeric values or x is valid!");
                    hours = JOptionPane.showInputDialog(null, "Please enter hours worked or press x to exit:");
                              cHours = hours.charAt(0);
                    }
               }
                   
               if(Character.isDigit(cHours))
               {
                   dHours = Double.parseDouble(hours);//Converts the strings into Doubles
                              if(dHours> 12)
                    {
                    JOptionPane.showMessageDialog(null, "Hours worked may not be more than 12. Please reenter hours.");
                    hours = JOptionPane.showInputDialog(null, "Please enter hours worked or press x to exit:");
                              cHours = hours.charAt(0);
                    }
                   
               }
                   
          }
                   
        String sales = JOptionPane.showInputDialog(null,"Please enter total amount of sales or press x to exit:");
          char cSales = sales.charAt(0);
         
          if(Character.isLetter(cSales))
               {
                    if(sales.equals(x)||sales.equals(X))
                    {
                         System.exit(0);
                    }
                    else
                    {
                              /* Change this logic. Note, if the user enters an invalid entry again, the check is not done.
                              Might want to use a while loop instead of 'if'. Or do a 'return' to break further processing */
                    JOptionPane.showMessageDialog(null, "Invalad Entry! Only numeric values or x is valid!");
                    sales = JOptionPane.showInputDialog(null,"Please enter total amout of sales or press x to exit:");
                    cSales = sales.charAt(0);
                    }
               }
          Double tempSales = Double.valueOf(sales);          
          double dSales = Double.parseDouble(sales);//Converts the strings into Doubles
          CalculateWage sentWage = new CalculateWage();
          CalculateCommission sentComm = new CalculateCommission();
          //create an object from the CalculateWage class
         
          sentComm.getSales(dSales);
          //to pass the variable dSales to the getSales method in the CalculateCommission class
         
          sentWage.getHours(dHours);
          //to pass the variable dHours to the getHours method in the CalculateWage class
         
         remove (tName);
           remove(nameButton);
           repaint();
           
           FlowLayout flow = new FlowLayout(FlowLayout.LEFT);
           con.setLayout(flow);
           
        outputLabel.setLocation(0,0);    
          outputLabel.setText (sentWage.wages() + "\t\t hours worked");
          outputLabel2.setLocation(100,100);

          outputLabel2.setText (sentComm.commission() + "\t\t sales");
           
     
   }
}


public class CalculateWage
{
     double rate = 10;
     double Hours;
     double overtimePay;
     double regularPay;
     double calPay;
     double pay;
     
     
     public void getHours(double hours)//method to the the sales amount
     {
          calPay = hours;
          //gets the sale amount that was passed to it from EmployeePay class
     }


     public double wages()
     {
     
          if(calPay > 8)
          {
               regularPay = 8*rate;
               overtimePay = (calPay - 8) * 1.5 * rate;
               //time and a half for hours over 8
          }
          else
          {
               regularPay = calPay * rate;
               overtimePay = 0.0;
          }
         
          return regularPay+overtimePay ;
     }
}



Some more bugs in the code. To be continued ... ;)


0
kjayaramanCommented:
Good now that your code might have some limited functionality. Try to correct the validation strategy.

Try adding 100 for hours, It throws you an error message... Now reenter 100... :)) Now your code silently accepts it assuming that the user enters the correct number of hours for the second time. Work on your 'if' clauses that you use for validations. Try out a strategy like this
while (condition is false) { Show error message; Get the data again from the user; set the paramters so that the condition in the whle is checked with the new data }
Or..
if (condition is false) { show error message; stop processing, rollback all changes and revert to the initial state from which the user can restart the whole process }

Sounds good?
0
tamihallAuthor Commented:
This is great, but when I get ready to display it am I going to be able to show BOTH overtime and regular pay? I need to show what is what. This might seem like a silly question but I am really new at this.
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

tamihallAuthor Commented:
Thanks for your help but I got it myself. I was able to fix what I needed to fix.
0
tamihallAuthor Commented:
I had to totally redo the wage program and seperate the amounts into two different methods.
0
RuadRauFlessaCommented:
So you say you do not need the question any more?
0
moduloCommented:
Closed, 250 points refunded.

modulo
Community Support Moderator
Experts Exchange
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.