Pārlūkot izejas kodu

made sure all the intellij stuff works

Kr Younger 6 gadus atpakaļ
vecāks
revīzija
e9c37d4af8
11 mainītis faili ar 100 papildinājumiem un 495 dzēšanām
  1. 99
    20
      .gitignore
  2. 0
    43
      Account.java
  3. 0
    44
      AccountData.java
  4. 0
    38
      ActionResult.java
  5. 0
    52
      Bank.java
  6. 0
    11
      BasicAccount.java
  7. 0
    75
      CashMachine.java
  8. 0
    78
      CashMachineApp.java
  9. 0
    18
      PremiumAccount.java
  10. 1
    1
      README.TXT
  11. 0
    115
      package.bluej

+ 99
- 20
.gitignore Parādīt failu

@@ -1,27 +1,106 @@
1
-*.class
1
+.metadata
2
+bin/
3
+tmp/
4
+*.tmp
5
+*.bak
6
+*.swp
7
+*~.nib
8
+local.properties
9
+.settings/
10
+.loadpath
11
+.recommenders
2 12
 
3
-# BlueJ files
4
-*.ctxt
13
+# External tool builders
14
+.externalToolBuilders/
5 15
 
6
-# Package Files #
7
-*.war
8
-*.ear
16
+# Locally stored "Eclipse launch configurations"
17
+*.launch
9 18
 
10
-# Eclipse #
11
-.classpath
12
-.project
13
-.settings/
14
-bin/
19
+# PyDev specific (Python IDE for Eclipse)
20
+*.pydevproject
21
+
22
+# CDT-specific (C/C++ Development Tooling)
23
+.cproject
24
+
25
+# Java annotation processor (APT)
26
+.factorypath
27
+
28
+# PDT-specific (PHP Development Tools)
29
+.buildpath
30
+
31
+# sbteclipse plugin
32
+.target
33
+
34
+# Tern plugin
35
+.tern-project
36
+
37
+# TeXlipse plugin
38
+.texlipse
39
+
40
+# STS (Spring Tool Suite)
41
+.springBeans
42
+
43
+# Code Recommenders
44
+.recommenders/
15 45
 
16
-# IDEA #
17
-.idea/
46
+# Scala IDE specific (Scala & Java development for Eclipse)
47
+.cache-main
48
+.scala_dependencies
49
+.worksheet
50
+
51
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
52
+# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
53
+
54
+# User-specific stuff:
55
+.idea/**
56
+.idea/**/tasks.xml
57
+.idea/dictionaries
58
+
59
+# Sensitive or high-churn files:
60
+.idea/**/dataSources/
61
+.idea/**/dataSources.ids
62
+.idea/**/dataSources.xml
63
+.idea/**/dataSources.local.xml
64
+.idea/**/sqlDataSources.xml
65
+.idea/**/dynamic.xml
66
+.idea/**/uiDesigner.xml
67
+
68
+# Gradle:
69
+.idea/**/gradle.xml
70
+.idea/**/libraries
71
+.idea/*
18 72
 *.iml
19
-out/
20 73
 
21
-# Maven #
22
-dependency-reduced-pom.xml
23
-target/
74
+# CMake
75
+cmake-build-debug/
76
+
77
+# Mongo Explorer plugin:
78
+.idea/**/mongoSettings.xml
79
+
80
+## File-based project format:
81
+*.iws
82
+
83
+## Plugin-specific files:
24 84
 
