Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account

# Need Help with Adding Percents in Java

### #1 Scyrus Posted 20 February 2006 - 07:09 PM

Scyrus

New Member

• Member
• 8 posts
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:

```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

Edited by Scyrus, 20 February 2006 - 07:09 PM.

• 0

### #2 destin Posted 20 February 2006 - 08:24 PM

destin

Member

• Member
• 53 posts
The switch statement's syntax is very easy. Let's use your code for example
```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.

Edited by destin, 20 February 2006 - 11:00 PM.

• 0

### Similar Topics

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users