forked from nus-cs2113-AY2223S2/tp
-
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 nus-cs2113-AY2223S2#26 from xiaoge26/master
Add create account method
- Loading branch information
Showing
3 changed files
with
41 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,32 @@ | ||
package seedu.bankwithus; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Scanner; | ||
|
||
public class AccountList { | ||
|
||
protected ArrayList<Account> accounts; | ||
private Ui ui; | ||
public AccountList() { | ||
|
||
} | ||
|
||
public AccountList(Scanner scanner) { | ||
|
||
} | ||
|
||
/** | ||
* Creates a new account and adds it to the AccountList. | ||
* | ||
* @param name Name of the new account to be added | ||
* @param balanceString Balance of the new account to be added in String type | ||
* @throws NumberFormatException If balanceString cannot be parsed into a float number | ||
*/ | ||
public void addAccount(String name, String balanceString) throws NumberFormatException { | ||
try { | ||
float balance = Float.parseFloat(balanceString); | ||
Account newAccount = new Account(name, balance); | ||
accounts.add(newAccount); | ||
} catch (NumberFormatException e) { | ||
ui.showNumberFormatError(); | ||
} | ||
} | ||
} |
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
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,16 @@ | ||
package seedu.bankwithus; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
class AccountListTest { | ||
|
||
@Test | ||
void addAccount_invalidBalance_expectException() throws NullPointerException { | ||
String name = "Bob"; | ||
String balanceString = "abc"; | ||
AccountList accountList = new AccountList(); | ||
assertThrows(NullPointerException.class, | ||
() -> accountList.addAccount(name, balanceString)); | ||
} | ||
} |