Here is an example where I tried to put them in but it seems everytime
I make a change more errors popup. I haveing a hard time on figuring
how to implement it into the code. Does it have to be after cvertain
events. The variable transfers are confusing to.
// Payroll.java
//This calls the external class scanner
import java.util.Scanner;//program uses scanner
public class PR5
{
//main method begins program execution
public static void main( String args[] )
Employee payroll3 = new Employee(String name, double hours, double
rate );
payroll3.determineWage();
public class Employee
{
private String name;
private double hours;
private double rate;
// if the constructor uses parameter names identical to instance
variable names the "this" reference is required to distinguish between
names
public Employee(String name, double hours, double rate) //constructor
{
this.name = name; // set "this" object's name
this.hours = hours; // set "this" object's hours
this.rate = rate; // set "this" object's rate
}
public void determineWage()
{ // Start Rate Method
// create Scanner to obtain input from command window
Scanner input = new Scanner( System.in );
// Variable Declaration
double rate; // Hourly Rate
double hours; // Hours Worked
//double pay; // Weekly Pay ( Rate * Hours)
//double check;
// Get User Inputs
System.out.printf( "Enter the employee's name (Enter stop when
finished): " );
String name = input.next();
while(!name.equals("stop"));
{ // Start user input loop until "stop" is entered
// Get hourly rate
System.out.printf( "Enter a positive hourly pay rate: " );
rate = input.nextDouble();
while ( rate <= 0 )
{ // Start hourly rate loop until positive number is entered
System.out.printf( "\nHourly rate must be positive: " );
rate = input.nextDouble();
} // End hourly rate loop
// Get hours worked
System.out.printf( "Enter a positive number of hours worked: " );
hours = input.nextDouble();
while ( hours <= 0 )
{ // Start hours loop until positive number is entered
System.out.printf( "\nThe number of hours worked must be positive: "
);
hours = input.nextDouble();}
} // End hours loop
// public class Calculation
//public Employee( rate, hours); {
//}
//{
double pay = rate * hours;
//}
// Return the amount of pay using hours and rate
double pay = paycheck( rate, hours );
// Display results
System.out.printf ( "\nEmployee: %s", name );
System.out.printf( "\nHourly rate: $%.2f\n", rate );
System.out.printf( "\nHours worked: $%.2f\n", hours );
System.out.printf( "\nWeekly paycheck: $%.2f\n", pay);
// Get name to check if loop should continue
System.out.printf( "\n\nEnter the employee's name (Enter stop when
finished): " );
name = input.next();
} // End User input loop
// Returns the paycheck amount based on doubles, rate and hours
}// End Rate Method
public double paycheck( double x, double y)
{ // Start class paycheck
double check = x * y; // Calulate paycheck
return check; // Send the check value back to calling method
} // End class paycheck
} // End of Payroll Class
Chris Smith - 17 Jul 2006 03:44 GMT
> Here is an example where I tried to put them in but it seems everytime
> I make a change more errors popup.
> public class PR5
> {
[quoted text clipped - 3 lines]
> Employee payroll3 = new Employee(String name, double hours, double
> rate );
For one thing, you seem to be missing an open brace for your main method
here.
Secondly, you've got something confused in calling the constructor.
When you define the constructor in the class, you'll include a formal
parameter list like you've got above. But when you use the constructor
to create an object, you need actual values there. Something like:
Employee bob = new Employee("Bob Bobswell", 40.0, 22.50);
> public Employee(String name, double hours, double rate) //constructor
> {
> this.name = name; // set "this" object's name
> this.hours = hours; // set "this" object's hours
> this.rate = rate; // set "this" object's rate
> }
This looks fine. Just fix your use of the class.

Signature
Chris Smith - Lead Software Developer / Technical Trainer
MindIQ Corporation
Mark Space - 17 Jul 2006 05:51 GMT
Just to add a little to what Chris said, but in more general terms.
What you have here is an example of debugging a program. Your program
does something unexpected, and you have to figure out why. It's a good
idea to take every opportunity to practice this skill. Of course,
asking for help is valid also, but at some point in your career you have
to develop some techniques for effective debugging.
One thing I notice about your code is that it's littered with lots of
sections that are commented out. It's really hard to read. And the
basic problem here was that you were missing a brace, which can be hard
to spot, not to mention hard to spot in a program that's also hard to read.
One technique I've seen people use is to completely remove a difficult
problem, then approach it carefully in small steps, make certain each
small step is correct.
For example, one friend in college used to start his programming by
making all files, with nothing in them besides comments. Then he'd
compile that, just to make sure he had everything correct in the
structure of the program. This let him know that he wasn't missing a
start comment like /* somewhere.
Then he'd carefully add some code, usually just the class names and
methods, with no body at all. Fore example, something like this:
// Payroll.java
import java.lang.String;
public class PR5
{
public static void main( String args[] )
{
}
public class Employee
{
public Employee(String name, double hours, double rate)
{
}
}
public void determineWage()
{
}
public double paycheck( double x, double y)
{
} // End class paycheck
} // End of Payroll Class
Then compile that. I notice immediately now that I did this, that you
have a comment "end class paycheck" but paycheck seems to lack a class
keyword. It's a method, not a class. So maybe there is something to
look at. Also, I'm not really sure if determineWage() is part of PR5 or
Employee, your code is really hard to read. You should look at that
then correct it if needed.
Anyway, next you should add some variable declarations, then compile
again. Then add some objects and basic loops, then compile again.
Eventually if you have a syntax error somewhere, it'll be in the last
small thing you added, and much easier to find.
It's a good idea to pay careful attention to braces in indentation.
Make the code easy to read as possible. Then any nesting errors, like
missing a brace, will jump right out at you.
So this is just one little trick you can use when nothing makes any
sense. It takes a bit of time, but if you are really stuck, it'll help
you find your own errors, usually faster than if you wait for someone
else to get back to you with an answer.
> Here is an example where I tried to put them in but it seems everytime
> I make a change more errors popup. I haveing a hard time on figuring
[quoted text clipped - 104 lines]
>
> } // End of Payroll Class