0

okay sorry if this is a really dumb question (im really new to java) but how do I set weather the user imputed savings or checking to to one of the if else statements. ex if I wanted to deposit 500 to checking or savings and I input savings but how do I tell java which account they selected so it can deposit or withdraw?

package javaapplication3;

import java.util.Scanner

public class Transfer 
{
    public static void main(String[] args)
    {
        int checking = 1000;
        int savings = 1000;
        int amount = 0;


        Scanner in = new Scanner(System.in);
        System.out.println("ballance of checking: " + checking );
        System.out.println("ballance of savings: " + savings );
        System.out.println("What is the ammount you wish to deposit, transfer, or withdraw?: " );
        amount = in.nextInt();
        if    (amount < 0 )
        {
           System.out.println("sorry you cant do that please only input positive amounts"); 

        }
        else
        {
            System.out.println(amount);
        }
        System.out.println("which account will you be useing checking or savings? : " );
        String account = in.next();
        if (account.equals("checking"))
        {
            System.out.println("ballance of checking: " + checking );
        }    
        else if (account.equals("savings"))
        {
            System.out.println("ballance of savings: " + savings );
        }
        else 
        {
        System.out.println("something went wrong"  );
        }
        System.out.println(" will you be transferring depositing or withdrawing?: " );
        String action = in.next();
        if (action.equals("transfering"))
        {
            System.out.println("transferring: " + amount);
            System.out.println("account: " + account );

        }
        else if (action.equals("depositing"))   
        {  
        System.out.println("depositing: " + amount);
        System.out.println("account: " + account );

        }      
        else if (action.equals("withdrawing"))            
        {
            System.out.println("withdrawing: " + amount );
            System.out.println("account: " + account );


        }        
        else
        {
        System.out.println("something went wrong: ");
        }
        System.out.println("ballance of checking: " + checking );
        System.out.println("ballance of savings: " + savings );


    }        
}

1 Answers1

0

The first in.nextInt(); did not consume the carriage return. Do like this :

        amount = in.nextInt();
        in.nextLine();
        if    (amount < 0 )
        {
           System.out.println("sorry you cant do that please only input positive amounts"); 

        }
        else
        {
            System.out.println(amount);
        }
        System.out.println("which account will you be useing checking or savings? : " );
        String account = in.next();
ToYonos
  • 16,469
  • 2
  • 54
  • 70