Need Help with Adding Percents via 'Switch'


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Need Help with Adding Percents via 'Switch'

  1. #1
    Join Date
    Feb 2006
    Posts
    1

    Need Help with Adding Percents via 'Switch'

    Hey guys, this is my first post and I'm just starting to get into the basics of Java. I've got one small problem thus far; I'm creating a program that displays an employee's current salary, then adds a percentage of money into their original salary from a corresponding "rating" that they recieve. The following is for the score/percent added to their salary: 1 = 6%, 2 = 4%, 3 = 1.5%. Here is my code so far:

    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, newBalance;
    		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();
    		 
    			switch (rating) {
        case 1:
            
            break;
        case 2:
            
            break;
        case 3:
            
            break;
        case 4:
            
            break;
        default:
            break;
    }
    	
    		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));
    		}
    	}
    The output is supposed to look like this: (but I'm stuck on what to insert for the switch methods)

    Code:
    Enter the current salary: 1000
    Enter the performance rating: 1
    Amount of your raise: $60.00
    Your new salary: $1,060.00

    Thanks to all that contribute their help.
    Last edited by scyrusurcys; 02-22-2006 at 08:11 PM.

  2. #2
    Join Date
    Feb 2006
    Posts
    9

    here i had similar case,

    Code:
    import java.util.Scanner;
    import java.text.DecimalFormat;
    
    public class SwitchDemo {
        public static void main(String[] args) {
    
    	double palka,taxu;
    	int taxrate;
    	taxrate =0;
    	      
    
          Scanner scan = new Scanner (System.in);
    
          System.out.print ("Enter the first number: ");
          palka = scan.nextDouble();
    
    	if (palka > 100000)
    	{
    	taxrate = 1;
    	}
    	else if ( palka > 60000 && palka <= 100000)
    	{
    	taxrate =2 ;
    	}
    	else if ( palka > 30000 && palka <= 60000 )
    	{
    	taxrate =3 ;
    	}
    	else if ( palka > 15000 && palka <= 30000)
    	{
    	taxrate =4 ;
    	}
    	else if ( palka > 5000 &&  palka <= 15000 )
    	{
    	taxrate =5 ;
    	}
    	else if ( palka <= 5000  )
    	{
    	taxrate =6 ;
    	}
    
            switch (taxrate) 
    {
                case 1: 
    			taxu = palka * 0.40;
    			System.out.println(" your salary is  " + palka +"so your tax will be  " + taxu );
    			 break;
                case 2:  
    
    			taxu = palka * 0.30;
    			System.out.println(" your salary is  " + palka +"so your tax will be  " + taxu );
    			 break;
                case 3:  
    
    			taxu = palka * 0.20;
    			System.out.println(" your salary is  " + palka +"so your tax will be  " + taxu );
    			 break;
                case 4: 
    		 	taxu = palka * 0.10;
    			System.out.println(" your salary is  " + palka +"so your tax will be  " + taxu );
    			 break;
    	    case 5: 
    		 	taxu = palka * 0.05;
    			System.out.println(" your salary is  " + palka +"so your tax will be  " + taxu );
    			 break;
    	    case 6: 
    		 	taxu = palka * 0.00;
    			System.out.println(" your salary is  " + palka +"so your tax will be  " + taxu );
    			 break;
                
                default: System.out.println("wrong!");break;
            }
        }
    }

  3. #3
    Join Date
    Feb 2006
    Posts
    11
    It looks like you're right there. Just put in what you want for each switch.
    i.e. Case 1:
    raise = salary * .06;

Similar Threads

  1. Replies: 0
    Last Post: 10-22-2002, 06:38 AM
  2. Adding Web Server Controls
    By Maggie Dolinska in forum .NET
    Replies: 0
    Last Post: 02-19-2002, 06:29 PM
  3. Adding Data to a Database Field in VB6
    By Brian Higgins in forum VB Classic
    Replies: 1
    Last Post: 11-27-2001, 12:19 AM
  4. Replies: 1
    Last Post: 11-21-2001, 01:08 PM
  5. Replies: 1
    Last Post: 02-05-2001, 11:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center