Hello guys !
I need some help with my Java Assignment ...
Assignment: http://screencast.com/t/NmLcx7OlA
I'm stuck from the begging until the c part.
I have no idea how to do a loop that reads every line from a file and how do I take those fields and add them into a Object ?
Thank you for your help !!!
Payroll Assignment
Page 1 of 15 Replies - 737 Views - Last Post: 08 February 2013 - 10:58 AM
Replies To: Payroll Assignment
#2
Re: Payroll Assignment
Posted 07 February 2013 - 05:04 PM
It sounds like you need to reference lectures, slides, or your textbook. Most professors (I've yet to encounter one) don't just assign something without having a lecture on it.
#3
Re: Payroll Assignment
Posted 07 February 2013 - 05:07 PM
Sonic94, on 07 February 2013 - 04:29 PM, said:
Hello guys !
I need some help with my Java Assignment ...
Assignment: http://screencast.com/t/NmLcx7OlA
I'm stuck from the begging until the c part.
I have no idea how to do a loop that reads every line from a file and how do I take those fields and add them into a Object ?
Thank you for your help !!!
I need some help with my Java Assignment ...
Assignment: http://screencast.com/t/NmLcx7OlA
I'm stuck from the begging until the c part.
I have no idea how to do a loop that reads every line from a file and how do I take those fields and add them into a Object ?
Thank you for your help !!!
Use a while loop and a scanner to read the file and save the input from the file in an array like this..
while( scanner.hasNextLine() )
String line[] = scanner.nextLine();
String x = line[0];
.........
//and then to create an object with the input
Object ob = new Object(x);
#4
Re: Payroll Assignment
Posted 07 February 2013 - 06:27 PM
Use a while loop and a scanner to read the file and save the input from the file in an array like this..
[/quote]
I manage to do it like this:
The thing is that rate and workHours has all the values stored in them, I don't see how I can do this:
a. The total gross pay for all employees.
b. The total number of hours worked by all employees
The teacher doesn't want that we use Arrays ...
while( scanner.hasNextLine() )
String line[] = scanner.nextLine();
String x = line[0];
.........
//and then to create an object with the input
Object ob = new Object(x);
[/quote]
I manage to do it like this:
String name1 = s.next(); String name2 = s.next(); String fullName = name1 + " " + name2; int id = s.nextInt(); double rate = s.nextDouble(); double workHours = s.nextDouble();
The thing is that rate and workHours has all the values stored in them, I don't see how I can do this:
a. The total gross pay for all employees.
b. The total number of hours worked by all employees
The teacher doesn't want that we use Arrays ...
#5
Re: Payroll Assignment
Posted 08 February 2013 - 10:41 AM
Sonic94, on 07 February 2013 - 06:27 PM, said:
Use a while loop and a scanner to read the file and save the input from the file in an array like this..
while( scanner.hasNextLine() )
String line[] = scanner.nextLine();
String x = line[0];
.........
//and then to create an object with the input
Object ob = new Object(x);
I manage to do it like this:
String name1 = s.next(); String name2 = s.next(); String fullName = name1 + " " + name2; int id = s.nextInt(); double rate = s.nextDouble(); double workHours = s.nextDouble();
The thing is that rate and workHours has all the values stored in them, I don't see how I can do this:
a. The total gross pay for all employees.
b. The total number of hours worked by all employees
The teacher doesn't want that we use Arrays ...
[/quote]
well if i understand well ..
a. You have to create a local variable to sum the total gross pay.. int sum = sum + grosspay;
b. You have to do the same int totalHours = totalHours + workHours;
#6
Re: Payroll Assignment
Posted 08 February 2013 - 10:58 AM
Create an employee object for each entry read from your scanner and add it to a list. After you're done reading the file, you can iterate over the list and sum up all of the hours and pay.
ArrayList<Employee> payroll = new ArrayList<Employee>();
while(s.hasNextLine()) {
String name1 = s.next();
String name2 = s.next();
String fullName = name1 + " " + name2;
int id = s.nextInt();
double rate = s.nextDouble();
double workHours = s.nextDouble();
payroll.add( new Employee(fullName, id, rate, workHours) );
}
Page 1 of 1

New Topic/Question
Reply


MultiQuote



|