Re: Constructor Help Needed



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

.



Relevant Pages

  • Re: Constructor Help Needed
    ... public double paycheck(double x, double y) ... import java.util.Scanner;//program uses scanner ... {// Start hourly rate loop until positive number is entered ...
    (comp.lang.java.programmer)
  • Re: java.util.Scanner and EOF/EOT issues
    ... The infinite loop isn't in Scanner, ... code just keeps on checking hasNext(). ... recognized by Character.isWhitespace," which includes line delimiters. ...
    (comp.lang.java.programmer)
  • Re: OO Style with Ada Containers
    ... cursors aren't tagged because an operation can only be primitive for a ... Also included is a simple scanner ... while not End_Of_File loop ... (Word: String; ...
    (comp.lang.ada)
  • RE: Thread Events
    ... I've tried putting a loop in my thread. ... I then setscanstop=true in the interrupt handler ... > with built in scanner. ... > the scanner to notify my main thread when it successfully reads a barcode. ...
    (microsoft.public.pocketpc.developer)
  • Re: Still in while loop hell, Now with refined question!
    ... My problem is the while loop. ... scanner usually blocks for whatever reason. ... make an array of lists, which will then be processed in a certain ...
    (comp.lang.java.programmer)