Need some help with Payroll assignment.

Last week I developed a payroll program that duffy helped out quite a bit with. This week we need to improve on the program a little more. Here is what the teacher is asking:

"Modify the Payroll Program so that it uses a class to store and retrieve the employee's name, the hourly rate, and the number of hours worked. Use a constructor to initialize the employee information, and a method within that class to calculate the weekly pay. Once stop is entered as the employee name, the application should terminate. "

I'm a little unsure how to create the class that stores the employee info to be carried to each step. The teacher explained that there should be two classes, employee and payroll. I'm not sure how to set up the employee class. here is my code:

// Multiplication.java

// Payroll program

import java.util.Scanner;

publicclass Payroll

{

privatestaticfinal String STOP ="stop";

publicstaticvoid main(String args[])

{

Scanner scanner =new Scanner (System.in);

System.out.print("Please enter name < enter 'stop' to exit program:");

String nameOfEmployee = scanner.nextLine();

if (!nameOfEmployee.equals(STOP))

{

double rate = 0;

double hours = 0;

double totalPay;

do

{

System.out.print("Enter rate:$ ");

rate = scanner.nextDouble();

if ( rate >=0 )

break;

else

{

System.out.print ("Please enter a postive number." );

}

}while (rate < 0);

System.out.println ("rate: " + rate);

do

{

System.out.print("Enter hours: ");

hours = scanner.nextDouble();

if ( hours >= 0 )

break;

else

{

System.out.print ("Please enter a postive number.");

}

}while (hours < 0 );

System.out.println ("hours: " + hours);

totalPay = rate * hours;

scanner.nextLine();

System.out.printf("%s pay is $ %.2f\n", nameOfEmployee, totalPay);

}

}

}

Any advice would be greatly appreciated. Oh I also need to figure out how to keep the program going and having only 'stop' end it. Right now it just cycles once.

Message was edited by:

stevedub

[3758 byte] By [steveduba] at [2007-11-26 14:43:42]
# 1

public class Employee {

private String name;

private double hourlyRate;

private int hoursWorked;

// Constructor to initialize the employee with the information provided.

public Employee(String name, double hourlyRate, int hoursWorked) {

setName(name);

setHourlyRate(hourlyRate);

setHoursWorked(hoursWorked);

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public double getHourlyRate() {

return hourlyRate;

}

public void setHourlyRate(double hourlyRate) {

this.hourlyRate = hourlyRate;

}

public int getHoursWorked() {

return hoursWorked;

}

public void setHoursWorked(int hoursWorked) {

this.hoursWorked = hoursWorked;

}

}

You need to have an Employee class like above with a constructor which accepts employee data and initializes the object.

Then you need to modify your program to get all the information from the user input and initialize an object for each employee information entered until the magic word 'stop' is entered for the name.

To make the program loop multiple times, you need a do-while for taking input and having the !nameOfEmployee.equals(STOP) for the while.

annie79a at 2007-7-8 8:31:20 > top of Java-index,Java Essentials,New To Java...
# 2

Thanks for the reply Anie, just a couple questions. Where do i put the public class Employee in my code? and also, do I change the if (!nameOfEmployee.equals (stop)) with a while in front to make it loop?

I'm sorry, I am very new to programming, and my class is online so it it hard to get prompt help. I get more help here than in my class.

steveduba at 2007-7-8 8:31:20 > top of Java-index,Java Essentials,New To Java...
# 3

> Where do i put the public class Employee in my code?

It's a public class. It would have its own source file called Employee.java and it will be in the same directory and your Payroll class.

> and also, do I change the if (!nameOfEmployee.equals

> (stop)) with a while in front to make it loop?

Exactly! Remember that an 'if' statement will traverse only once. Since you need to do it multiple times and you are not sure, you will use the while loop. I would suggest do-while because you need to execute that part for at least one input. :)

> I'm sorry, I am very new to programming, and my class

> is online so it it hard to get prompt help. I get

> more help here than in my class.

I wonder what kind of a class that is.

annie79a at 2007-7-8 8:31:20 > top of Java-index,Java Essentials,New To Java...
# 4

Ok annie, I changed the 'if' to a 'do/while' but I am getting an error. here is what I did:

