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