Solved

Java Methods Weekly Wages

Posted on 2009-04-06
1
421 Views
Last Modified: 2012-06-27
I am having trouble figuring out how to start this assignment.  I am really struggling with my Java class can you please help?  The Assignment is as follows:

Method named initialize that initializes the values of the rate and hours variables to 0 and the
name variable to Any Worker. Void or value-returning method?
2. Method named getHoursRate that prompts the user to input values for the hours worked and
rate of pay per hour and based on those input values changes the values these two variables
were set to by the initialize method above. Void or value-returning method?
3. Method named calculateWages that calculates and returns the amount due the employee based
on the hours worked and rate of pay per hour. The hours worked and rate per hour are stored in
the variables rate and hours respectively. The formula for calculating the amount due the
employee is as follows: for the first 40 hours, the rate is the given rate; for hours over 40, the
rate is 1.5 times the given rate.
4. Method named printCheck that prints (outputs) the named Employee, the hours worked, rate of
pay per hour and the amount due the employee.
5. Modify the main method in the provided WeeklyWages program to use and test each of the
above methods.
We were given this to start with:
 

import java.util.*;
 

public class WeeklyWages

{

    static Scanner console = new Scanner(System.in);

    static double wages, rate, hours;
 

    public static void main(String[] args)

    {

        

        System.out.print("Line 2: Enter the working "

                       + "hours: ");                    //Line 2

        hours = console.nextDouble();                   //Line 3

        System.out.println();                           //Line 4
 

        System.out.print("Line 5: Enter the pay "

                       + "rate: ");                     //Line 5

        rate = console.nextDouble();                    //Line 6

        System.out.println();                           //Line 7
 

        if (hours > 40.0)                               //Line 8

            wages = 40.0 * rate +

                    1.5 * rate * (hours - 40.0);        //Line 9

        else                                            //Line 10

            wages = hours * rate;                       //Line 11
 

        System.out.printf("Line 12: The wages are $%.2f %n",

                           wages);                      //Line 12

        System.out.println();                           //Line 13

    }

}

Open in new window

0
Comment
Question by:claramusic95
1 Comment
 
LVL 15

Accepted Solution

by:
fsze88 earned 500 total points
ID: 24083365

import java.util.*;

 

public class WeeklyWages

{

    static Scanner console = new Scanner(System.in);

    static double wages, rate, hours;

    

    public WeeklyWages(){

      rate = 0;

      hours = 0;

    }

    

    public void initialize (){

      rate = 0;

      hours = 0;

    }

    

    public void getHoursRate (){

        System.out.print("Line 2: Enter the working "

                       + "hours: ");                    //Line 2

        hours = console.nextDouble();                   //Line 3

        System.out.println();                           //Line 4

 

        System.out.print("Line 5: Enter the pay "

                       + "rate: ");                     //Line 5

        rate = console.nextDouble();                    //Line 6

        System.out.println();                           //Line 7

    

    }

    

    public void calculateWages (){

        if (hours > 40.0)                               //Line 8

            wages = 40.0 * rate +

                    1.5 * rate * (hours - 40.0);        //Line 9

        else                                            //Line 10

            wages = hours * rate;                       //Line 11

    

    }

    public void printCheck (){

    

         System.out.printf("Line 12: The wages are $%.2f %n",

                           wages);                      //Line 12

        System.out.println();                           //Line 13

   

    }

    public static void main(String[] args)

    {

      WeeklyWages ww = new WeeklyWages();

      ww.initialize();

      ww.getHoursRate();

      ww.calculateWages();

      ww.printCheck();

      

        

    }

}

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
eclipse formatting 6 73
Java SE 8u111  Lot of stuff broke 11 54
xampp tool 12 30
servlet filter example 37 46
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This video teaches viewers about errors in exception handling.

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now