do {

System.out.print("Please enter name < enter 'stop' to exit program:");

String nameOfEmployee = scanner.nextLine();

} while (!nameOfEmployee.equals(STOP))

It tells me to add a semi-colon, but when I do add one I get even more errors. Am I missing something here?

steveduba at 2007-7-8 8:31:20 > top of Java-index,Java Essentials,New To Java...
# 5

> It tells me to add a semi-colon, but when I do add

> one I get even more errors. Am I missing something

> here?

There are a couple of things I notice:

- There should be a semicolon after the while condition.

while (!nameOfEmployee.equals(STOP));

- Your nameOfEmployee would need to be declared beofe the do block so that the variable's scope is accessible to the while condition.

annie79a at 2007-7-8 8:31:20 > top of Java-index,Java Essentials,New To Java...
# 6
How exactly do I declare nameOfEmployee outside of the 'do'? I'm sorry, like I said before I am very new to all this and this class is moving way to fast for me. I really appreciate your help :)
steveduba at 2007-7-8 8:31:20 > top of Java-index,Java Essentials,New To Java...
# 7

Ok, I modified my code some, but I'm getting errors trying to get the loop to continue. here is what I did:

// Multiplication.java

// Payroll program

import java.util.Scanner;

public class Payroll

{

private static final String STOP = "stop";

public static void main(String args[])

{

Scanner scanner = new Scanner (System.in);

while (!nameOfEmployee.equals(STOP));

{

System.out.print("Please enter name < enter 'stop' to exit program:");

String nameOfEmployee = scanner.nextLine();

double rate = 0;

double hours = 0;

double totalPay;

do

{

System.out.print("Enter rate:$ ");

rate = scanner.nextDouble();

if ( rate >=0 )

break;

else

{

System.out.print ( "Please enter a postive number." );

}

} while (rate < 0);

System.out.println ("rate: " + rate);

do

{

System.out.print("Enter hours: ");

hours = scanner.nextDouble();

if ( hours >= 0 )

break;

else

{

System.out.print ( "Please enter a postive number.");

}

} while (hours < 0 );

System.out.println ("hours: " + hours);

totalPay = rate * hours;

scanner.nextLine();

System.out.printf("%s pay is $ %.2f\n", nameOfEmployee, totalPay);

}

}

}

}

steveduba at 2007-7-8 8:31:20 > top of Java-index,Java Essentials,New To Java...
# 8

I guess I find it easier to have an infinite while loop and break if 'stop' is encountered in the name input.

import java.util.Scanner;

public class Payroll {

private static final String STOP = "stop";

public static void main(String args[]) {

Scanner scanner = new Scanner (System.in);

String nameOfEmployee = "";

@SuppressWarnings("unused")

Employee employee = null;

while(true) {

System.out.print("Please enter name < enter '" +STOP +"' to exit program> :");

nameOfEmployee = scanner.nextLine();

if(nameOfEmployee.equals(STOP)) {

// Terminate scanning for more data once stop is encountered.

break;

}

double rate = 0;

double hours = 0;

double totalPay;

do {

System.out.print("Enter rate:$ ");

rate = scanner.nextDouble();

if ( rate >=0 ) {

break;

} else {

System.out.print ( "Please enter a postive number." );

}

} while (rate < 0);

System.out.println ("rate: " + rate);

do {

System.out.print("Enter hours: ");

hours = scanner.nextDouble();

if ( hours >= 0 ) {

break;

} else {

System.out.print ( "Please enter a postive number.");

}

} while (hours < 0 );

System.out.println ("hours: " + hours);

// Initialize your Employee object.

employee = new Employee(nameOfEmployee, rate, hours);

totalPay = rate * hours;

scanner.nextLine();

System.out.printf("%s pay is $ %.2f\n", nameOfEmployee, totalPay);

}

}

}

annie79a at 2007-7-8 8:31:20 > top of Java-index,Java Essentials,New To Java...
# 9
> Ok, I modified my code some, but I'm getting errors> trying to get the loop to continue.What errors are you getting? Is it with the code itself or the way the program is behaving?
annie79a at 2007-7-8 8:31:20 > top of Java-index,Java Essentials,New To Java...
# 10

This is the error I get when I compile the code:

