Results 1 to 9 of 9
  1. #1
    GhostShaman is offline Member
    Join Date
    Mar 2010
    Posts
    4
    Rep Power
    0

    Question Return Statement and Boolean Help

    Basically I am very new too java, I am an adult student and have been trying to understand return statements and Boolean expressions (used separately or together). The resources that I do have are just not clicking for me, so I was wondering if anyone could give me a crash course. Basically I under stand with Boolean the symbols such as (==, <,>,>=, etc...) but what happens after that I am lost. Like if I was making a simple non gui salary program and wanted to calculate over time. I can not figure out how to get the Boolean to work with the rest of the program. Also with return statements, I am totally lost, every time I try to write code with them it never works, and I also need to know how to print the return.

    I could go posting code on here, and if you guys ask I will, but Im not looking for someone to fix it for me, I just need a little more education, so any help, you can give I greatly appreciate it

    :confused:

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Hi, post the code and ask a specific question. It's hard to get the exact problem without seeing an example. When you post code make sure you use code tags
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    GhostShaman is offline Member
    Join Date
    Mar 2010
    Posts
    4
    Rep Power
    0

    Default

    Well here is what I am working now, its a simple salary non-ui program that letse the user enter total hours worked, and rate of pay, then calculates everything, and if there is over time, adds that into the calculation. IM not done with it but this is what I have so far...

    I just need a better understanding of the two, this book is horrible.

    Java Code:
    import java.util.Scanner;
    public class Salary
    {
    	public static void main(String[] args)
    	{
    		double rPay;
    		double otPay;
    		int hWorked;
    		Scanner keyBoard = new Scanner(System.in);
    		System.out.print("Enter your Hourly Rate  ");
    		rPay = keyBoard.nextInt();
    		System.out.print("Enter Regular Hours worked ");
    		hWorked = keyBoard.nextInt();		
    		System.out.print("Enter Over Time Hours worked ");
    		otPay = keyBoard.nextInt();
    		isOverTimePay(rPay, otPay, hWorked);
    		System.out.println("Your regular weekly salary is $" + (rPay * hWorked));
    		}
    	public static int isOverTimePay(double rPay, double otPay, double hWorked)
    	{
    		int oPay;
    		boolean overTimePay = (hWorked > 40);
    		return oPay;	
    	}
    }

  4. #4
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Ok, so what is the method isOverTimePay supposed to do? The name suggests that it just returns whether there was overtime or not, but the return type is int.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  5. #5
    GhostShaman is offline Member
    Join Date
    Mar 2010
    Posts
    4
    Rep Power
    0

    Default

    Yeah this is where I start to get confused, I was going to have isOverTimePay determine if they were in overt time, and if so, to add a line to calculate their new salary. Ive added and deleted so much code now I don't remember what I have had in there originally. I just dont understand how to get the boolean statement to work and I guess I dont know how return all works too well.

  6. #6
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Uhm, then you have a glitch in the main method. You already asked for Hours worked overtime:
    Java Code:
    System.out.print("Enter Over Time Hours worked ");
    otPay = keyBoard.nextInt();
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  7. #7
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  8. #8
    GhostShaman is offline Member
    Join Date
    Mar 2010
    Posts
    4
    Rep Power
    0

    Default

    basically the assignment says:

    write an application that calculates and displays the weekly salary for an employee. The main() method prompts the user for an hour pay rate, eular hours, and overtime hours. Create a separate method to calculate overtime pay, which is regular hours times the pay rate plus over time hours times 1.5 times the pay rate; return the result to the main() method to be displayed.
    So if I can let me re ask my question:

    I can re-write this and put the formula in place, I guess what I want to ask is could anyone give me an example on how to
    return the result to the main() method to be displayed.
    I cleaned up the code a little and I can "cheat" to get the result but this is not returning to the main method take a look:

    Java Code:
    import java.util.Scanner;
    public class Salary
    {
    	public static void main(String[] args)
    	{
    		double rPay;
    		double otWorked;
    		int hWorked;
    		Scanner keyBoard = new Scanner(System.in);
    		System.out.print("Enter your Hourly Rate  ");
    		rPay = keyBoard.nextInt();
    		System.out.print("Enter Regular Hours worked ");
    		hWorked = keyBoard.nextInt();		
    		System.out.print("Enter Over Time Hours worked ");
    		otWorked = keyBoard.nextInt();
    		isOverTimePay(rPay, otWorked, hWorked);
    		System.out.println("Your regular weekly salary is $ " + (rPay * hWorked));
    		}
    	public static void isOverTimePay(double rPay, double otWorked, double hWorked)
    	{
    		System.out.println("With over time is " + ((otWorked * rPay) * 1.5 + (rPay * hWorked)));
    	}
    }

  9. #9
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Fine, now read the second tutorial I've posted before.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

Similar Threads

  1. Boolean Return Value
    By devstarter in forum New To Java
    Replies: 5
    Last Post: 03-02-2010, 07:45 AM
  2. Help with Recursion and return statement
    By nicolek808 in forum New To Java
    Replies: 3
    Last Post: 09-10-2009, 10:02 AM
  3. problem while using return statement
    By shaluchandran in forum New To Java
    Replies: 10
    Last Post: 12-12-2008, 06:29 PM
  4. there is no return statement
    By gabriel in forum New To Java
    Replies: 17
    Last Post: 12-03-2008, 04:55 PM
  5. [SOLVED] return statement
    By Nakira in forum New To Java
    Replies: 8
    Last Post: 11-12-2008, 11:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •