-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from ifeanyichukwuOtiwa-sports/BP-10010-use-com…
…mand-pattern Bp 10010 use command pattern
- Loading branch information
Showing
10 changed files
with
235 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/io/codewithwinnie/commandstrategy/impl/AddInterestCmd.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.codewithwinnie.commandstrategy.impl; | ||
|
||
import java.util.Scanner; | ||
|
||
import io.codewithwinnie.Bank; | ||
import io.codewithwinnie.commandstrategy.intface.InputCommand; | ||
|
||
/** | ||
* Created by @author Ifeanyichukwu Otiwa | ||
* 27/06/2022 | ||
*/ | ||
|
||
public class AddInterestCmd implements InputCommand { | ||
@Override | ||
public int execute(final Scanner scanner, final Bank bank, final int current) { | ||
bank.addInterest(); | ||
return current; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/io/codewithwinnie/commandstrategy/impl/AuthorizeLoanCmd.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.codewithwinnie.commandstrategy.impl; | ||
|
||
import java.util.Scanner; | ||
|
||
import io.codewithwinnie.Bank; | ||
import io.codewithwinnie.commandstrategy.intface.InputCommand; | ||
|
||
/** | ||
* Created by @author Ifeanyichukwu Otiwa | ||
* 27/06/2022 | ||
*/ | ||
|
||
public class AuthorizeLoanCmd implements InputCommand { | ||
@Override | ||
public int execute(final Scanner scanner, final Bank bank, final int current) { | ||
System.out.println(("Enter loan amount: ")); | ||
int loanAmt = scanner.nextInt(); | ||
if (bank.authorizeLoan(loanAmt, current)) | ||
System.out.println(("Your loan is approved")); | ||
else | ||
System.out.println(("Your loan is denied")); | ||
|
||
return current; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/io/codewithwinnie/commandstrategy/impl/DepositCmd.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.codewithwinnie.commandstrategy.impl; | ||
|
||
import java.util.Scanner; | ||
|
||
import io.codewithwinnie.Bank; | ||
import io.codewithwinnie.commandstrategy.intface.InputCommand; | ||
|
||
/** | ||
* Created by @author Ifeanyichukwu Otiwa | ||
* 25/06/2022 | ||
*/ | ||
|
||
public class DepositCmd implements InputCommand { | ||
@Override | ||
public int execute(final Scanner scanner, final Bank bank, final int current) { | ||
System.out.println("Enter Deposit Amount: "); | ||
int amt = scanner.nextInt(); | ||
bank.deposit(current, amt); | ||
System.out.println("Credit Alert\nYour current balance is " + bank.getBalance(current)); | ||
return current; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Deposit"; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/io/codewithwinnie/commandstrategy/impl/NewCmd.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.codewithwinnie.commandstrategy.impl; | ||
|
||
import java.util.Scanner; | ||
|
||
import io.codewithwinnie.Bank; | ||
import io.codewithwinnie.commandstrategy.intface.InputCommand; | ||
|
||
/** | ||
* Created by @author Ifeanyichukwu Otiwa | ||
* 25/06/2022 | ||
*/ | ||
|
||
public class NewCmd implements InputCommand { | ||
@Override | ||
public int execute(final Scanner scanner, final Bank bank, int current) { | ||
System.out.println("Enter \n\t1 for Foreign\n\t2 for domestic"); | ||
boolean isForeign = scanner.nextInt() == 1; | ||
System.out.println("Enter \n\t1 Savings\n\t2 Regular Checking\n\t3 Interest Checking"); | ||
int type = scanner.nextInt(); | ||
current = bank.newAccount(type, isForeign); | ||
System.out.println("Your new account Number is " + current ); | ||
return current; | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/io/codewithwinnie/commandstrategy/impl/QuitCmd.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.codewithwinnie.commandstrategy.impl; | ||
|
||
import java.util.Scanner; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import io.codewithwinnie.Bank; | ||
import io.codewithwinnie.commandstrategy.intface.InputCommand; | ||
|
||
/** | ||
* Created by @author Ifeanyichukwu Otiwa | ||
* 25/06/2022 | ||
*/ | ||
|
||
public class QuitCmd implements InputCommand { | ||
private static final Logger LOG = LoggerFactory.getLogger(QuitCmd.class); | ||
@Override | ||
public int execute(final Scanner scanner, final Bank bank, final int current) { | ||
LOG.info("Good Bye!"); | ||
return -1; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/io/codewithwinnie/commandstrategy/impl/SelectCmd.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.codewithwinnie.commandstrategy.impl; | ||
|
||
import java.util.Scanner; | ||
|
||
import io.codewithwinnie.Bank; | ||
import io.codewithwinnie.commandstrategy.intface.InputCommand; | ||
|
||
/** | ||
* Created by @author Ifeanyichukwu Otiwa | ||
* 25/06/2022 | ||
*/ | ||
|
||
public class SelectCmd implements InputCommand { | ||
@Override | ||
public int execute(final Scanner scanner, final Bank bank, int current) { | ||
System.out.println("Enter account number: "); | ||
final int curr = scanner.nextInt(); | ||
int balance = bank.getBalance(curr); | ||
System.out.println("the balance of " + curr + " is " + balance); | ||
return curr; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Select"; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/io/codewithwinnie/commandstrategy/impl/SetForeignCmd.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.codewithwinnie.commandstrategy.impl; | ||
|
||
import java.util.Scanner; | ||
|
||
import io.codewithwinnie.Bank; | ||
import io.codewithwinnie.commandstrategy.intface.InputCommand; | ||
|
||
/** | ||
* Created by @author Ifeanyichukwu Otiwa | ||
* 27/06/2022 | ||
*/ | ||
|
||
public class SetForeignCmd implements InputCommand { | ||
@Override | ||
public int execute(final Scanner scanner, final Bank bank, final int current) { | ||
System.out.println("Enter \n\t1 for Foreign\n\t2 for domestic"); | ||
int val = scanner.nextInt(); | ||
bank.setForeign(current, val == 1); | ||
return current; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/io/codewithwinnie/commandstrategy/impl/ShowAllCmd.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.codewithwinnie.commandstrategy.impl; | ||
|
||
import java.util.Scanner; | ||
|
||
import io.codewithwinnie.Bank; | ||
import io.codewithwinnie.commandstrategy.intface.InputCommand; | ||
|
||
/** | ||
* Created by @author Ifeanyichukwu Otiwa | ||
* 27/06/2022 | ||
*/ | ||
|
||
public class ShowAllCmd implements InputCommand { | ||
@Override | ||
public int execute(final Scanner scanner, final Bank bank, final int current) { | ||
System.out.println(bank.toString()); | ||
return current; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/io/codewithwinnie/commandstrategy/intface/InputCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package io.codewithwinnie.commandstrategy.intface; | ||
|
||
import java.util.Scanner; | ||
|
||
import io.codewithwinnie.Bank; | ||
|
||
@FunctionalInterface | ||
public interface InputCommand { | ||
public int execute(Scanner scanner, Bank bank, int current); | ||
} |