Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialmaryam khan
451 Pointspayroll application
hi, I am new to java and would like some assistance with my code.. the program is called Payroll.. i have 2 classes Employee and PayrollApp.
The Employee class should contain the name of the employee, hourly wages and # of hours worked, all taken from the user. This should contain Accessors and Mutators and a method called getPayment() that returns the total amount to be paid to the employee based on the numbers of hours worked.
PayrollApp is the main method and contains a private method that cannot be static and it should contain a method to print out payroll info for each employee which cannot be static. the method is called printStatement. There should be an array that holds upto 100 Employee Objects:
This is my code: can someone please help me and correct it?
public class Employee
{
public String name(getName()) { System.out.println("Please enter your name"); String name[]=sc.nextLine(); name=getName(); return name[]; }
public int hoursWorked(gethoursWorked())
{
System.out.println("Please enter the number of hours worked");
int hoursWorked[]=Integer.parseInt(sc.nextLine));
hoursWorked=gethoursWorked();
return hoursWorked[];
}
public int wages(getWages())
{ System.out.println("Please enter your hourly wage"); int wages[]=Ineger.paseInt(sc.nextLine)); wages=getWages(); return wages[]; }
public int payment(getPayment())
{ for (int i=0;i<names.lenght;i++)
{
payment=wages*hoursWorked;
System.out.printf("%s made this much money: ",payment);
}
}
}
import java.util.Scanner; import java.util.ArrayList;
public class payRollApp
{ private void main(String[]args)
{
Scanner sc=new Scanner(System.in);
public String printStatement()
{
System.out.println("Welcome to the Payroll Application");
private final int MAX_EMPLOYEES(100);
{
while(name<MAX_EMPLOYEES)
{
get Employee();
}
else
{
getPayment();
}
Arrays.sort(name,wages,hoursWorked);
System.out.printf("Employee information %s %n %d",name+wages+hoursWorked);
}
}
}
1 Answer
Steven Parker
231,269 PointsIt's hard to read code posted without Markdown formatting.
But one thing that stood out on first glance was the spelling of "names.lenght" (instead of "length").
maryam khan
451 Pointsmaryam khan
451 PointsAlso i forgot to mention that there won't always be necessarily 100 employees each time, there could be less then 100