DecisionMakingDemo1.java
1    package com.seleniummaster.javawebdriver.tutorial; 
2     
3    import java.util.Scanner; 
4     
5    /** 
6     * Created by SeleniumMaster on 4/19/2017. 
7     */ 
8    public class DecisionMakingDemo1 { 
9        public static void main(String[] args) { 
10           //if else statement, always uses with relational operators: ==, !=, >, >=, <, <= 
11           //define a scanner object to input withdraw amount 
12           System.out.println("Example 1 for conditional statement"); 
13           Scanner inputAmount = new Scanner(System.in); 
14           System.out.println("Enter the amount to withdraw:  "); 
15           int withdrawAmount = inputAmount.nextInt(); 
16           System.out.println("You entered:  " + withdrawAmount); 
17           //balance 
18           int accountBalance = 10000; 
19           if (withdrawAmount < accountBalance) { 
20               accountBalance = accountBalance - withdrawAmount; 
21               System.out.println(String.format("Your balance is %d", accountBalance)); 
22           } else { 
23               System.out.println("Please enter an amount less than your account balance"); 
24               System.out.println("Your account balance was: " + accountBalance); 
25           } 
26           //use conditional operators ?: 
27           System.out.println("Example 2 for conditional statement"); 
28           int accountBalance2 = 5000; 
29           System.out.println("Your initial balance:   " + accountBalance2); 
30           Scanner inputAmount2 = new Scanner(System.in); 
31           System.out.println("Enter the amount to withdraw:  "); 
32           int withdrawAmount2 = inputAmount2.nextInt(); 
33           System.out.println("You entered:  " + withdrawAmount2); 
34           //balance 
35           int finalBalance = accountBalance2 - withdrawAmount2; 
36           accountBalance2 = withdrawAmount2 < accountBalance2 ? finalBalance : accountBalance2; 
37           System.out.println(String.format("Your balance is %d", accountBalance2)); 
38       } 
39   } 
40