C:\Documents and Settings\stevew\My Documents\Payroll.java:66: 'class' or 'interface' expected

}

^

C:\Documents and Settings\stevew\My Documents\Payroll.java:67: 'class' or 'interface' expected

^

2 errors

Tool completed with exit code 1

steveduba at 2007-7-8 8:31:20 > top of Java-index,Java Essentials,New To Java...
# 11

I also get this error when running your code:

C:\Documents and Settings\stevew\My Documents\Payroll.java:56: cannot find symbol

symbol : constructor Employee(java.lang.String,double,double)

location: class Employee

employee = new Employee(nameOfEmployee, rate, hours);

^

1 error

Tool completed with exit code 1

steveduba at 2007-7-8 8:31:20 > top of Java-index,Java Essentials,New To Java...
# 12

> I also get this error when running your code:

This is because you are using the Employee class just the way I posted without pondering over it for a minute. The number of hours worked is being read as a double by you and I declared it as an int in the Employee class - I typed the class on the fly just to give you an idea, and I don't remember if that int for number of hours was deliberate or not. I suggest that you take some time to understand your code.

Now obviously, you need to change the Employee class to have hoursWorked as double and correspondingly change the constructor and the getHoursWorked() and setHoursWorked() to use double instead of int.

annie79a at 2007-7-8 8:31:20 > top of Java-index,Java Essentials,New To Java...
# 13

> Documents\Payroll.java:66: 'class' or 'interface'

> expected

> }

> ^

I didn't exactly take a look at your code but I am guessing that you are not closing all the braces that you opened. It is essential that you match all your braces so that the compiler is able to understand the end of a block. This would require you to carefully go through the code and match all the braces.

annie79a at 2007-7-8 8:31:20 > top of Java-index,Java Essentials,New To Java...
# 14
Hey annie, I got that loop to work. I really appreciate all your help, now I just need to figure out how to store the name and I'm all set. That will be my next step, so if I have any more questions I will shoot another post. Thanks again!
steveduba at 2007-7-8 8:31:20 > top of Java-index,Java Essentials,New To Java...
# 15
> now I just need to figure out how to store the nameWhat are your requirements for storage? Do you intend to store a 'list' of all the names entered (or rather the employee information)?
aniseeda at 2007-7-21 16:16:28 > top of Java-index,Java Essentials,New To Java...
# 16

All the program has to do is basically store the employee's name once entered, and then carry it through each of the steps. For example:

enter employee name: stevedub

enter the rate for stevedub: 15

enter the hours for stevedub: 40

employee name: stevedub

weekly wages = 600

steveduba at 2007-7-21 16:16:28 > top of Java-index,Java Essentials,New To Java...
# 17

Ok, this is my code updated, but I get an error message that I'm not sure about. Here is the code:

import java.util.Scanner;

public class PayrollTest {

private static final String STOP = "stop";

public static void main(String args[]) {

Scanner scanner = new Scanner (System.in);

Employee name;

name = new Employee(nameOfEmployee, rate, hours);

String nameOfEmployee = "";

@SuppressWarnings("unused")

Employee employee = null;

while(true) {

System.out.print("Please enter name < enter '" +STOP +"' to exit program> :");

nameOfEmployee = scanner.nextLine.();

if(nameOfEmployee.equals(STOP)) {

// Terminate scanning for more data once stop is encountered.

break;

}

double rate = 0;

double hours = 0;

double totalPay;

do {

System.out.print("Enter rate:$ ");

rate = scanner.nextDouble();

if ( rate >=0 ) {

break;

} else {

System.out.print ( "Please enter a postive number." );

}

} while (rate < 0);

System.out.println ("rate: " + rate);

do {

System.out.print("Enter hours: ");

hours = scanner.nextDouble();

if ( hours >= 0 ) {

break;

} else {

System.out.print ( "Please enter a postive number.");

}

} while (hours < 0 );

System.out.println ("hours: " + hours);

// Initialize your Employee object.

employee = new Employee(nameOfEmployee, rate, hours);

totalPay = rate * hours;

scanner.nextLine();

System.out.printf("%s pay is $ %.2f\n", nameOfEmployee, totalPay);

}

}

}

And here is the error message that I get:

