Results 1 to 10 of 10
Like Tree3Likes
  • 1 Post By Norm
  • 1 Post By Norm
  • 1 Post By Tolls

Thread: This code Terminates after typing the input

  1. #1
    mmirbekian is offline Member
    Join Date
    Jul 2016
    Posts
    17
    Rep Power
    0

    Default This code Terminates after typing the input

    my codes gets terminaated by entering the input and doesn't go further.

    Steps: Get the balance
    If (it's before the 14th of the month and the balance is more than INSURANCE,)
    available minus INSURANCE.
    Return the excess.
    If (it's in between the 26th and 17th of the month and the balance is more than CAR,)
    available minus CAR.
    Return the excess.


    public class Phhhn {

    public static void main(String[] args) {
    double excess = 0.0;
    final double INSURANCE = 162;
    final double CAR = 305.00;
    System.out.print("Enter your available balance:");
    Scanner balance1 = new Scanner(System.in);
    double available = balance1.nextDouble();

    Calendar cal = Calendar.getInstance();
    int days = cal.get(Calendar.DAY_OF_MONTH);
    if(days<=14 && available> INSURANCE){
    excess= available-INSURANCE;
    System.out.print("You can withdraw" + excess);
    }
    if(days < 26 && days > 17 && available> CAR){
    excess =available - CAR;
    System.out.print("You can withdraw" + excess);
    }
    }
    }
    Output:
    <terminated>
    Enter your balance: 500.00
    Last edited by mmirbekian; 07-17-2016 at 12:04 AM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: This code Terminates after typing the input

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.

    Please copy the contents of the console from when you execute the code and paste it here so we can see what happens.
    mmirbekian likes this.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    mmirbekian is offline Member
    Join Date
    Jul 2016
    Posts
    17
    Rep Power
    0

    Default Re: This code Terminates after typing the input

    Output:
    <terminated>
    Enter your balance: 500.00

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: This code Terminates after typing the input

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: This code Terminates after typing the input

    That is clearly not the output of the posted code.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  6. #6
    mmirbekian is offline Member
    Join Date
    Jul 2016
    Posts
    17
    Rep Power
    0

    Default Re: This code Terminates after typing the input

    Quote Originally Posted by Norm View Post
    Please edit your post and wrap your code with code tags:

    Java Code:
    public class Phhhn {
    
    public static void main(String[] args) {
    double excess = 0.0;
    final double INSURANCE = 162;
    final double CAR = 305.00;
    System.out.print("Enter your available balance:");
    Scanner balance1 = new Scanner(System.in);
    double available = balance1.nextDouble();
    
    Calendar cal = Calendar.getInstance();
    int days = cal.get(Calendar.DAY_OF_MONTH);
    if(days<=14 && available> INSURANCE){
    excess= available-INSURANCE;
    System.out.print("You can withdraw" + excess);
    }
    if(days < 26 && days > 17 && available> CAR){
    excess =available - CAR;
    System.out.print("You can withdraw" + excess);
    }
    }
    }
    Enter your available balance: 500.00
    Norm I don't know if it's right this time..
    Last edited by Norm; 07-18-2016 at 04:03 PM. Reason: [parse tags removed

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: This code Terminates after typing the input

    That's one step - the code now has highlights, however it has lost all its indentations.
    You need to copy the source from your IDE and paste it here inside of the code tags.

    What do you expect the program's output to be?
    Please explain why you think the program should have any output. If none of the if statements are true, the print statements will not be executed.
    mmirbekian likes this.
    If you don't understand my response, don't ignore it, ask a question.

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: This code Terminates after typing the input

    Java Code:
    int days = cal.get(Calendar.DAY_OF_MONTH);
    if(days<=14 && available> INSURANCE){
        excess= available-INSURANCE;
        System.out.print("You can withdraw" + excess);
    }
    if(days < 26 && days > 17 && available> CAR){
        excess =available - CAR;
        System.out.print("You can withdraw" + excess);
    }
    These are the only output after the prompt to enter a balance.
    To see which of these it might go down, print out the value of 'days' and 'available' before the first 'if' statement.
    Just on the days side I can spot a number of valid 'day' values that will fall through the gap in the logic.
    mmirbekian likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  9. #9
    mmirbekian is offline Member
    Join Date
    Jul 2016
    Posts
    17
    Rep Power
    0

    Default Re: This code Terminates after typing the input

    u r totally right.. there is a logical problem..I'm working on it

  10. #10
    mmirbekian is offline Member
    Join Date
    Jul 2016
    Posts
    17
    Rep Power
    0

    Default Re: This code Terminates after typing the input

    Quote Originally Posted by Norm View Post
    That's one step - the code now has highlights, however it has lost all its indentations.
    You need to copy the source from your IDE and paste it here inside of the code tags.

    What do you expect the program's output to be?
    Please explain why you think the program should have any output. If none of the if statements are true, the print statements will not be executed.
    now it works !
    Thanks alot
    sorry I felt a little bit sleepy.. forgot my else statement
    Java Code:
    import java.util.Calendar;
    import java.util.Scanner;
    
    public class Phhhn {
    	
    	    public static void main(String[] args) {
    	    	int excess = 0;
    	    	int insurance = 162;
    	    	int car = 305;
    	    	System.out.print("Enter your available balance:");
    	    	Scanner balance1 = new Scanner(System.in);
    	    	int available = balance1.nextInt();
    	    	Calendar cal = Calendar.getInstance();
    	    	int days = cal.get(Calendar.DAY_OF_MONTH);
    	    	System.out.println("Today is: " + days);
    	    	
    	    	if(days <= 14 && available > insurance){
    	    		excess= available - insurance;
    	    		System.out.println("You can withdraw: " + excess);
    	    	}
    	    	else if(days < 26 && days > 17 && available> car){
    	    		excess =available - car;
    	    		System.out.println("You can withdraw: " + excess);
    	    	}
    	    	else {
    	    		System.out.print("cheers");
    	    	}
    	     }
    	 }

Similar Threads

  1. Program terminates when i try to run it
    By vincentdotts in forum New To Java
    Replies: 3
    Last Post: 03-15-2015, 02:59 AM
  2. Replies: 7
    Last Post: 03-05-2013, 09:19 AM
  3. My program terminates before letting me enter an answer
    By soradogoof in forum New To Java
    Replies: 2
    Last Post: 09-22-2011, 01:01 AM
  4. Replies: 7
    Last Post: 11-23-2009, 08:42 AM
  5. Application automatically terminates
    By PaulT in forum Eclipse
    Replies: 4
    Last Post: 03-18-2009, 05:02 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
  •