I need help with my homework!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tikney5
    New Member
    • Feb 2008
    • 1

    I need help with my homework!

    I need to modify my current program so that is uses a class to store and retrieve the employees name, hourly rate, and number of hourse 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 terminiate. Below is my previous code and some of what I think I need for this assignment. Any help would be great. Thanks.
    [CODE=Java]
    import java.util.Scann er; //program uses class Scanner

    public class EmployeePayroll 2
    {
    //main method begins execution of Java Application
    public static void main(String args[])
    {
    //create scanner to obtain input from command window
    Scanner input= new Scanner ( System.in);


    String employeeName="" ; //input employee name
    double hourlyRate; //employees hourly rate
    double hoursWorked; //hours worked for the week
    double sum; //employees weekly pay




    System.out.prin t("Enter Name of Employee:");//prompt
    employeeName=in put.next();//read name from user


    while (!employeeName. equals("stop")) //ends program after entering stop
    {

    System.out.prin t("Enter hourly rate:");//prompt
    hourlyRate = input.nextDoubl e(); //read rate from user


    while (hourlyRate<0.0 ) //starts while loop to be sure number entered is positive
    {
    System.out.prin t("Hourly rate must be a positive number. Please enter a positive hourly rate:");//prompt
    hourlyRate=inpu t.nextDouble();//read first number
    input.nextLine( );//prompt user for input
    }//end while

    System.out.prin t("Enter hours worked:");//prompt
    hoursWorked = input.nextDoubl e(); //read hours worked from user


    while (hoursWorked<0. 0) //Is number entered positive
    {

    System.out.prin t("Hours worked must be a positive number. Please enter a positive number of hours:");//prompt
    hoursWorked=inp ut.nextDouble() ;//read second number
    input.nextLine( );//prompt


    }
    sum= hourlyRate * hoursWorked; //multiply numbers

    System.out.prin tf("The employee %s was paid $ %.2f this week", employeeName, sum);
    //display name and sum

    System.out.prin t("Enter Name of Employee-Enter stop to end:");//prompt
    employeeName=in put.nextLine();//read name form user

    }//end while loop



    }//end method main

    }//end class EmployeePayroll 2


    New stuff I know it is horrible!

    public class Employee
    {

    private String employeeName; //input employee name
    private double hourlyRate;//employees hourly rate
    private int hoursWorked; //employee hours worked


    public Employee(String employeeName, double hourlyRate, int hoursWorked){
    // constructor for an employee object
    employeeName = employeeName;
    hourlyRate = hourlyRate;
    hoursWorked = hoursWorked;
    }

    public Employee(String employeeName, double hourlyRate){
    // overload of the constructor to set a default 40 hour work week

    }

    // get methods

    public String getemployeeName (){
    return employeeName;
    }

    public int gethoursWorked( ){
    return hoursWorked;
    }

    public double gethourlyRate() {
    return hourlyRate;
    }

    // getter method to calculate and return the total

    public double getTotal(){
    return (hoursWorked * hourlyRate);
    }
    }[/CODE]
    Last edited by BigDaddyLH; Feb 15 '08, 06:47 PM. Reason: code tags
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    Please enclose your posted code in [code] tags (See How to Ask a Question).

    This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

    Please use [code] tags in future.

    MODERATOR

    Comment

    Working...