Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works

Need Help with Adding Percents in Java

  • Please log in to reply



    New Member

  • Member
  • Pip
  • 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





  • Member
  • PipPip
  • 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%
	case 2:
		// do logic w/ 4%
	case 3:
		// do logic w/ 2%
	case 4:
		// do logic w/ 1%

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

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP