Can't get file to complile and don't know how to fix it

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jlgraham
    New Member
    • Jun 2008
    • 10

    Can't get file to complile and don't know how to fix it

    This is the first course I have ever taken in any programming language. This is my last assignment and totally frustrated. My employee class compiled but get 1 error when I tried to compile my EmpMainline class and I don't know how to fix it. It is in line 65 of my code. can't find symbol constructor Employee location class Employee. I would really appreciate any help on getting this to work. It may be my array. Our last class introduced us to arrays and I was a bit confused but thought I figured them out. Here are the 2 classes.
    Code:
    import javax.swing.*;
    import java.util.*;
    import java.text.*;
    
    public class EmpMainline
    {
    	public static void main(String args[])
    	{
    		String 		last, first, mid, payStr, hoursStr, otStr, vacStr;
    		String		birthDateStr, hireDateStr;
    		String		simpleDateCalculationOutput;
    		double		pay, hours, ot;
    		int			vac;
    		int			numEmp = 0;
    		int 		i;
    		Employee    emp[]; //sets up my array
    
    		// now set the size of the array
    		emp = new Employee[numEmp];
    
    		// walk through the # employees and get the input
    		for(i=0; i<numEmp; i++)
    		{
    			last = JOptionPane.showInputDialog(null,"Enter employee's last name",
    												    "Employee Information",
    													 JOptionPane.PLAIN_MESSAGE);   // get employee's last name
    
    			first = JOptionPane.showInputDialog(null,"Enter employee's first name",
    													 "Employee Information",
    											          JOptionPane.PLAIN_MESSAGE);   // get employee's first name
    
    			mid = JOptionPane.showInputDialog(null,"Enter employee's middle name or initial",
    												   "Employee Information",
    											        JOptionPane.PLAIN_MESSAGE);
    
    			birthDateStr = Employee.getDate("Enter date of birth (YYYY/MM/DD)", 2, "1930/01/01");
    
    			hireDateStr  = Employee.getDate("Enter date of hire (YYYY/MM/DD)", 2, "1930/01/01");
    
    			payStr = JOptionPane.showInputDialog(null,"Enter employee's hourly wage",
    												      "Employee Information",
    													   JOptionPane.PLAIN_MESSAGE);
    			pay = Double.parseDouble(payStr);
    
    			hoursStr = JOptionPane.showInputDialog(null,"Enter employee's regular weekly hours",
    													    "Employee Information",
    														 JOptionPane.PLAIN_MESSAGE);
    			hours = Double.parseDouble(hoursStr);
    
    			otStr = JOptionPane.showInputDialog(null,"Enter employee's weekly overtime hours",
    													 "Employee Information",
    													  JOptionPane.PLAIN_MESSAGE);
    			ot = Double.parseDouble(otStr);
    
    			vacStr = JOptionPane.showInputDialog(null,"Enter employee's vacation weeks",
    													  "Employee Information",
    													   JOptionPane.PLAIN_MESSAGE);
    			vac = Integer.parseInt(vacStr);
    
    			//get the employee's age at hire
    			simpleDateCalculationOutput = Employee.simpleDateSubtraction(birthDateStr, hireDateStr);
    			Employee.outputMessage("Your age when you were hired is " + simpleDateCalculationOutput);
    
    			emp[i] = new Employee(last, first, mid, birthDateStr, hireDateStr, payStr, hoursStr, otStr, vacStr);
    
    		}
    
    	}
    }
    
    
    import javax.swing.*;
    import java.util.*;
    import java.text.*;
    
    public class Employee
    {
    	//class attributes
    	private static int empID = 100;
    	//instance attributes
    	private String	lastName;
    	private String	firstName;
    	private String	midName;
    	private String	birthDate;
    	private String	hireDate;
    	private String  dateToday;
    	private int		hireAge;
    	private int 	presentAge;
    	private int		vacation;
    	private double 	payRate;
    	private double	otHours;
    	private double	regHours;
    	private int myEmpID;
    
    	public Employee(String last, String first, String mid, String dob, String doh, double pay, double hours, double ot, int vac)
    	{
    		lastName  = last;
    		firstName = first;
    		midName	  = mid;
    		birthDate = dob;
    		hireDate  = doh;
    		payRate	  = pay;
    		regHours  = hours;
    		otHours   = ot;
    		vacation  = vac;
    		myEmpID   = empID++;
    	}
    
    	public String getLastName()
    	{
    		return lastName;
    	}
    
    	public String getFirstName()
    	{
    		return firstName;
    	}
    
    	public String getMidName()
    	{
    		return midName;
    	}
    
    	public String getBirthDate()
    	{
    		return birthDate;
    	}
    
    	public String getHireDate()
    	{
    		return hireDate;
    	}
    
    	public double getPayRate()
    	{
    		return payRate;
    	}
    
    	public double getRegHours()
    	{
    		return regHours;
    	}
    
    	public double getOtHours()
    	{
    		return otHours;
    	}
    
    	public int getVacation()
    	{
    		return vacation;
    	}
    
    	public static String getDateToday()
    	{
    		Date 	today = new Date();
    		String	todayStr;
    
    		SimpleDateFormat	dateFormat = new SimpleDateFormat("yyyy/MM/dd");
    		todayStr = dateFormat.format(today);
    
    		return todayStr;
    	}
    
    	public static String getDate(String promptMsg, int numRetries, String defaultValue)
    	{
    		int		currNumRetries = 0;
    		String	userInput;
    		String	acceptedInput = "";
    		String	errMsg;
    
    		SimpleDateFormat myFormat = new SimpleDateFormat("yyyy/MM/dd");
    
    		// do not allow 2 digit years, single digits days or months
    		myFormat.setLenient(false);
    		while(currNumRetries < numRetries)
    		{
    			errMsg = "";
    			userInput = JOptionPane.showInputDialog(null, promptMsg,"Enter date ....",
    											        JOptionPane.QUESTION_MESSAGE);
    
    			// depending on the input type, we will do various input checks
    			// check that the date is in the correct format
    			try
    			{
    				if(userInput.length() != 10)
    				{
    					acceptedInput = "";
    					currNumRetries++;
    					errMsg = "Please specify a date (YYYY/MM/DD)";
    				}
    				else
    				{
    					Date tmpDate = myFormat.parse(userInput);
    					acceptedInput = userInput;
    					currNumRetries = 2;
    				}
    			}
    			catch(Exception e)
    			{
    				acceptedInput = "";
    				currNumRetries++;
    				System.out.printf("SimpleDateFormat Exception was caught\n");
    				errMsg = "Please specify a valid date (YYYY/MM/DD)";
    			}
    
    			if(errMsg.length() > 0)
    			{
    				JOptionPane.showMessageDialog(null, errMsg,"Error in Input",
    											  JOptionPane.WARNING_MESSAGE);
    			}
    
    		}
    
    			if(acceptedInput.length() == 0)
    			{
    				acceptedInput = defaultValue;
    				JOptionPane.showMessageDialog(null,"Defaulting to : " + acceptedInput,"Error in Input",
    											  JOptionPane.WARNING_MESSAGE);
    			}
    			return(acceptedInput);
    		}
    
    
    		public static void outputMessage(String promptMsg)
    		{
    				JOptionPane.showMessageDialog(null, promptMsg,"Date Differences",
    											  JOptionPane.WARNING_MESSAGE);
    		}
    
    
    		public static String simpleDateSubtraction(String birthDateStr, String hireDateStr)
    		{
    			int		birthDateVal, hireDateVal, yearDifference;
    			String	tmpStr;
    			String	outputString;
    
    			// since I have already verified that the date strings a valid dates I can do the
    			// following without any worries - and I don't have to trap any errors or exceptions
    			tmpStr = birthDateStr.substring(0,4)+birthDateStr.substring(5,7)+birthDateStr.substring(8,10);
    			birthDateVal = Integer.parseInt(tmpStr);
    
    			tmpStr = hireDateStr.substring(0,4)+hireDateStr.substring(5,7)+hireDateStr.substring(8,10);
    			hireDateVal = Integer.parseInt(tmpStr);
    
    			yearDifference = (hireDateVal-birthDateVal) / 10000;
    
    			return(yearDifference + " Age at Hire");
    		}
    
    }
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Look at the constructor of your Employee class: it takes Strings, doubles and an
    int as its parameters; you are trying to call a constructor with only nine Strings
    as its parameters. It doesn't exist and that's what your compiler is whining about.

    kind regards,

    Jos

    Comment

    • samido
      New Member
      • Oct 2007
      • 52

      #3
      Hi, I think you ment to put:

      emp[i] = new Employee(last, first, mid, birthDateStr, hireDateStr, pay, hours, ot, vac);

      instead of:

      emp[i] = new Employee(last, first, mid, birthDateStr, hireDateStr, payStr, hoursStr, otStr, vacStr);

      this will solve your proble and I tested it, just put any number greater than zero on your employee number like: int numEmp = 4; is doing something now atleast.

      kind regards Sam Rabophala

      Comment

      • jlgraham
        New Member
        • Jun 2008
        • 10

        #4
        Thanks everyone. I got it all working and ready to hand in including my Sort and Report Classes. I have made a new post. Would appreciate any replies. Thanks

        Comment

        Working...