1,105,375 Community Members

The Employee and ProductionWorker Classes

Member Avatar
richard.haines.39
Newbie Poster
10 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Need Help!

Here's the first production worker. 
Exception in thread "main" java.lang.IllegalArgumentException: Multiple decimal separators in pattern "#.##0.00"
    at java.text.DecimalFormat.applyPattern(DecimalFormat.java:2519)
    at java.text.DecimalFormat.<init>(DecimalFormat.java:416)
    at ProductionWorker.toString(ProductionWorker.java:42)
    at java.lang.String.valueOf(String.java:2826)
    at java.io.PrintStream.println(PrintStream.java:771)
    at WorkerDemo.main(WorkerDemo.java:10)
Java Result: 1
BUILD SUCCESSFUL (total time: 8 seconds)

// Employee Class

public class Employee
{
      private String name;
      private String employeeNumber;
      private String hireDate;

public Employee(String n, String num, String date)
{
      name = n;
      setEmployeeNumber(num);
      hireDate = date;
}

public Employee()
{
      name = "";
      employeeNumber = "";
      hireDate = "";
}
public void setName(String n)
{
      name = n;
}
public void setEmployeeNumber(String e)
{
      if (isValidEmpNum(e))
         employeeNumber = e;
      else
         employeeNumber = "";
}
public String getHireDate()
{
      return hireDate;
}
private boolean isValidEmpNum(String e)
{
      boolean status = true;

      if (e.length() != 5)
         status = false;
      else
      {
         if ((!Character.isDigit(e.charAt(0)))               ||
             (!Character.isDigit(e.charAt(1)))                  ||
             (!Character.isDigit(e.charAt(2)))                  ||
             (e.charAt (3) != '-')                                      ||
             (Character.toUpperCase(e.charAt(4)) < 'A')  ||
             (Character.toUpperCase(e.charAt(4)) > 'M'))
                status = false;
      }

      return status;
}
public String toString()
{
      String str = "Name: " + name + "\nEmployee Number: ";

      if (employeeNumber == "")
         str += "INVALID EMPLOYEE NUMBER";
      else
         str += employeeNumber;
      return
      str += ("\nHire Date: " + hireDate);
   }
}

// ProductionWorker Class

import java.text.DecimalFormat;
public class ProductionWorker extends Employee
{
      public static final int DAY_SHIFT = 1;
      public static final int NIGHT_SHIFT = 2;

      private int shift;
      private double payRate;

public ProductionWorker(String n, String num, String date,
               int sh, double rate)
{
      super(n, num, date);
      shift = sh;
      payRate = rate;
}
public ProductionWorker()

{
      super();
      shift = DAY_SHIFT;
      payRate = 0.0;
}
public void setShift(int s)
{
      shift = s;
}
public void setPayRate(double p)
{
      payRate = p;
}
public int getShift()
{
      return shift;
}
public double getPayRate()
{
      return payRate;
}
public String toString()
{
      DecimalFormat dollar = new DecimalFormat("#.##0.00");

      String str = super.toString();

      str += "\nShift: ";
      if (shift == DAY_SHIFT)
          str += "Day";
      else if (shift == NIGHT_SHIFT)
           str += "Night";
      else
           str += "INVALID SHIFT NUMBERS";
      return
      str += ("\nHourly Pay Rate: $" +
                 dollar.format(payRate));

   }
}

// WorkerDemo Class

public class WorkerDemo
{
      public static void main (String[] args)
      {
            ProductionWorker pw =
                     new ProductionWorker("John Smith", "123-A", "11-15-2005",
                                                        ProductionWorker.DAY_SHIFT, 16.50);

      System.out.println("Here's the first production worker. ");
      System.out.println(pw);

      ProductionWorker pw2 = new ProductionWorker();
      pw2.setName("Joan Jones");
      pw2.setEmployeeNumber("222-L");
      pw2.setHireDate("12-12-2005");
      pw2.setShift(ProductionWorker.NIGHT_SHIFT);
      pw2.setPayRate(18.50);

      System.out.println("\nHere's the second production worker. ");
      System.out.println(pw2);
   }
}
Member Avatar
mvmalderen
Nearly a Posting Maven
2,370 posts since Feb 2009
Reputation Points: 2,071 [?]
Q&As Helped to Solve: 282 [?]
Skill Endorsements: 40 [?]
 
