Page 1 of 3 123 LastLast
Results 1 to 20 of 48
  1. #1
    afrttoh is offline Member
    Join Date
    Nov 2008
    Location
    London
    Posts
    39
    Rep Power
    0

    Default [SOLVED] java method help

    Java Code:
    import javax.swing.JOptionPane;
    public class PayCheckWeek7
    {
    	public static void main(String[] args)
    	{
    		String input = JOptionPane.showInputDialog("What's your name?");
    		String input1 = JOptionPane.showInputDialog("What's your hourly wage?");
    		double n = Double.parseDouble(input1);
    		String input2 = JOptionPane.showInputDialog("how many hours you worked in the past week?");
    		double m = Double.parseDouble(input2);
    	   	
    		if (m > 40)
    		{
    			JOptionPane.showMessageDialog (null,"your wage this week is: " + ((n*m)*1.5));
    		}
    
    		else
    		{
    			JOptionPane.showMessageDialog (null,"your wage this week is: " + (n*m));
    		}
    		
    		     
    		
    	}
    }


    I need to modify the above program. The functionality of the new program should be exactly the same. However, write a method called
    calculatePay, which calculates the total amount of pay. Call this method
    from within the main method, and display its return value. (tried my best and couldnt do it!)
    Last edited by afrttoh; 11-26-2008 at 04:18 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    (tried my best and couldnt do it!)
    it's always best to post your attempt. that way we can see what it is you don't understand. also without your attempt and only with your assignment, the implicit question is assumed to be: "please do my homework for me". And I know that this is not what you want us to do here, right?

  3. #3
    afrttoh is offline Member
    Join Date
    Nov 2008
    Location
    London
    Posts
    39
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    it's always best to post your attempt. that way we can see what it is you don't understand. also without your attempt and only with your assignment, the implicit question is assumed to be: "please do my homework for me". And I know that this is not what you want us to do here, right?
    Thank you!!
    Well this is my attempt as you can see I have created this java program but couldnít create a method as I am a beginner I do practice and read a lot but hey itís not that easy, needs some help!


    One thing I would like to say I have seen many of your posts trying to help other members but non of your post has a real attempt to help its just kind of VERY very limited advice in another word (sorry I cant help you do it yourself or get out of here!)

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Basically what you need is, put that code in another methods and call it in the main method. Result should be display to the console, right?

  5. #5
    afrttoh is offline Member
    Join Date
    Nov 2008
    Location
    London
    Posts
    39
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Basically what you need is, put that code in another methods and call it in the main method. Result should be display to the console, right?
    yes this is what i was trying to do!
    Last edited by afrttoh; 11-26-2008 at 05:07 AM.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    What the new method name and the return data type. Write that method definition only and post it here to see.

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    One thing I would like to say I have seen many of your posts trying to help other members but non of your post has a real attempt to help its just kind of VERY very limited advice in another word (sorry I cant help you do it yourself or get out of here!)
    You can think what you want, and you can choose to read a post or ignore it. You won't be breaking my heart either way. Myself, I stick to my recommendation that you must first attempt to create the calculatePay() method and then show us your attempt. To re-iterate and amplify, How will you every learn to program if you don't push yourself beyond your current limits? how will we know exactly what you don't understand, exactly what mistakes you are making if we don't see this attempt?

    Well? Your call.

    Also, you would do well to read this link to help you get "better" help from me and from others:
    How To Ask Questions The Smart Way

  8. #8
    afrttoh is offline Member
    Join Date
    Nov 2008
    Location
    London
    Posts
    39
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Basically what you need is, put that code in another methods and call it in the main method. Result should be display to the console, right?
    Quote Originally Posted by Eranga View Post
    What the new method name and the return data type. Write that method definition only and post it here to see.
    Definition:

    1- Write a program called PayCheckWeek7.java that asks the user for the
    Following input:
    ētheir name
    ētheir hourly wage
    ēhow many hours they worked in the past week.
    The program should then calculate the pay for the employee,
    assuming that any overtime work (over 40 hours per week) is paid
    at 150 percent of the regular wage. Use a message dialog box to
    display the total pay. You should use variables of type double and
    display the output in pounds.

    >>> I have done this correctly plz find above<<<



    2- based on this program. The functionality of the new program should be exactly the same as the old one. However, this time, write a method called
    calculatePay, which calculates the total amount of pay. Call this method
    from within the main method, and display its return value.

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Ok, can you get three user inputs correctly, with the correct data types? Start from the first line, break your task into simple steps and workout one at a time.

  10. #10
    afrttoh is offline Member
    Join Date
    Nov 2008
    Location
    London
    Posts
    39
    Rep Power
    0

    Default

    I do not have any problems with the first part of the exercise Im only stuck in the 2nd one which is writing a method.
    Last edited by afrttoh; 11-26-2008 at 05:37 AM.

  11. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by afrttoh View Post
    I do not have any problems with the first part of the exercise Im only stuck in the 2nd one which is writing a method.
    You saying that you don't know how to write a method? How did you write the main method, if so.

  12. #12
    afrttoh is offline Member
    Join Date
    Nov 2008
    Location
    London
    Posts
    39
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    You saying that you don't know how to write a method? How did you write the main method, if so.
    I mean writing a different method.

  13. #13
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    There is no different lol. As I said in one of my previous post, since you know the method name, return type and the argument list, just write the method definition and send it to here. Just forget all and do it first.

  14. #14
    afrttoh is offline Member
    Join Date
    Nov 2008
    Location
    London
    Posts
    39
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    There is no different lol. As I said in one of my previous post, since you know the method name, return type and the argument list, just write the method definition and send it to here. Just forget all and do it first.
    thank you i will try and see what happens :)

  15. #15
    afrttoh is offline Member
    Join Date
    Nov 2008
    Location
    London
    Posts
    39
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    You can think what you want, and you can choose to read a post or ignore it. You won't be breaking my heart either way. Myself, I stick to my recommendation that you must first attempt to create the calculatePay() method and then show us your attempt. To re-iterate and amplify, How will you every learn to program if you don't push yourself beyond your current limits? how will we know exactly what you don't understand, exactly what mistakes you are making if we don't see this attempt?

    Well? Your call.

    Also, you would do well to read this link to help you get "better" help from me and from others:
    [......How To Ask Questions The Smart Way[/URL]
    Well I didnít say other members are not helpful did I? To be honest the only member who is not helpful is you.

    and about the link thank you but I already knows this regulations as I am a powerful expert member in some other PHP programming forums just unlucky got little knowledge about java and had to come here to get help!

  16. #16
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by afrttoh View Post
    thank you i will try and see what happens :)
    Try it lol, not a difficult thing actually. Since you have an experience on programming this cannot be difficult at all. We want to see your become expert in Java, that's why we are asking to move in this way. :)

  17. #17
    afrttoh is offline Member
    Join Date
    Nov 2008
    Location
    London
    Posts
    39
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Try it lol, not a difficult thing actually. Since you have an experience on programming this cannot be difficult at all. We want to see your become expert in Java, that's why we are asking to move in this way. :)

    Yes, I know there are a lot of common things between many programming languages and thatís why I didnít find java difficult (I have only started few weeks ago) but I get stuck a lot!! Anyways I know that I will get there eventually... ;)
    Once again thanks for your great help

  18. #18
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  19. #19
    RJ12 is offline Member
    Join Date
    Nov 2008
    Posts
    3
    Rep Power
    0

    Default

    I know I should not do this but try this code (I dont have the java compiler on the computer im using)If the code dosent work try fixing it. Two things
    1.The pay should not be a string along with the hour
    2.you forgot the System.exit(0) function

    Java Code:
    import javax.swing.JOptionPane;
    public class PayCheckWeek7
    {
    	public static void main(String[] args)
    	{
    		String name = JOptionPane.showInputDialog("What's your                       		name?");
    		int hourWage = JOptionPane.showInputDialog("What's 			your 		hourly wage?");
    		double n = Double.parseDouble(input1);
    		int hours = JOptionPane.showInputDialog("how many 			hours you worked in the past week?");
    		double total = hourWage * hours;
    
    	   	JOptionPane.showMessageDialog(null, name + "your pay is      		" + total);
    		System.exit(0)	
    	}
    }

  20. #20
    afrttoh is offline Member
    Join Date
    Nov 2008
    Location
    London
    Posts
    39
    Rep Power
    0

    Default

    Quote Originally Posted by RJ12 View Post
    I know I should not do this but try this code (I dont have the java compiler on the computer im using)If the code dosent work try fixing it. Two things
    1.The pay should not be a string along with the hour
    2.you forgot the System.exit(0) function

    Java Code:
    import javax.swing.JOptionPane;
    public class PayCheckWeek7
    {
    	public static void main(String[] args)
    	{
    		String name = JOptionPane.showInputDialog("What's your                       		name?");
    		int hourWage = JOptionPane.showInputDialog("What's 			your 		hourly wage?");
    		double n = Double.parseDouble(input1);
    		int hours = JOptionPane.showInputDialog("how many 			hours you worked in the past week?");
    		double total = hourWage * hours;
    
    	   	JOptionPane.showMessageDialog(null, name + "your pay is      		" + total);
    		System.exit(0)	
    	}
    }
    Thanks alot,
    i tried it at the moment its giving me this error:

    ---------- Compile Java Source ----------
    PayCheckWeek7.java:13: ';' expected
    System.exit(0)
    ^
    1 error

    Output completed (1 sec consumed)

Page 1 of 3 123 LastLast

Similar Threads

  1. Pls Help me for Newton-Raphson method by Java
    By kienph2004 in forum Advanced Java
    Replies: 3
    Last Post: 08-13-2008, 05:07 PM
  2. Call Java Method
    By hussainzim in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 05-15-2008, 07:22 AM
  3. Any method for improving of java thread
    By code453 in forum Java Applets
    Replies: 0
    Last Post: 12-20-2007, 08:29 AM
  4. Java constructor method
    By carl in forum New To Java
    Replies: 2
    Last Post: 07-31-2007, 02:15 PM
  5. The main method in java...
    By lenny in forum New To Java
    Replies: 1
    Last Post: 07-31-2007, 06:21 AM

Posting Permissions

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