0

Hi i am practicing java and just learning java for few days. i need to subtract the scholarship amount of 500000 by 100000 but i seemed to be stuck on 400000 and it does not continue. What is wrong with my code please someone help me. Thanks in advance.

import java.util.Scanner;
import java.util.LinkedList;

public class Main
{
   public static void main(String [] args)
   {
      Scanner input = new Scanner(System.in);
      Application a = new Application();
      LinkedList lList = new LinkedList();
      boolean bEligible = false;
      int scholarship = 100000;
      int scholarshipAmount = 500000;
      int amount;

      while(scholarshipAmount != 0)
      {
         System.out.println("Please enter name");
         a.setsName(input.nextLine());

         System.out.println("1–Pre Diploma, 2–Diploma, 3–Degree");
         System.out.println("Please enter your Study Level");
         a.setiStudyLevel(input.nextInt());

         System.out.println("Please enter your Personality Score");
         a.setiPersonalityScore(input.nextInt());

         System.out.println("Please enter your Parents Incomee");
         a.setdParentsIncome(input.nextDouble());

         String sName = a.getsName();
         int iStudyLevel = a.getiStudyLevel();
         int iPersonalityScore = a.getiPersonalityScore();
         double dParentsIncome = a.getdParentsIncome();

         if(iPersonalityScore <=90)
         {
            if(dParentsIncome >=3000)
            {
               System.out.println("you are not eligible for scholarship ");
            }
            else
            {
               System.out.println("you are eligible for scholarship ");
               bEligible = true;
            }
         }
         else
         {
            System.out.println("you are eligible for scholarship ");
         }


         System.out.println(sName);
         System.out.println(iStudyLevel);
         System.out.println(iPersonalityScore);
         System.out.println(dParentsIncome);

         amount = scholarshipAmount - scholarship;

         System.out.println(amount);
      }
   }
}
Jeff Ward
  • 1,109
  • 6
  • 17
ace
  • 9
  • 2
  • Probably related with http://stackoverflow.com/questions/7056749/scanner-issue-when-using-nextline-after-nextxxx – Christian Tapia Jun 02 '14 at 18:26
  • i am sorry but that question doesn't have to do with while loop. am sorry if am not mistaken – ace Jun 02 '14 at 18:29
  • Just as a head's up, you'll have other issues with this code soon. Check out this page for the size that `int`s can hold: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html – Jeremy J Starcher Jun 02 '14 at 18:45

1 Answers1

6

You are never changing the scholarshipAmount amount

You need to do this

 scholarshipAmount = scholarshipAmount - scholarship;

and you will then need to change this

System.out.println(amount);

to

System.out.println(scholarshipAmount );
David Pilkington
  • 13,528
  • 3
  • 41
  • 73
  • Ace, as David points out, you're never modifying the variable that the loop condition is being checked against. You may also want to consider using a for loop since you're always subtracting the same thing and to ensure you're modifying your loop condition (`for(;scholarshipAmount != 0; scholarshipAmount -= scholarship)`). Finally, you may also want to consider changing your condition to `scholarshipAmount > 0` that way your loop ends if the amount somehow becomes negative. – user3507600 Jun 02 '14 at 18:34
  • @ace If you are happy with the answer please can you accept it so that the issue can be closed – David Pilkington Jun 03 '14 at 05:17