Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package loginsystem;
- import java.util.ArrayList;
- import java.util.Random;
- import java.util.Scanner;
- /**
- *
- * @author sebastian
- */
- public class Customer {
- private ArrayList<Account> accountList;
- ArrayList<Account>userList;
- Scanner input = new Scanner(System.in);
- boolean exit = false;
- LogInSystem view;
- Customer(LogInSystem log) {
- this.accountList = new ArrayList();
- this.view = log;
- this.userList = new ArrayList();
- while(!exit){
- view.printLoggedOutMenu();
- int choice = input.nextInt();
- performAction(choice);
- }
- }
- private void performAction(int choice) {
- switch(choice){
- case 1:
- logInScreen();
- break;
- case 2:
- createUser();
- break;
- case 0:
- System.exit(0);
- break;
- default:
- System.out.println("Ett okänt fel inträffade.");
- }
- }
- private void logInScreen() {
- view.printUsernameQuestion();
- String username = input.next();
- view.printPasswordQuestion();
- String password = input.next();
- if(getUserAccountFromAccountList(username,password)==null){
- System.out.println("Inloggningen misslyckades");
- return;
- }
- getUserAccountFromAccountList(username,password);
- while(!exit){
- view.printLoggedInMenu();
- int choice = input.nextInt();
- performActionTwo(choice);
- }
- }
- private void createUser() {
- System.out.println("Personnummer: ");
- String ssn = input.next();
- System.out.println("Välj lösenord");
- String password = input.next();
- if(getSsnFromAccountList(ssn)!= null){
- System.out.println("Det finns redan en användare med det personnummret");
- }
- Account a = new Account(ssn,password);
- addUserAccount(a);
- System.out.println("Du har skapat en ny användare.");
- System.out.println("Personnummer: "+a.getSsn());
- System.out.println("Lösenord: "+a.getPassword());
- }
- public void addUserAccount(Account a){
- this.userList.add(a);
- }
- private Account getSsnFromAccountList(String ssn){
- for(Account a : userList){
- if(a.getSsn().equals(ssn)){
- return a;
- }
- }
- return null;
- }
- private Account getUserAccountFromAccountList(String ssn,String password){
- for(Account a: userList){
- if(a.getSsn().equals(ssn)&&a.getPassword().equals(password)){
- return a;
- }
- }
- return null;
- }
- public ArrayList<Account> getAccountList() {
- return accountList;
- }
- public void setAccountList(ArrayList<Account> accountList) {
- this.accountList = accountList;
- }
- private void performActionTwo(int choice) {
- switch(choice){
- case 1:
- accountDetails();
- break;
- case 2:
- deposit();
- break;
- case 3:
- withdraw();
- break;
- case 4:
- createNewAccount();
- break;
- case 0:
- System.exit(0);
- break;
- default:
- System.out.println("Okänt fel inträffade");
- }
- }
- private void accountDetails() {
- System.out.println("Kontoinformation");
- System.out.println("Kontonummer: Saldo:");
- System.out.println("---------------------------------------");
- for(int i = 0;i < accountList.size();i++){
- System.out.printf("%1d %19d\n",accountList.get(i).getAccountNumber(),accountList.get(i).getBalance(),"\n");
- System.out.println("-----------------------------------");
- }
- }
- private void deposit() {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- private void withdraw() {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- private void createNewAccount() {
- int accountNumber = 0;
- System.out.println("Hur mycket vill du sätta in på kontot?");
- int deposit = input.nextInt();
- Account a = new Account();
- accountNumber = createAccountNumber(accountNumber);
- a.setBalance(deposit);
- a.setAccountNumber(accountNumber);
- addNewAccount(a);
- System.out.println("Du har skapat ett nytt bankkonto!");
- System.out.println("Kontonummer: "+accountNumber);
- System.out.println("Saldo: "+a.getBalance());
- }
- private int createAccountNumber(int accountNumber){
- Random random = new Random();
- accountNumber = random.nextInt(9999+1-1000)+1000;
- return accountNumber;
- }
- private void addNewAccount(Account account){
- this.accountList.add(account);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement