Need Help with Adding Percents in Java |
![]() ![]() |
Need Help with Adding Percents in Java |
Feb 20 2006, 07:09 PM
Post
#1
|
|
|
New Member ![]() Posts: 8 OS: XP |
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 |
|
|
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 |
|
|
![]() ![]() |
Similar Topics
| Topic Title | Replies / Views | Topic Information | |||||
|---|---|---|---|---|---|---|---|
![]() |
5 / 247 | 1st September 2005 - 05:30 PM reedrogue7 started - last by reedrogue7 |
|||||
![]() |
3 / 3,511 | 18th October 2005 - 06:11 PM Santana started - last by greyknight17 |
|||||
![]() |
3 / 311 | 7th February 2006 - 08:59 PM ejay563 started - last by ejay563 |
|||||
![]() |
7 / 268 | 30th October 2008 - 08:08 AM suchaloser started - last by koko_crunch |
|||||
|
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. |