Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Im lost....

  1. #1
    Junior Member
    Join Date
    Aug 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Im lost....

    I have to write a program that keeps track of hours and pay for a single plumber.

    1. Allow the user to enter the plumber's name, ID and pay rate.
    2. Allow the user to enter the hours worked for each of 5 days. Store the data in an array.
    3. Produce a report that lists the plumbers name, ID and pay rate, the average number of hours worked, the total hours worked and plumbers total pay. ( Take into account overtime which is paid at 1.5 times the pay rate for each hour worked over 40.)

    My teacher expects us to know Java from high school and I was never taught it and I need your help to try and figure this out.



    // houseKeeping()
    int pay;
    int date[] = new int[5];
    int totalhours = 0;
    int payRate = 10;
    int otpay;
    int id;
    int othours;
    String PlumbersName;

    System.out.print("Enter Plumbers Name: ");
    PlumbersName = String.parseInt(input.readLine());

    System.out.print("Enter Plumbers ID: ");
    id = Integer.parseInt(input.readLine());

    System.out.print("Enter Plumbers Pay Rate: ");
    payRate = Integer.parseInt(input.readLine());

    for(counter = 0; counter < 5; counter++)
    {

    date[counter] = 0;
    }

    for(counter = 4; counter >=0; counter--)
    System.out.println("Hours Worked:" + counter + date[counter]);

    System.out.println();

    // workreport()
    pay = totalhours * payRate;
    otpay = othours * payrate * (payrate + (payrate + 1/2));

    I cant get any of this to work....


  2. #2
    Member
    Join Date
    May 2010
    Posts
    36
    Thanks
    0
    Thanked 13 Times in 12 Posts

    Default Re: Im lost....

    i wrote an example for you. the code is not perfect, but runs without errors as long the input is correct. i hope, you got the idea, so you can enhance your own code.

    import java.io.*;
     
    public class ImLost {
    	public static void main(String[] args) {
    		double totalPay;
    		int hoursWorked[] = new int[5];
    		int totalHours = 0;
    		int payRate = 10;
    		double otPay;
    		int id = 0;
    		int otHours;
    		String PlumbersName = "";
     
    		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
     
    		// read the plumbers name, id and pay rate
    		try {
    			System.out.print("Enter Plumbers name: ");
    			PlumbersName = in.readLine();
     
    			System.out.print("Enter Plumbers id: ");
    			id = Integer.parseInt(in.readLine());
     
    			System.out.print("Enter Plumbers Pay Rate: ");
    			payRate = Integer.parseInt(in.readLine());
    		} catch (IOException e) {
    			System.out.println(e.getMessage());
    		}
     
    		// loop 5 times for reading the hours worked
    		for (int counter = 0; counter < hoursWorked.length; counter++) {
     
    			// initialize the array at element counter with 0
    			hoursWorked[counter] = 0;
    			System.out.print("Hours worked day " + (counter + 1) + ": ");
    			try {
    				hoursWorked[counter] = Integer.parseInt(in.readLine());
    			} catch (IOException e) {
    				System.out.println(e.getMessage());
    			}
    		}
     
    		for (int counter = 0; counter < hoursWorked.length; counter++) {
    			System.out
    					.println("Hours Worked " + counter + hoursWorked[counter]);
    			totalHours += hoursWorked[counter];
    		}
     
    		// workreport(), print plumbers parameters
    		System.out.println("Pay report for " + PlumbersName);
    		System.out.println("ID: " + id);
    		System.out.println("Pay rate: " + payRate);
    		// calculations
    		System.out.println("Total of hours worked: " + totalHours);
    		System.out.println("Average of hours worked: " + (totalHours / 5.0));
     
    		if (totalHours > 40) {
    			otHours = totalHours - 40;
    			otPay = otHours * (payRate * 1.5);
    			totalPay = otPay + (40 * payRate);
    			System.out.println("Total pay: " + totalPay);
    		} else {
    			System.out.println("Total pay: " + totalHours * payRate);
    		}
    	}
    }

  3. The Following User Says Thank You to j2me64 For This Useful Post:

    brale76578 (September 2nd, 2010)

Similar Threads

  1. I'm lost
    By stoptheerrors in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 31st, 2010, 09:47 AM
  2. [SOLVED] java Reflection Question - I am lost.
    By prain in forum Java Theory & Questions
    Replies: 3
    Last Post: May 13th, 2010, 03:43 PM
  3. lost
    By nyny in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 7th, 2010, 08:32 AM
  4. Need Help! I'm completly lost!
    By DeMolay8613 in forum Java Theory & Questions
    Replies: 0
    Last Post: January 11th, 2010, 01:21 PM
  5. please could you help me with this java problem im very lost
    By eyeore in forum Java Theory & Questions
    Replies: 4
    Last Post: September 7th, 2009, 10:19 AM