C:\Documents and Settings\Owner.YOUR-E92F6775CF\My Documents\PayrollTest.java:20: <identifier> expected

nameOfEmployee = scanner.nextLine.();

^

1 error

Tool completed with exit code 1

steveduba at 2007-7-21 16:16:28 > top of Java-index,Java Essentials,New To Java...
# 18
nameOfEmployee = scanner.nextLine.();you got extra pair of .should be nameOfEmployee = scanner.nextLine();
fastmikea at 2007-7-21 16:16:28 > top of Java-index,Java Essentials,New To Java...
# 19

> Employee name;

> name = new Employee(nameOfEmployee, rate, hours);

This part of the code is wrong. The variables nameOfEmployee, rate and hours are not even declared at that point. This will not compile.

I see that you are not really following the code that annie79 posted. You are just copying it.

aniseeda at 2007-7-21 16:16:28 > top of Java-index,Java Essentials,New To Java...
# 20
i already posted the solution me and duffy with our own examples. and now i dont know what he is trying to do http://forum.java.sun.com/thread.jspa?threadID=5122153&messageID=9429487#9429487
fastmikea at 2007-7-21 16:16:28 > top of Java-index,Java Essentials,New To Java...
# 21

This is a new step in the payroll program to have it store the employee's name through each of the steps. I'm ready to throw in the towel on this stuff, I just can't grasp the concepts at all. I'm already 4 weeks into my 9 week class, and I still don't have a clue. I think I need to find tutor or something, that I can actually sit down with and have them show me the processes involved.

Thanks for trying to help out me out though, I really appreciate it. I really do want to learn how to program, but I don't think its going to happen by the end of my class.

steveduba at 2007-7-21 16:16:28 > top of Java-index,Java Essentials,New To Java...
# 22

> I'm ready to throw in the towel on this stuff, I just

> can't grasp the concepts at all. I'm already 4 weeks

> into my 9 week class, and I still don't have a clue.

> I think I need to find tutor or something

I think you should seriously start reading

http://java.sun.com/docs/books/tutorial/

and ask questions to get concepts clarified.

To start with, leaving the part where you store information in an Employee object, is everything else clear? Any generic questions that you want to ask, ask rightaway.

aniseeda at 2007-7-21 16:16:28 > top of Java-index,Java Essentials,New To Java...
# 23

> I'm ready to throw in the towel on this stuff, I just

> can't grasp the concepts at all. I'm already 4 weeks

> into my 9 week class, and I still don't have a clue.

That's not unusual, sometimes it takes a eureka moment to get some of the concepts, but giving up isn't going to help you at all.

> I think I need to find tutor or something, that I can

> actually sit down with and have them show me the

> processes involved.

Perhaps you need to take an easier example, from the links provided. If you work through that, and try to understand as much as you can. Then see if you can apply it to your course work (If you are having difficulty, then it means you are going to have to put a lot of time and effort into it). Nobody here is going to give you the answer, and getting a 1 to 1 session will only make you dependant on the tutor, and may hinder your understanding the concepts.

>

> Thanks for trying to help out me out though, I really

> appreciate it. I really do want to learn how to

> program, but I don't think its going to happen by the

> end of my class.

If you put in the effort you will. If you don't it wont. Few things in life are easy, but most reward effort - if you put in the effort, you will succeed.

macrules2a at 2007-7-21 16:16:29 > top of Java-index,Java Essentials,New To Java...
# 24

> This is a new step in the payroll program to have it

> store the employee's name through each of the steps.

> I'm ready to throw in the towel on this stuff, I just

> can't grasp the concepts at all. I'm already 4 weeks

> into my 9 week class, and I still don't have a clue.

> I think I need to find tutor or something, that I can

> actually sit down with and have them show me the

> processes involved.

You're making a mistake that every student does. They don't understand that computer science and programming (and all problem solving) is about divide and conquer. Break a large problem up into smaller ones that you can handle. It's called decomposition in programming.

You have a bunch of requirements here. You're trying to solve them all at the same time and getting bunched up. Do them one at a time and check them off.

You're probably solving this by sitting right down at the keyboard and hammering away. Have you written words, drawn a few pictures, did a little research with the javadocs first?

