Question: public class Payroll { public static void main ( String [ ] args ) { public class Payroll { private String name; private String id;

public class Payroll {
public static void main(String[] args){
public class Payroll {
private String name;
private String id;
private int hours;
private double rate;
//No arg Constructor
public Payroll()
{
name="";
id="";
hours=0;
rate=0;
}
//Parameterised Constructor
public Payroll(String name, String id, int hours, double rate){
setName(name);
setHours(hours);
setId(id);
setRate(rate);
}
//setters and getters
public void setName(String name){
if(!name.equals(""))
this.name = name;
else
throw new IllegalArgumentException("Name should not be empty...");
}
public void setId(String id){
if(id.length()!=6)
throw new IllegalArgumentException("Not a valid ID...");
else if(
Character.isLetter(id.charAt(0))
&& Character.isLetter(id.charAt(1))
&& Character.isDigit(id.charAt(2))
&& Character.isDigit(id.charAt(3))
&& Character.isDigit(id.charAt(4))
&& Character.isDigit(id.charAt(5))
)
this.id = id;
else
{
throw new IllegalArgumentException("Not a valid ID...");
}
}
public void setHours(int hours){
if(hours>=0 && hours<=84)
this.hours = hours;
else
throw new IllegalArgumentException("Not valid hours...");
}
public void setRate(double rate){
if(rate>=0 && rate<=25.00)
this.rate = rate;
else
throw new IllegalArgumentException("Not valid rate...");
}
public String getName(){
return name;
}
public String getId(){
return id;
}
public int getHours(){
return hours;
}
public double getRate(){
return rate;
}
@Override
public String toString(){
return "Payroll{"+
"name='"+ name +'\''+
", id='"+ id +'\''+
", hours="+ hours +
", rate="+ rate +
'}';
}
}
class Payroll{
public static void main(String[] args)
{
try {
Payroll payroll = new Payroll("James","CC4435",84,25);
System.out.println(payroll);
}
catch (IllegalArgumentException ex)
{
System.out.println(ex.getMessage());
}
}
}
}
}
Iam getting these errors
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The nested type Payroll cannot hide an enclosing type
Illegal modifier for the local class Payroll; only abstract or final is permitted
Duplicate nested type Payroll
The constructor Payroll(String, String, int, int) is undefined
at payrollclass.Payroll.main(Payroll.java:6)
the assignment is In this assignment, you are to create a class named Payroll.
In the class, you are to have the following data members:
name: String (5 pts)
id: String (5 pts)
hours: int (5 pts)
rate: double (5 pts)
private members (5 pts)
You are to create no-arg and parameterized constructors and the appropriate setters(accessors) and getters (mutators).(20 pts)
The class definition should also handle the following exceptions:
An employee name should not be empty, otherwise an exception should be thrown. (10 pts)
An employee id should have the form LLNNNN. If that form is not received, an exception should be thrown. (10 pts)
An employee's hours should neither be negative nor greater than 84. An exception should be thrown otherwise. (10 pts)
An employee's pay rate should neither be negative nor greater than 25.00. An exception should be thrown otherwise. (10 pts)
Demonstrate this class in a program (separate class or in the same class).(5 pts)
The exception messages should be appropriate to the specific exception that has occurred. (5 pts)
Create a package payroll for the project. (5 pts)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!