1
 

The exception message tells you exactly what the problem is: Multiple decimal separators in pattern "#.##0.00"
A decimal separator in this context is a dot, and your formatter pattern contains multiple (more than one, two to be precise) of these.

Member Avatar
richard.haines.39
Newbie Poster
10 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: ProductionWorker.setHireDate
    at WorkerDemo.main(WorkerDemo.java:15)
Java Result: 1
Member Avatar
richard.haines.39
Newbie Poster
10 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I've been working on this to long and for some reason I can't figure out what to do?

Member Avatar
mvmalderen
Nearly a Posting Maven
2,370 posts since Feb 2009
Reputation Points: 2,071 [?]
Q&As Helped to Solve: 282 [?]
Skill Endorsements: 40 [?]
 
0
 

It seems like you haven't defined a setHireDate() method in your ProductionWorker class.

Member Avatar
richard.haines.39
Newbie Poster
10 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I've tried but then it says it conflicts with my employee class...?

Member Avatar
Taywin
Posting Maven
2,632 posts since Apr 2010
Reputation Points: 134 [?]
Q&As Helped to Solve: 378 [?]
Skill Endorsements: 17 [?]
 
0
 

How did you implement it? Also in which class did you implement the method in?

Member Avatar
richard.haines.39
Newbie Poster
10 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I tried in the productionworker class by putting public setHireDate() method...im getting really frustrated with it.

Member Avatar
mvmalderen
Nearly a Posting Maven
2,370 posts since Feb 2009
Reputation Points: 2,071 [?]
Q&As Helped to Solve: 282 [?]
Skill Endorsements: 40 [?]
 
0
 

Please post the modified version of your code.

Member Avatar
richard.haines.39
Newbie Poster
10 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 
    import java.text.DecimalFormat;
    public class ProductionWorker extends Employee
    {
    public static final int DAY_SHIFT = 1;
    public static final int NIGHT_SHIFT = 2;
    private int shift;
    private double payRate;
    public ProductionWorker(String n, String num, String date,
    int sh, double rate)
    {
    super(n, num, date);
    shift = sh;
    payRate = rate;
    }
    public ProductionWorker()
    {
    super();
    shift = DAY_SHIFT;
    payRate = 0.0;
    }
    public setHireDate()
    {
    hireDate = date;
    }
    public void setShift(int s)
    {
    shift = s;
    }
    public void setPayRate(double p)
    {
    payRate = p;
    }
    public int getShift()
    {
    return shift;
    }
    public double getPayRate()
    {
    return payRate;
    }
    public String toString()
    {
    DecimalFormat dollar = new DecimalFormat("#.##0.00");
    String str = super.toString();
    str += "\nShift: ";
    if (shift == DAY_SHIFT)
    str += "Day";
    else if (shift == NIGHT_SHIFT)
    str += "Night";
    else
    str += "INVALID SHIFT NUMBERS";
    return
    str += ("\nHourly Pay Rate: $" +
    dollar.format(payRate));
    }
    }
Member Avatar
mvmalderen
Nearly a Posting Maven
2,370 posts since Feb 2009
Reputation Points: 2,071 [?]
Q&As Helped to Solve: 282 [?]
Skill Endorsements: 40 [?]
 
0
 

Define your setHireDate as follows and put it in your Employee class (remove the other one from ProductionWorker, my bad):

public void setHireDate(String date)
{
    hireDate = date;
}
Member Avatar
richard.haines.39
Newbie Poster
10 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

wow. thank you very much! I was trying to use it in the productionworker...lol

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article