Do you back up working versions when you tackle the next piece, or do you immediately modify working code and end up with nothing when it's a mess and can't recover the last working version?

> Thanks for trying to help out me out though, I really

> appreciate it. I really do want to learn how to

> program, but I don't think its going to happen by the

> end of my class.

Probably not, but that's because becoming a really good programmer takes more than one class and nine weeks.

Mastering anything is hard work: math, a golf swing, a jump shot, etc. Programming is no different. Only you can decide whether or not you pay the price.

%

duffymoa at 2007-7-21 16:16:29 > top of Java-index,Java Essentials,New To Java...
# 25

Thanks for all the replies guys, you are all right, I really need to sit down and take a few (many) steps back. I'm just getting really frustrated with this, and I need to calm down a bit and try to understand what I'm doing. I usually pick up on things really easy, and I am usually able to figure things out pretty quick. I think that is why I am getting so frustrated. It also doesn't help that I am being rushed by deadlines from the teacher when I don't even know what I'm doing exactly. It also doesn't help that I work full time with kids and I have to try to cram all this knowledge in at once.

steveduba at 2007-7-21 16:16:29 > top of Java-index,Java Essentials,New To Java...
# 26

> I have to try to cram all this knowledge in at once.

Don't try to! That would do you more good. Understanding concepts one by one would be more beneficial. I seriously suggest that you start reading the tutorial. It should not take more than a couple of hours (maybe more) to read up on the first few chapters with a thorough reading. I would suggest that you focus on the first three parts [url=http://java.sun.com/docs/books/tutorial/java/index.html]here[/url]. Once you are comfortable with that, you could proceed to the next chapters and you will find your assignment easier to work with. And while you are studying, don't hesitate to get your queries clarified.

aniseeda at 2007-7-21 16:16:29 > top of Java-index,Java Essentials,New To Java...
# 27
Thank you very much for all of the helpful info. I have started to read up the tutorial at my lunch and I will continue when I get home. I have till Sunday for this assignment, so hopefully I can get some good reading time in.
steveduba at 2007-7-21 16:16:29 > top of Java-index,Java Essentials,New To Java...
# 28

> Thanks for all the replies guys, you are all right, I

> really need to sit down and take a few (many) steps

> back. I'm just getting really frustrated with this,

> and I need to calm down a bit and try to understand

> what I'm doing.

When I think back to the first time I was asked to program a computer, I know I felt like this, too. It wasn't a pretty sight at all.

> I usually pick up on things really

> easy, and I am usually able to figure things out

> pretty quick. I think that is why I am getting so

> frustrated. It also doesn't help that I am being

> rushed by deadlines from the teacher when I don't

> even know what I'm doing exactly.

> It also doesn't

> help that I work full time with kids and I have to

> try to cram all this knowledge in at once.

I know what that is, too. I'll be watching your thread. I'm at work now, but I'll see what I can do to help sort you out a bit tonight.

%

duffymoa at 2007-7-21 16:16:29 > top of Java-index,Java Essentials,New To Java...
# 29

There is one thing I didn't notice so far about your assignment. The calculation for the weekly pay is supposed to be in the Employee class. So, it should be modified as follows:

/*

*Employee

*/

public class Employee {

private String name;

private double hourlyRate;

private double hoursWorked;

// Constructor to initialize the employee with the information provided.

public Employee(String name, double hourlyRate, double hoursWorked) {

setName(name);

setHourlyRate(hourlyRate);

setHoursWorked(hoursWorked);

}

// Method to get the employee name.

public String getName() {

return this.name;

}

// Method to set the employee name.

private void setName(String name) {

this.name = name;

}

// Method to set the hourly rate.

private void setHourlyRate(double hourlyRate) {

this.hourlyRate = hourlyRate;

}

// Method to set the hours worked.

private void setHoursWorked(double hoursWorked) {

this.hoursWorked = hoursWorked;

}

// Method to compute the weekly pay.

public double getWeeklyPay() {

return this.hourlyRate *this.hoursWorked;

}

}

I am chopping down a few methods which would not be used.

annie79a at 2007-7-21 16:16:29 > top of Java-index,Java Essentials,New To Java...
# 30

Now, we will modify the Payroll class to make better use of this Employee class.

