Hey there I'm having trouble with this code in java can anyone help?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Hey there I'm having trouble with this code in java can anyone help?

  1. #1
    Join Date
    Apr 2017
    Posts
    1

    Hey there I'm having trouble with this code in java can anyone help?

    If the total salary is less than 500, the worker will receive 10% bonus. If the salary is between 500 and 1000, the worker will receive 5% bonus.
    the code is as follows but i need to readjust it with ..if etc
    please help as I am a beginner.

    Code:
    import java.util.*;
    
    public class Salary
    {
    
      public static void main (String[] args)
      {
    		Scanner console = new Scanner(System.in);
      		double normal,extra,total;
    		System.out.println("Please Enter number of normal hours: ");
    		normal = console.nextDouble();
    	 	System.out.println("Please Enter number of extra hours: ");
    		extra = console.nextDouble();
    		total = 10*normal+15*extra;
    		System.out.println("Total salary is: "+total+"\n");
       }
    }
    Last edited by 2kaud; April 11th, 2017 at 04:21 AM. Reason: Code tags added

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    18,882

    Re: Hey there I'm having trouble with this code in java can anyone help?

    If it is java then why did you post it to the C++ forum?
    Victor Nijegorodov

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,295

    Re: Hey there I'm having trouble with this code in java can anyone help?

    [Thread moved]

    For info, when posting code please use code tags. Go Advanced, select the formatted code and click '#'.

    Cheers!
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C, C++ Compiler: Microsoft VS2017

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,295

    Re: Hey there I'm having trouble with this code in java can anyone help?

    What do the constants 10 and 15 represent?

    What about if the salary is greater than 1000?

    Consider
    Code:
    if (total < 500) {
       //code for total < 500 here
    } else {
        if (total <= 1000) {
           //code for total between 500 and 1000
        } else {
            //code for total > 1000
        }
    }
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C, C++ Compiler: Microsoft VS2017

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


HTML5 Development Center