Welcome Guest ( Log In | Register )

      
Discover the best free computer help!
Learn more about Geeks to Go by taking the tour. Spyware, virus, trojan, fake security or privacy alerts? Read the malware cleaning guide.
 
Reply to this topicStart new topic
Need Help with Adding Percents in Java
Scyrus
post Feb 20 2006, 07:09 PM
Post #1


New Member
*
Posts: 8
OS: XP



I'm compiling a program that calculates a person's current salary, then adds:

6% to a person's salary who's rating = 1
4% to a person's salary who's rating = 2
2% to a person's salary who's rating = 3
1% to a person's salary who's rating = 4

Current code:

CODE
import java.util.Scanner;
   import java.text.NumberFormat;
   import java.util.Locale;

public class Project5A1
{
    public static void main (String[] args)
    {
        double currentSalary;
        int rating;
        int raise;
        int double raise = 0;
        
        Scanner scan = new Scanner(System.in);
                
        System.out.print ("Enter the current salary: ");
        currentSalary = scan.nextDouble();
        System.out.print ("Enter the performance rating: ");
        rating = scan.nextInt();
    
    
        NumberFormat dollar = NumberFormat.getCurrencyInstance(Locale.US);
        System.out.println ("Amount of your raise: " + dollar.format(raise));
        System.out.println ("Your new salary: " +
            dollar.format(currentSalary + raise));
        }
    }



I've never done a switch statement, let alone know how it's set up. It's obvious at what the switch statement does, but I wouldn't have a clue how to write it in this program. My book only covers the term but doesn't give an example. I've searched all over the place for an example or instructions but have failed to find any. Any help would be appreciated. Thanks guys

This post has been edited by Scyrus: Feb 20 2006, 07:09 PM
Go to the top of the page
 
+Quote Post
destin
post Feb 20 2006, 08:24 PM
Post #2


Member
**
Posts: 53
OS: Mac OS X



The switch statement's syntax is very easy. Let's use your code for example
CODE

switch (rating) {
    case 1:
        // do logic w/ 6%
        break;
    case 2:
        // do logic w/ 4%
        break;
    case 3:
        // do logic w/ 2%
        break;
    case 4:
        // do logic w/ 1%
        break;
    default:
        break;
}


Btw, I doubt you tried searching for switch statement help.

This post has been edited by destin: Feb 20 2006, 11:00 PM
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 


RSS Time is now: 1st December 2008 - 04:05 PM
Advertisements do not imply our endorsement of that product or service. The forum is run by volunteers who donate their time and expertise. We make every attempt to ensure that the help and advice posted is accurate and will not cause harm to your computer. However, we do not guarantee that they are accurate and they are to be used at your own risk.