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);
   }
}

Recommended Answers

All 12 Replies

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.

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: ProductionWorker.setHireDate
    at WorkerDemo.main(WorkerDemo.java:15)
Java Result: 1

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

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

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

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

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

Please post the modified version of your code.

    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));
    }
    }

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;
}

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

make this change
before:

      DecimalFormat dollar = new DecimalFormat("#.##0.00");

after:

      DecimalFormat dollar = new DecimalFormat("#.##");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.