Browse Source

Working on it not yet finished

Nicholas Maidanos 6 years ago
parent
commit
aafe27885a
4 changed files with 80 additions and 30 deletions
  1. BIN
      .DS_Store
  2. 66
    16
      TicketMachine.java
  3. 7
    7
      bluej.pkg
  4. 7
    7
      package.bluej

BIN
.DS_Store View File


+ 66
- 16
TicketMachine.java View File

@@ -17,6 +17,8 @@ public class TicketMachine
17 17
     private int balance;
18 18
     // The total amount of money collected by this machine.
19 19
     private int total;
20
+    
21
+    private int score;
20 22
 
21 23
     /**
22 24
      * Create a machine that issues tickets of the given price.
@@ -29,6 +31,36 @@ public class TicketMachine
29 31
         balance = 0;
30 32
         total = 0;
31 33
     }
34
+    
35
+    public TicketMachine(){
36
+        price = 0;
37
+        balance = 0;
38
+        total = 0;
39
+    }
40
+    
41
+    public void setPrice(int ticketCost) {
42
+        price = ticketCost;
43
+    }
44
+    
45
+    public void empty(){
46
+        total = 0;
47
+    }
48
+    
49
+    public void prompt() {
50
+        System.out.println("Please inser the correct amount of money");
51
+    }
52
+    
53
+    public void showPrice(){
54
+        System.out.println("The price of a ticket is " + price);
55
+    }
56
+    
57
+    public void discount(int amount){
58
+        price = price - amount;
59
+    }
60
+    
61
+    public void increase(int points){
62
+        score += points;
63
+    }
32 64
 
33 65
     /**
34 66
      * Return the price of a ticket.
@@ -47,12 +79,18 @@ public class TicketMachine
47 79
         return balance;
48 80
     }
49 81
 
82
+
50 83
     /**
51 84
      * Receive an amount of money in cents from a customer.
52 85
      */
53
-    public void insertMoney(int amount)
54
-    {
55
-        balance = balance + amount;
86
+    public void insertMoney(int amount) {
87
+        
88
+        if(amount > 0) {
89
+            balance = balance + amount;
90
+        } else {
91
+            System.out.println("Use a positive amount: " + amount);
92
+        }
93
+
56 94
     }
57 95
 
58 96
     /**
@@ -60,19 +98,31 @@ public class TicketMachine
60 98
      * Update the total collected and
61 99
      * reduce the balance to zero.
62 100
      */
63
-    public void printTicket()
64
-    {
65
-        // Simulate the printing of a ticket.
66
-        System.out.println("##################");
67
-        System.out.println("# The BlueJ Line");
68
-        System.out.println("# Ticket");
69
-        System.out.println("# " + price + " cents.");
70
-        System.out.println("##################");
71
-        System.out.println();
72
-
73
-        // Update the total collected with the balance.
74
-        total = total + balance;
75
-        // Clear the balance.
101
+    public void printTicket() {
102
+        
103
+        if(balance >= price) {
104
+            // Simulate the printing of a ticket.
105
+            System.out.println("##################");
106
+            System.out.println("# The BlueJ Line");
107
+            System.out.println("# Ticket");
108
+            System.out.println("# " + price + " cents.");
109
+            System.out.println("##################");
110
+            System.out.println();
111
+    
112
+            // Update the total collected with the balance.
113
+            total = total + balance;
114
+            // Clear the balance.
115
+            balance = 0;        
116
+        } else {
117
+            System.out.println("You must insert at least: " + 
118
+                                   (price - balance) + " cents.");
119
+                                        
120
+        }
121
+    }
122
+    public int refundBalance() {
123
+        int amountToRefund;
124
+        amountToRefund = balance;
76 125
         balance = 0;
126
+        return amountToRefund;
77 127
     }
78 128
 }

+ 7
- 7
bluej.pkg View File

@@ -1,16 +1,16 @@
1 1
 #BlueJ package file
2
-editor.fx.0.height=722
3
-editor.fx.0.width=800
4
-editor.fx.0.x=709
5
-editor.fx.0.y=113
2
+editor.fx.0.height=684
3
+editor.fx.0.width=870
4
+editor.fx.0.x=391
5
+editor.fx.0.y=23
6 6
 objectbench.height=101
7
-objectbench.width=461
7
+objectbench.width=776
8 8
 package.divider.horizontal=0.6
9 9
 package.divider.vertical=0.8007380073800738
10 10
 package.editor.height=427
11 11
 package.editor.width=674
12
-package.editor.x=1067
13
-package.editor.y=119
12
+package.editor.x=480
13
+package.editor.y=23
14 14
 package.frame.height=600
15 15
 package.frame.width=800
16 16
 package.numDependencies=0

+ 7
- 7
package.bluej View File

@@ -1,16 +1,16 @@
1 1
 #BlueJ package file
2
-editor.fx.0.height=722
3
-editor.fx.0.width=800
4
-editor.fx.0.x=709
5
-editor.fx.0.y=113
2
+editor.fx.0.height=684
3
+editor.fx.0.width=870
4
+editor.fx.0.x=391
5
+editor.fx.0.y=23
6 6
 objectbench.height=101
7
-objectbench.width=461
7
+objectbench.width=776
8 8
 package.divider.horizontal=0.6
9 9
 package.divider.vertical=0.8007380073800738
10 10
 package.editor.height=427
11 11
 package.editor.width=674
12
-package.editor.x=1067
13
-package.editor.y=119
12
+package.editor.x=480
13
+package.editor.y=23
14 14
 package.frame.height=600
15 15
 package.frame.width=800
16 16
 package.numDependencies=0