Results 1 to 4 of 4

Thread: loop

  1. #1
    durdanto is offline Member
    Join Date
    Feb 2011
    Posts
    20
    Rep Power
    0

    Default loop

    I am trying to make loop that does the following:

    It calculates tax based on status that is promted to user to enter.
    so i did the following:
    Java Code:
    System.out.println("Welcome to Revenue Agency Taxation");
    
    System.out.println("\nTax filing status can be as follows:" +
    "\n(0-single, 1-married, 2-widowed, 2-living common-law, 4-to quit this program)");
    
    Scanner myKeyboard = new Scanner(System.in);
    System.out.print("\nEnter the filing status: ");
    int i = myKeyboard.nextInt();
    while (i<4 & i>=0)
    {....
    }
    Then i put the required algorithm for calculation which works fine.
    But loop keeps promting to enter Income once calculation is done, Not the Status.
    I can not figure out how can i make it promt user to enter "filing Status"

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    You seem to be asking to for filing status outside the the loop, try moving it inside the loop.

  3. #3
    durdanto is offline Member
    Join Date
    Feb 2011
    Posts
    20
    Rep Power
    0

    Default

    I tried out many thing...
    for (int j = 0; j < 2; j++)

    but it seems that it gets stuck on that loop(keep promting Income), does not end the loop once the filing status is entered.

    I want the following:

    Tax filing status can be as follows:
    (0-single, 1-married, 2-widowed, 3-living common-law, 4-to quit this program)
    Enter the filing status: 0
    Enter the taxable income in $ 400000
    Tax is $117683.5
    Tax filing status can be as follows:
    (0-single, 1-married, 2-widowed, 3-living common-law, 4-to quit this program)
    Enter the filing status: 3
    Enter the taxable income in $ 400000
    Tax is $114360.0


    But i keep getting this:

    Tax filing status can be as follows:
    (0-single, 1-married, 2-widowed, 2-living common-law, 4-to quit this program)

    Enter the filing status: 0
    Enter the taxable income in $ 4000000
    Tax is $1377683.5

    Enter the taxable income in $
    (It does not ask for Status)

  4. #4
    durdanto is offline Member
    Join Date
    Feb 2011
    Posts
    20
    Rep Power
    0

    Default

    Here is my code that i have done so far:

    Java Code:
    	public static void main(String[] args) 
    	{
    		
    		
    		//Welcome message:
    		System.out.println("Welcome to Revenue Agency Taxation");
    		System.out.println("\nTax filing status can be as follows:" +
    				"\n(0-single, 1-married, 2-widowed, 2-living common-law, 4-to quit this program)");
    		
    		
    		//Scanner
    		
    		Scanner myKeyboard = new Scanner(System.in);
    		
    		
    		System.out.print("\nEnter the filing status: ");
    		
    		
    		//program starting algorithm:
    		
    		double [] rates= {0.10, 0.15, 0.25, 0.28, 0.33, 0.35}; 
    		double[][] brackets = {
    							{8350, 33950, 82250, 171550, 372950},   //single
    							{16700, 20885, 67900, 137050, 372950},  // Married
    							{8350, 33950, 68525, 104425, 186475},   // Widowed
    							{11950, 45500, 117450, 190200, 372950}  // Living common-law
    							};
    		
    		
    		
    		int i = myKeyboard.nextInt();
    		while (i<4 & i>=0)
    		{
    			
    			System.out.print("\nEnter the taxable income in $ ");
    			double income = myKeyboard.nextDouble();
    			
    			
    			
    			//tax calculation:
    			double tax = 0;
    			
    			
    			{[COLOR="Red"]TAX-Algorithm[/COLOR]}
    				
    			
    				System.out.println("\nTax is $" + tax );
    		}
    		System.out.println("\nGood Bye" );
    		
    		
    		}
    
    }

Similar Threads

  1. JTextField loop 2x for-loop WEIRD!
    By Streetproject in forum AWT / Swing
    Replies: 2
    Last Post: 02-16-2011, 06:46 PM
  2. [Q] Loop issue (while loop)
    By iriscience in forum New To Java
    Replies: 9
    Last Post: 01-31-2011, 05:21 PM
  3. Convert do while loop to for loop
    By sandeeptheviper in forum New To Java
    Replies: 3
    Last Post: 01-03-2011, 01:37 PM
  4. Replies: 5
    Last Post: 04-30-2010, 06:05 PM
  5. while-loop stopping on first loop
    By davester in forum New To Java
    Replies: 6
    Last Post: 06-26-2009, 09:46 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •