Use NetBeans IDE 8.2+ Need help with creating code for this intructions and most
ID: 3723597 • Letter: U
Question
Use NetBeans IDE 8.2+
Need help with creating code for this intructions and most of all please include comments on how you understood it, I cannont understand this instuctions. Like the netamount and others do i add them before the loop and then I add each elemnt of the array to contain each of the parameters to for loop during the iteration, or do i use them from phase 1, althguht they should be private parameters in phase 1.
You can use this link for phase 1, as it might be easier to understand instructions with knowing what pahse 1 looks like.
http://www.chegg.com/homework-help/questions-and-answers/program-represents-simple-payroll-system-could-hypothetically-used-company-maintain-inform-q26671149?trackid=7c83bc7b&strackid=7735db82&ii=6
This is what needs to be done.
Please follow the instructions below:
1- Download from moodle the solution I posted for the project.
2- Add a new class called PayrollSystem_Phase2.
3- Add the main method provided below.
4- Add another method called parseEmployeePaychecks that has two parameters: one of type int and one of type String. The method returns an ArrayList of Paycheck elements.
The int parameter represents an employee id, whereas the String parameter represents the list of paychecks the employee has received and which the method converts to an ArrayList of Paycheck elements.
5- You may assume that the String parameter has the following format:
periodBeginDate1:periodEndDate1:grossAmount1:taxAmount1:bonusAmount1# periodBeginDate2:periodEndDate2:grossAmount2:taxAmount2:bonusAmount2#...
6- I’m providing you with an algorithm for the method below:
public static ArrayList<Paycheck> parseEmployeePaychecks(int empID, String paycheckData)
{
/*
1- Declare an ArrayList of Paycheck elements and initialize to an empty list.
2- Split the paycheckData parameter on the # to get each paycheck information.
3- Write a loop to iterate through the list of paycheck strings, which should have the following format: periodBeginDate:periodEndDate:grossAmount:taxAmount:bonusAmount
4- Calculate the netAmount to be: grossAmount – taxAmount + bonusAmount
5- Create a Paycheck object using the employee id passed in the first parameter and the data parsed from the second parameter.
6- Add the Paycheck object to the ArrayList that this method returns.
7- After the loop, return the ArrayList of Paycheck objects.
*/
}
public static void main(String args[])
{
String paycheckData = "01/22/2018:01/26/2018:2500.50:375.25:50#" +
"01/29/2018:02/02/2018:2430.50:370.75:25#" +
"02/05/2018:02/09/2018:2630.50:380.25:60";
ArrayList<Paycheck> empPaychecks = parseEmployeePaychecks(1, paycheckData);
for(Paycheck checkElement: empPaychecks)
{
System.out.println(checkElement.toString());
}
}
Executing the main method should print the following to the output console:
run:
Employee ID: 1
Period Begin Date: 01/22/2018
Period End Date: 01/26/2018
Gross Amount: 2500.5
Tax Amount: 375.25
Bonus Amount: 50.0
Net Amount: 2175.25
-------------------------------
Employee ID: 1
Period Begin Date: 01/29/2018
Period End Date: 02/02/2018
Gross Amount: 2430.5
Tax Amount: 370.75
Bonus Amount: 25.0
Net Amount: 2084.75
-------------------------------
Employee ID: 1
Period Begin Date: 02/05/2018
Period End Date: 02/09/2018
Gross Amount: 2630.5
Tax Amount: 380.25
Bonus Amount: 60.0
Net Amount: 2310.25
-------------------------------
Explanation / Answer
Hi.. I have written java program for the above.
Paycheck.java
public class Paycheck {
private int EmpId;
private String periodBeginDate;
private String periodEndDate;
private double grossAmount;
private double taxAmount;
private double bonusAmount;
private double netAmount;
@Override
public String toString() {
return " Employee ID: " + EmpId + " Period Begin Date: " + periodBeginDate + " Period End Date " + periodEndDate
+ " Gross Amount: " + grossAmount + " Tax Amount: " + taxAmount + " Bonus Amount: " + bonusAmount
+ " Net Amount: " + netAmount + " ------------------------------ ";
}
public Paycheck(int empId, String periodBeginDate, String periodEndDate, double grossAmount, double taxAmount,
double bonusAmount, double netAmount) {
super();
EmpId = empId;
this.periodBeginDate = periodBeginDate;
this.periodEndDate = periodEndDate;
this.grossAmount = grossAmount;
this.taxAmount = taxAmount;
this.bonusAmount = bonusAmount;
this.netAmount = netAmount;
}
public int getEmpId() {
return EmpId;
}
public void setEmpId(int empId) {
EmpId = empId;
}
public String getPeriodBeginDate() {
return periodBeginDate;
}
public void setPeriodBeginDate(String periodBeginDate) {
this.periodBeginDate = periodBeginDate;
}
public String getPeriodEndDate() {
return periodEndDate;
}
public void setPeriodEndDate(String periodEndDate) {
this.periodEndDate = periodEndDate;
}
public double getGrossAmount() {
return grossAmount;
}
public void setGrossAmount(double grossAmount) {
this.grossAmount = grossAmount;
}
public double getTaxAmount() {
return taxAmount;
}
public void setTaxAmount(double taxAmount) {
this.taxAmount = taxAmount;
}
public double getBonusAmount() {
return bonusAmount;
}
public void setBonusAmount(double bonusAmount) {
this.bonusAmount = bonusAmount;
}
public double getNetAmount() {
return netAmount;
}
public void setNetAmount(double netAmount) {
this.netAmount = netAmount;
}
}
PayCheckDriver.java
import java.util.ArrayList;
public class PayCheckDriver {
public static void main(String[] args) {
// TODO Auto-generated method stub
String paycheckData = "01/22/2018:01/26/2018:2500.50:375.25:50#" +
"01/29/2018:02/02/2018:2430.50:370.75:25#" +
"02/05/2018:02/09/2018:2630.50:380.25:60";
ArrayList<Paycheck> empPaychecks = parseEmployeePaychecks(1, paycheckData);
for(Paycheck checkElement: empPaychecks)
{
System.out.println(checkElement.toString());
}
}
private static ArrayList<Paycheck> parseEmployeePaychecks(int i, String paycheckData) {
// TODO Auto-generated method stub
ArrayList<Paycheck> pc = new ArrayList<Paycheck>();
String tot[] = paycheckData.split("#");
for(int k=0;k<tot.length;k++) {
String vals[] = tot[k].split(":");
double netamount = Double.parseDouble(vals[2])-Double.parseDouble(vals[3])+Double.parseDouble(vals[4]);
Paycheck p = new Paycheck(i, vals[0], vals[1], Double.parseDouble(vals[2]), Double.parseDouble(vals[3]), Double.parseDouble(vals[4]), netamount);
pc.add(p);
}
return pc;
}
}
Output:
Employee ID: 1
Period Begin Date: 01/22/2018
Period End Date 01/26/2018
Gross Amount: 2500.5
Tax Amount: 375.25
Bonus Amount: 50.0
Net Amount: 2175.25
------------------------------
Employee ID: 1
Period Begin Date: 01/29/2018
Period End Date 02/02/2018
Gross Amount: 2430.5
Tax Amount: 370.75
Bonus Amount: 25.0
Net Amount: 2084.75
------------------------------
Employee ID: 1
Period Begin Date: 02/05/2018
Period End Date 02/09/2018
Gross Amount: 2630.5
Tax Amount: 380.25
Bonus Amount: 60.0
Net Amount: 2310.25
------------------------------
Please test the code and let me know any issues. Thank you. All the best.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.