25
-# logs #
26
-*.log
27
-logs/
85
+# IntelliJ
86
+/out/
87
+
88
+# mpeltonen/sbt-idea plugin
89
+.idea_modules/
90
+
91
+# JIRA plugin
92
+atlassian-ide-plugin.xml
93
+
94
+# Cursive Clojure plugin
95
+.idea/replstate.xml
96
+
97
+# Crashlytics plugin (for Android Studio and IntelliJ)
98
+com_crashlytics_export_strings.xml
99
+crashlytics.properties
100
+crashlytics-build.properties
101
+fabric.properties
102
+target/*
103
+
104
+.project
105
+.classpath
106
+.settings

+ 0
- 43
Account.java Parādīt failu

@@ -1,43 +0,0 @@
1
- 
2
-
3
-/**
4
- * @author ZipCodeWilmington
5
- */
6
-public abstract class Account {
7
-
8
-    private AccountData accountData;
9
-
10
-    public Account(AccountData accountData) {
11
-        this.accountData = accountData;
12
-    }
13
-
14
-    public AccountData getAccountData() {
15
-        return accountData;
16
-    }
17
-
18
-    public void deposit(int amount) {
19
-        updateBalance(getBalance() + amount);
20
-    }
21
-
22
-    public boolean withdraw(int amount) {
23
-        if (canWithdraw(amount)) {
24
-            updateBalance(getBalance() - amount);
25
-            return true;
26
-        } else {
27
-            return false;
28
-        }
29
-    }
30
-
31
-    protected boolean canWithdraw(int amount) {
32
-        return getBalance() >= amount;
33
-    }
34
-
35
-    public int getBalance() {
36
-        return accountData.getBalance();
37
-    }
38
-
39
-    private void updateBalance(int newBalance) {
40
-        accountData = new AccountData(accountData.getId(), accountData.getName(), accountData.getEmail(),
41
-                newBalance);
42
-    }
43
-}

+ 0
- 44
AccountData.java Parādīt failu

@@ -1,44 +0,0 @@
1
- 
2
-
3
-/**
4
- * @author ZipCodeWilmington
5
- */
6
-public final class AccountData {
7
-
8
-    private final int id;
9
-    private final String name;
10
-    private final String email;
11
-
12
-    private final int balance;
13
-
14
-    AccountData(int id, String name, String email, int balance) {
15
-        this.id = id;
16
-        this.name = name;
17
-        this.email = email;
18
-        this.balance = balance;
19
-    }
20
-
21
-    public int getId() {
22
-        return id;
23
-    }
24
-
25
-    public String getName() {
26
-        return name;
27
-    }
28
-
29
-    public String getEmail() {
30
-        return email;
31
-    }
32
-
33
-    public int getBalance() {
34
-        return balance;
35
-    }
36
-
37
-    @Override
38
-    public String toString() {
39
-        return "Account id: " + id + '\n' +
40
-                "Name: " + name + '\n' +
41
-                "Email: " + email + '\n' +
42
-                "Balance: " + balance;
43
-    }
44
-}

+ 0
- 38
ActionResult.java Parādīt failu

@@ -1,38 +0,0 @@
1
- 
2
-
3
-/**
4
- * @author ZipCodeWilmington
5
- */
6
-public class ActionResult<T> {
7
-
8
-    private T data;
9
-    private String errorMessage;
10
-
11
-    private ActionResult(T data) {
12
-        this.data = data;
13
-    }
14
-
15
-    private ActionResult(String errorMessage) {
16
-        this.errorMessage = errorMessage;
17
-    }
18
-
19
-    public T getData() {
20
-        return data;
21
-    }
22
-
23
-    public String getErrorMessage() {
24
-        return errorMessage;
25
-    }
26
-
27
-    public boolean isSuccess() {
28
-        return data != null;
29
-    }
30
-
31
-    public static <E> ActionResult<E> success(E data) {
32
-        return new ActionResult<E>(data);
33
-    }
34
-
35
-    public static <E> ActionResult<E> fail(String errorMessage) {
36
-        return new ActionResult<E>(errorMessage);
37
-    }
38
-}

+ 0
- 52
Bank.java Parādīt failu

@@ -1,52 +0,0 @@
1
- 
2
-
3
-//import rocks.zipcode.atm.ActionResult;
4
-
5
-import java.util.HashMap;
6
-import java.util.Map;
7
-
8
-/**
9
- * @author ZipCodeWilmington
10
- */
11
-public class Bank {
12
-
13
-    private Map<Integer, Account> accounts = new HashMap<>();
14
-
15
-    public Bank() {
16
-        accounts.put(1000, new BasicAccount(new AccountData(
17
-                1000, "Example 1", "example1@gmail.com", 500
18
-        )));
19
-
20
-        accounts.put(2000, new PremiumAccount(new AccountData(
21
-                2000, "Example 2", "example2@gmail.com", 200
22
-        )));
23
-    }
24
-
25
-    public ActionResult<AccountData> getAccountById(int id) {
26
-        Account account = accounts.get(id);
27
-
28
-        if (account != null) {
29
-            return ActionResult.success(account.getAccountData());
30
-        } else {
31
-            return ActionResult.fail("No account with id: " + id + "\nTry account 1000 or 2000");
32
-        }
33
-    }
34
-
35
-    public ActionResult<AccountData> deposit(AccountData accountData, int amount) {
36
-        Account account = accounts.get(accountData.getId());
37
-        account.deposit(amount);
38
-
39
-        return ActionResult.success(account.getAccountData());
40
-    }
41
-
42
-    public ActionResult<AccountData> withdraw(AccountData accountData, int amount) {
43
-        Account account = accounts.get(accountData.getId());
44
-        boolean ok = account.withdraw(amount);
45
-
46
-        if (ok) {
47
-            return ActionResult.success(account.getAccountData());
48
-        } else {
49
-            return ActionResult.fail("Withdraw failed: " + amount + ". Account has: " + account.getBalance());
50
-        }
51
-    }
52
-}

+ 0
- 11
BasicAccount.java Parādīt failu

@@ -1,11 +0,0 @@
1
- 
2
-
3
-/**
4
- * @author ZipCodeWilmington
5
- */
6
-public class BasicAccount extends Account {
7
-
8
-    public BasicAccount(AccountData accountData) {
9
-        super(accountData);
10
-    }
11
-}

+ 0
- 75
CashMachine.java Parādīt failu

@@ -1,75 +0,0 @@
1
- 
2
-
3
-//import rocks.zipcode.atm.bank.AccountData;
4
-//import rocks.zipcode.atm.bank.Bank;
5
-
6
-import java.util.function.Consumer;
7
-import java.util.function.Supplier;
8
-
9
-/**
10
- * @author ZipCodeWilmington
11
- */
12
-public class CashMachine {
13
-
14
-    private final Bank bank;
15
-    private AccountData accountData = null;
16
-
17
-    public CashMachine(Bank bank) {
18
-        this.bank = bank;
19
-    }
20
-
21
-    private Consumer<AccountData> update = data -> {
22
-        accountData = data;
23
-    };
24
-
25
-    public void login(int id) {
26
-        tryCall(
27
-                () -> bank.getAccountById(id),
28
-                update
29
-        );
30
-    }
31
-
32
-    public void deposit(int amount) {
33
-        if (accountData != null) {
34
-            tryCall(
35
-                    () -> bank.deposit(accountData, amount),
36
-                    update
37
-            );
38
-        }
39
-    }
40
-
41
-    public void withdraw(int amount) {
42
-        if (accountData != null) {
43
-            tryCall(
44
-                    () -> bank.withdraw(accountData, amount),
45
-                    update
46
-            );
47
-        }
48
-    }
49
-
50
-    public void exit() {
51
-        if (accountData != null) {
52
-            accountData = null;
53
-        }
54
-    }
55
-
56
-    @Override
57
-    public String toString() {
58
-        return accountData != null ? accountData.toString() : "Try account 1000 or 2000 and click submit.";
59
-    }
60
-
61
-    private <T> void tryCall(Supplier<ActionResult<T> > action, Consumer<T> postAction) {
62
-        try {
63
-            ActionResult<T> result = action.get();
64
-            if (result.isSuccess()) {
65
-                T data = result.getData();
66
-                postAction.accept(data);
67
-            } else {
68
-                String errorMessage = result.getErrorMessage();
69
-                throw new RuntimeException(errorMessage);
70
-            }
71
-        } catch (Exception e) {
72
-            System.out.println("Error: " + e.getMessage());
73
-        }
74
-    }
75
-}

+ 0
- 78
CashMachineApp.java Parādīt failu

@@ -1,78 +0,0 @@
1
- 
2
-
3
-
4
-import javafx.application.Application;
5
-import javafx.scene.Parent;
6
-import javafx.scene.Scene;
7
-import javafx.scene.control.Button;
8
-import javafx.scene.control.TextArea;
9
-import javafx.scene.control.TextField;
10
-import javafx.scene.layout.VBox;
11
-import javafx.stage.Stage;
12
-import javafx.scene.layout.FlowPane;
13
-
14
-/**
15
- * @author ZipCodeWilmington
16
- */
17
-public class CashMachineApp extends Application {
18
-
19
-    private TextField field = new TextField();
20
-    private CashMachine cashMachine = new CashMachine(new Bank());
21
-
22
-    private Parent createContent() {
23
-        VBox vbox = new VBox(10);
24
-        vbox.setPrefSize(600, 600);
25
-
26
-        TextArea areaInfo = new TextArea();
27
-
28
-        Button btnSubmit = new Button("Set Account ID");
29
-        btnSubmit.setOnAction(e -> {
30
-            int id = Integer.parseInt(field.getText());
31
-            cashMachine.login(id);
32
-
33
-            areaInfo.setText(cashMachine.toString());
34
-        });
35
-
36
-        Button btnDeposit = new Button("Deposit");
37
-        btnDeposit.setOnAction(e -> {
38
-            int amount = Integer.parseInt(field.getText());
39
-            cashMachine.deposit(amount);
40
-
41
-            areaInfo.setText(cashMachine.toString());
42
-        });
43
-
44
-        Button btnWithdraw = new Button("Withdraw");
45
-        btnWithdraw.setOnAction(e -> {
46
-            int amount = Integer.parseInt(field.getText());
47
-            cashMachine.withdraw(amount);
48
-
49
-            areaInfo.setText(cashMachine.toString());
50
-        });
51
-
52
-        Button btnExit = new Button("Exit");
53
-        btnExit.setOnAction(e -> {
54
-            cashMachine.exit();
55
-
56
-            areaInfo.setText(cashMachine.toString());
57
-        });
58
-
59
-        FlowPane flowpane = new FlowPane();
60
-
61
-        flowpane.getChildren().add(btnSubmit);
62
-        flowpane.getChildren().add(btnDeposit);
63
-        flowpane.getChildren().add(btnWithdraw);
64
-        flowpane.getChildren().add(btnExit);
65
-        vbox.getChildren().addAll(field, flowpane, areaInfo);
66
-        return vbox;
67
-    }
68
-
69
-    @Override
70
-    public void start(Stage stage) throws Exception {
71
-        stage.setScene(new Scene(createContent()));
72
-        stage.show();
73
-    }
74
-
75
-    public static void main(String[] args) {
76
-        launch(args);
77
-    }
78
-}

+ 0
- 18
PremiumAccount.java Parādīt failu

@@ -1,18 +0,0 @@
1
- 
2
-
3
-/**
4
- * @author ZipCodeWilmington
5
- */
6
-public class PremiumAccount extends Account {
7
-
8
-    private static final int OVERDRAFT_LIMIT = 100;
9
-
10
-    public PremiumAccount(AccountData accountData) {
11
-        super(accountData);
12
-    }
13
-
14
-    @Override
15
-    protected boolean canWithdraw(int amount) {
16
-        return getBalance() + OVERDRAFT_LIMIT >= amount;
17
-    }
18
-}

+ 1
- 1
README.TXT Parādīt failu

@@ -1,5 +1,5 @@
1 1
 ****************
2
-CashMachineBlueJ
2
+  CashMachine
3 3
 ****************
4 4
 
5 5
 A simple cash account <-> bank system implementation (very loosely modelled!)

+ 0
- 115
package.bluej Parādīt failu

@@ -1,115 +0,0 @@
1
-#BlueJ package file
2
-dependency1.from=Account
3
-dependency1.to=AccountData
4
-dependency1.type=UsesDependency
5
-dependency10.from=Bank
6
-dependency10.to=PremiumAccount
7
-dependency10.type=UsesDependency
8
-dependency11.from=Bank
9
-dependency11.to=ActionResult
10
-dependency11.type=UsesDependency
11
-dependency2.from=CashMachineApp
12
-dependency2.to=CashMachine
13
-dependency2.type=UsesDependency
14
-dependency3.from=CashMachineApp
15
-dependency3.to=Bank
16
-dependency3.type=UsesDependency
17
-dependency4.from=CashMachine
18
-dependency4.to=Bank
19
-dependency4.type=UsesDependency
20
-dependency5.from=CashMachine
21
-dependency5.to=AccountData
22
-dependency5.type=UsesDependency
23
-dependency6.from=CashMachine
24
-dependency6.to=ActionResult
25
-dependency6.type=UsesDependency
26
-dependency7.from=Bank
27
-dependency7.to=Account
28
-dependency7.type=UsesDependency
29
-dependency8.from=Bank
30
-dependency8.to=BasicAccount
31
-dependency8.type=UsesDependency
32
-dependency9.from=Bank
33
-dependency9.to=AccountData
34
-dependency9.type=UsesDependency
35
-editor.fx.0.height=722
36
-editor.fx.0.width=800
37
-editor.fx.0.x=788
38
-editor.fx.0.y=119
39
-objectbench.height=101
40
-objectbench.width=461
41
-package.divider.horizontal=0.6
42
-package.divider.vertical=0.8007380073800738
43
-package.editor.height=427
44
-package.editor.width=674
45
-package.editor.x=664
46
-package.editor.y=27
47
-package.frame.height=600
48
-package.frame.width=800
49
-package.numDependencies=11
50
-package.numTargets=8
51
-package.showExtends=true
52
-package.showUses=true
53
-project.charset=UTF-8
54
-project.invoke.thread=FX
55
-readme.height=58
56
-readme.name=@README
57
-readme.width=47
58
-readme.x=10
59
-readme.y=10
60
-target1.height=50
61
-target1.name=Account
62
-target1.showInterface=false
63
-target1.type=AbstractTarget
64
-target1.width=80
65
-target1.x=450
66
-target1.y=70
67
-target2.height=50
68
-target2.name=Bank
69
-target2.showInterface=false
70
-target2.type=ClassTarget
71
-target2.width=80
72
-target2.x=280
73
-target2.y=20
74
-target3.height=50
75
-target3.name=CashMachine
76
-target3.showInterface=false
77
-target3.type=ClassTarget
78
-target3.width=110
79
-target3.x=50
80
-target3.y=110
81
-target4.height=50
82
-target4.name=ActionResult
83
-target4.showInterface=false
84
-target4.type=ClassTarget
85
-target4.width=130
86
-target4.x=150
87
-target4.y=180
88
-target5.height=50
89
-target5.name=AccountData
90
-target5.showInterface=false
91
-target5.type=ClassTarget
92
-target5.width=110
93
-target5.x=550
94
-target5.y=290
95
-target6.height=50
96
-target6.name=PremiumAccount
97
-target6.showInterface=false
98
-target6.type=ClassTarget
99
-target6.width=130
100
-target6.x=510
101
-target6.y=200
102
-target7.height=50
103
-target7.name=BasicAccount
104
-target7.showInterface=false
105
-target7.type=ClassTarget
106
-target7.width=110
107
-target7.x=370
108
-target7.y=160
109
-target8.height=50
110
-target8.name=CashMachineApp
111
-target8.showInterface=false
112
-target8.type=ClassTarget
113
-target8.width=130
114
-target8.x=70
115
-target8.y=10