import java.util.Scanner;

/*

*Payroll

*/

public class Payroll {

// The termination string

private static final String STOP = "stop";

// Main method

public static void main(String args[]) {

Scanner scanner = new Scanner (System.in);

// Variable to read the employee name.

String nameOfEmployee = "";

// Variable to read the hourly rate.

double rate = 0;

// Variable to read the number of hours worked.

double hours = 0;

// Object of the Employee class used for calculations.

Employee employee = null;

/* Beginning of loop */

while(true) {

System.out.print("Please enter name < enter '" +STOP +"' to exit program> :");

// Employee name input scan

nameOfEmployee = scanner.nextLine();

if(nameOfEmployee.equals(STOP)) {

// Terminate scanning for more data once stop is encountered.

break;

}

// Scan hourly rate input.

do {

System.out.print("Enter rate:$ ");

rate = scanner.nextDouble();

if ( rate >=0 ) {

// Input valid ... so break out of the loop.

break;

} else {

System.out.print ( "Please enter a postive number for rate." );

}

} while (rate < 0);

// Scan number of hours worked input.

do {

System.out.print("Enter hours: ");

hours = scanner.nextDouble();

if ( hours >= 0 ) {

// Input valid so break out of the loop.

break;

} else {

System.out.print ( "Please enter a postive number for hours.");

}

} while (hours < 0 );

// Initialize your Employee object, since you have all the necessary data.

employee = new Employee(nameOfEmployee, rate, hours);

scanner.nextLine();

// The weekly pay is obtained by invoking the getWeeklyPay() method on the employee object.

System.out.printf("%s pay is $ %.2f\n", employee.getName(), employee.getWeeklyPay());

}

// Close the scanner since no further input is expected.

scanner.close();

}

}

I have added a few comments but if they are not sufficient to understand the code, feel free to ask more questions.

annie79a at 2007-7-21 16:16:33 > top of Java-index,Java Essentials,New To Java...
# 31
You can't do better than annie's guidance, stevedub.%
duffymoa at 2007-7-21 16:16:33 > top of Java-index,Java Essentials,New To Java...
# 32

Man, I'm sorry for causing so much uproar, I just need some help with programming, like many others do. I am starting to understand some of the concepts after reading some of the tutorials. I am now looking at the code and understanding some if it now.

I am currently on the section about objects, which really pertains to my assignment. I understand the need to create the Employee class, but I am wondering why so much information is needed in that class. It seems like the Payroll class does all of the calculations, and the only thing really needed from the Employee class is the employee's name. This is where I am getting confused some.

I think I understand that you must call upon that Employee class to be able to use it's methods, but how does the Employee class store the name? Just it just create a placeholder for the employee's name, and then when put into your program does it use the information entered? I am also wondering how to call the employee name through each of the steps. I read this in the tutorial, should I do something similar to the 'rate' 'hour' and 'total pay'?

System.out.println("Width of rectOne: " +

rectOne.width);

steveduba at 2007-7-21 16:16:33 > top of Java-index,Java Essentials,New To Java...
# 33

> I am currently on the section about objects, which

> really pertains to my assignment. I understand the

> need to create the Employee class, but I am wondering

> why so much information is needed in that class. It

> seems like the Payroll class does all of the

> calculations, and the only thing really needed from

> the Employee class is the employee's name. This is

> where I am getting confused some.

No, I looked at your original assignment statement again anf the calculations are expected to be done by the Employee class. See the code I posted recently.

You can consider the Employee class as a data object. Each object of the Employee class will represent an Employee. Thus, you can have the information of several employees together. They can be kept together in an array or a Collection (you will know as you progress).

annie79a at 2007-7-21 16:16:33 > top of Java-index,Java Essentials,New To Java...
# 34

Hello all,

i am taking some online courses, ( I think stevedub and i must have very similar assignments) the difficult part is reading all the material and understanding...i do much better when shown....moving on; I have already written a working program, (it is identical; as far as the coding, to annie79 post).

Maybe i am overthinking this? my assignment asks me to : use a class to store and retrieve name and info, use a constructor to start empoyee info and a method within the class to calculate hours and pay....to keep it simple, using the code annie79 has provided have i not already done that?

