I was wondering if I could get some help with a Java Program that I am currently working on for homework. When I run the program in Eclipse nothing shows up in the console can you help me out and tell me if I am missing something in my code or what's going on?
My Code:
public class Payroll {
public static void main(String[] args) {
}
// TODO Auto-generated method stub
private int[] employeeId = { 5658845, 4520125, 7895122, 8777541, 8451277, 1302850, 7580489 };
private int[] hours = new int[7];
private double[] payrate = new double[7];
private double[] wages;
/**
* Iterates through the wages array setting each element to the product of its corresponding
* values in the hours and payRate arrays.
*/
public void calculateWages()
{
wages = new double[7];
for (int index = 0; index < 7; index++)
{
wages[index] = hours[index] * payrate[index];
}
}
public int getEmployeeId(int index)
{
return employeeId[index];
}
public int[] getHours()
{
return hours;
}
public int getHours(int index)
{
return hours[index];
}
public double[] getPayrate()
{
return payrate;
}
public double getPayrate(int index)
{
return payrate[index];
}
/**
* Finds the wage of an employee and returns it.
*
* @param id The employee's ID
* @return The wage of the employee whose ID was given. Returns -1 if no employee was found.
*/
public double getWage(int id)
{
for (int index = 0; index < 7; index++)
{
if (id == employeeId[index])
{
return wages[id];
}
}
return -1;
}
public double[] getWages()
{
return wages;
}
public double getWages(int index)
{
return wages[index];
}
public void setEmployeeId(int index, int employeeId)
{
this.employeeId[index] = employeeId;
}
public void setHours(int index, int hours)
{
this.hours[index] = hours;
}
public void setPayRate(int index, double payRate)
{
this.payrate[index] = payRate;
}
public void setWages(int index, double wages)
{
this.wages[index] = wages;
}
}
solution:
File: Payroll.java
// Payroll class implementation
package payroll;
public class Payroll
{
// private members
private String name;
private String id;
private int hours;
private double rate;
// no-arg constructor implementation
public Payroll()
{
name = "";
id = "";
hours = 0;
rate = 0.0;
}
// parameterized constructor implementation
public Payroll(String aname, String aid, int ahours,
double arate)
{
setName(aname);
setId(aid);
setHours(ahours);
setRate(arate);
}
// setters
// setName method implementation
public void setName(String aname)
{
if(aname.equals(""))
{
throw new
IllegalArgumentException("Employee's name should not be
empty!");
}
name = aname;
}
// setId method implementation
public void setId(String aid)
{
if(aid.length() != 6 ||
!Character.isLetter(aid.charAt(0)) ||
!Character.isLetter(aid.charAt(1))
|| !Character.isDigit(aid.charAt(2)) ||
!Character.isDigit(aid.charAt(3))
|| !Character.isDigit(aid.charAt(4)) ||
!Character.isDigit(aid.charAt(5)))
{
throw new
IllegalArgumentException("Employee's id should have the form
LLNNNN!");
}
id = aid;
}
// setHours method implementation
public void setHours(int ahours)
{
if(ahours < 0 || ahours >
84)
{
throw new
IllegalArgumentException("Employee's hours should neither be
negative nor greater than 84!");
}
hours = ahours;
}
// setRate method implementation
public void setRate(double arate)
{
if(arate < 0 || arate >
25.00)
{
throw new
IllegalArgumentException("Employee's pay rate should neither be
negative nor greater than 25.00!");
}
rate = arate;
}
// getters
// getName method implementation
public String getName()
{
return name;
}
// getId method implementation
public String getId()
{
return id;
}
// getHours method implementation
public int getHours()
{
return hours;
}
// getRate method implementation
public double getRate()
{
return rate;
}
} // end of Payroll class
File: PayrollDemo.java
// PayrollDemo class implementation
package payroll;
public class PayrollDemo
{
// start main method
public static void main(String[] args)
{
// create an object for the Payroll
class
Payroll pr = new Payroll();
// test the setter method
pr.setName("Joseph Li");
pr.setId("JL3699");
pr.setHours(36);
pr.setRate(18.36);
// test the getter method
System.out.println("Detailes of
Payroll...");
System.out.println("Name: " +
pr.getName());
System.out.println("ID: " +
pr.getId());
System.out.println("Hours: " +
pr.getHours());
System.out.println("Pay rate: " +
pr.getRate());
} // end of main method
} // end of PayrollDemo class
I was wondering if I could get some help with a Java Program that I am...
Given attached you will find a file from Programming Challenge 5 of chapter 6 with required you to write a Payroll class that calculates an employee’s payroll. Write exception classes for the following error conditions: An empty string is given for the employee’s name. An invalid value is given to the employee’s ID number. If you implemented this field as a string, then an empty string could be invalid. If you implemented this field as a numeric variable, then a...
Please answer the following question with Java Modify the Employee and ProductionWorker classes provided below so they throw exceptions when the following errors occur. - The Employee class should throw an exception named InvalidEmployeeNumber when it receives an employee number that is less than 0 or greater than 9999. - The ProductionWorker class should throw an exception named InvalidShift when it receives an invalid shift. - The ProductionWorker class should thrown anexception named InvalidPayRate when it receives a negative number...
i am having trouble displaying results and displaying them evenly it is suppose to look like this Enter the following data for employee 1: Employee ID: 1298 Hours worked: 35.8 Pay rate (per hour): 23.45 Enter the following data for employee 2: Employee ID: 1899 Hours worked: 34.5 Pay rate (per hour): 19.5 Enter the following data for employee 3: Employee ID: 4435 Hours worked: 30.5 Pay rate (per hour): 20.75 Enter the following data for employee 4: Employee ID:...
With Java Language: 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) .İd: 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...
HospitalEmployee Inheritance help please. import java.text.NumberFormat; public class HospitalEmployee { private String empName; private int empNumber; private double hoursWorked; private double payRate; private static int hospitalEmployeeCount = 0; //----------------------------------------------------------------- // Sets up this hospital employee with default information. //----------------------------------------------------------------- public HospitalEmployee() { empName = "Chris Smith"; empNumber = 9999; hoursWorked = 0; payRate =0; hospitalEmployeeCount++; } //overloaded constructor. public HospitalEmployee(String eName,...
I would like help and there are three different classes in the coding.. 14.11 Prog11 Inheritance(PayrollOvertime) Create three files to submit: • Payroll class.java -Base class definition • PayrollOvertime.jave - Derived class definition • ClientClass.java - contains main() method Implement the two user define classes with the following specifications: Payroll class (the base class) (4 pts) • 5 data fields(protected) o String name - Initialized in default constructor to "John Doe" o int ID - Initialized in default constructor to...
How can I write a unit test for the following java method? (I am using intelliJ) public class ReviewEmployee{ public void EmployeeReview(Employee currentEmployee){ System.out.println("Your recorded hours for the week are: ") + (currentEmployee.getHours()); System.out.println("Your satisfactory rating is: ") + (currentlyEmployee.getRating()); System.out.println("Your bonus is: "); if(currentEmployee.getRating() < 3){ System.out.println(currentlyEmployee.getBonus()); } else{ System.out.println(currentlyEmployee.getBonus() + 500); } } } The Employee class is as follows: Public class Employee{ Private double hours; Private double rating; Private double bonus; Public Employee(double...
public class Person t publie alass EmployeeRecord ( private String firstName private String last Nanei private Person employee private int employeeID publie EnmployeeRecord (Person e, int ID) publie Person (String EName, String 1Name) thia.employee e employeeID ID setName (EName, 1Name) : publie void setName (String Name, String 1Name) publie void setInfo (Person e, int ID) this.firstName- fName this.lastName 1Name this.employee e employeeID ID: publio String getFiritName) return firstName public Person getEmployee) t return employeei public String getLastName public int getIDO...
I need help with this one method in java. Here are the guidelines. Only public Employee[] findAllBySubstring(String find). EmployeeManager EmployeeManager - employees : Employee[] - employeeMax : final int = 10 -currentEmployees : int <<constructor>> EmployeeManager + addEmployee( type : int, fn : String, ln : String, m : char, g : char, en : int, ft : boolean, amount : double) + removeEmployee( index : int) + listAll() + listHourly() + listSalary() + listCommision() + resetWeek() + calculatePayout() :...
Hey guys I am having trouble getting my table to work with a java GUI if anything can take a look at my code and see where I am going wrong with lines 38-49 it would be greatly appreciated! Under the JTableSortingDemo class is where I am having erorrs in my code! Thanks! :) import java.awt.*; import java.awt.event.*; import java.util.*; import java.util.List; import javax.swing.*; public class JTableSortingDemo extends JFrame{ private JTable table; public JTableSortingDemo(){ super("This is basic sample for your...