I think i have, perhaps i read too far ahead and now my brain is turning to mush. Simply put have i not met the criteria of this assignment already?

FSUbounda at 2007-7-21 16:16:33 > top of Java-index,Java Essentials,New To Java...
# 35

> Hello all,

> i am taking some online courses, ( I think stevedub

> and i must have very similar assignments) the

> difficult part is reading all the material and

> understanding...i do much better when

> shown....moving on; I have already written a working

> program, (it is identical; as far as the coding, to

> annie79 post).

Do you mean that you lifted her code, too?

> Maybe i am overthinking this?

It's more likely that you're underthinking it.

> my assignment

> asks me to : use a class to store and retrieve

> name and info, use a constructor to start empoyee

> info and a method within the class to calculate

> hours and pay....to keep it simple, using the code

> annie79 has provided have i not already done that?

I don't know, have you? How would you recognize it if you did?

> I think i have, perhaps i read too far ahead and now

> my brain is turning to mush. Simply put have i not

> met the criteria of this assignment already?

Who knows? Answer the question for yourself.

%

duffymoa at 2007-7-21 16:16:33 > top of Java-index,Java Essentials,New To Java...
# 36

I am new to java, however i am not a liar. My code was written before i even came here, so my first answer to your reply is "no i didnt lift her code".... and this is not sarcasim this is someone asking a simple question...; are there really many other ways to write this code?

Secondly the reason i asked my question is because i have read ahead, and have turned my assignment in, i thought that i was missing something because this is what i turned in a week ago....perhaps i was a step ahead and simply thought that i was over thinking the assignment.

Its unfortunate that seeking help from others results in having our integrity and intelligance questioned.

Thanks for your time.

FSUbounda at 2007-7-21 16:16:33 > top of Java-index,Java Essentials,New To Java...
# 37

import java.io.*;

public class Payroll

{

private static final String STOP = "stop";

public static void main(String[] args) throws IOException

{

float rate = 0;

int hours = 0;

String name = "";

BufferedReader input= new BufferedReader(new InputStreamReader(System.in));

do {

System.out.print("Please enter name, 'stop' to exit program: ");

name = input.readLine();

if (name.equals(STOP)) {

System.out.println("Bye");

}

else {

do {

System.out.println("Enter rate: ");

String rateString = input.readLine();

rate = Float.parseFloat(rateString);

} while (rate <= 0);

do {

System.out.println("Enter hours: ");

String hoursString = input.readLine();

hours = Integer.parseInt(hoursString);

} while (hours < 0 );

Employee employee = new Employee(name, rate, hours);

System.out.println("Name : " + employee.getName());

System.out.println("Rate : " + employee.getHourlyRate());

System.out.println("Hours: " + employee.getHoursWorked());

System.out.println("Total: " + employee.getTotal());

}

} while (!name.equals(STOP));

}

}

class Employee {

private String name;

private float hourlyRate;

private int hoursWorked;

//Default Constructor

public Employee()

{

name = "default";

hourlyRate = 0;

hoursWorked = 0;

}

// Constructor to initialize the employee with the information provided.

public Employee(String name, float hourlyRate, int hoursWorked) {

setName(name);

setHourlyRate(hourlyRate);

setHoursWorked(hoursWorked);

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public float getHourlyRate() {

return hourlyRate;

}

public void setHourlyRate(float hourlyRate) {

this.hourlyRate = hourlyRate;

}

public int getHoursWorked() {

return hoursWorked;

}

public void setHoursWorked(int hoursWorked) {

this.hoursWorked = hoursWorked;

}

public float getTotal() {

float total = hourlyRate * (float)hoursWorked;

return total;

}

}

ronana at 2007-7-21 16:16:33 > top of Java-index,Java Essentials,New To Java...
# 38

Thank You, i went back and reread a couple chapters after getting some rest. I was overthinking it, i had actually jumped ahead by an assignment. Essentially the assignment was asking for two seperate classes, Employee and Payroll, (which i had already done) it was asking for the name,rate,hours to be stored in the employee class and to be retrieved by the payroll class. I had done the assignment correctly. So again thank you for your help.

FSUbounda at 2007-7-21 16:16:33 > top of Java-index,Java Essentials,New To Java...