Browse Source

I got alot done with this. I still might need to look this over to

Nicholas Maidanos 6 years ago
parent
commit
e7357ec898
3 changed files with 47 additions and 39 deletions
  1. 33
    25
      TicketMachine.java
  2. 7
    7
      bluej.pkg
  3. 7
    7
      package.bluej

+ 33
- 25
TicketMachine.java View File

@@ -13,12 +13,16 @@ public class TicketMachine
13 13
 {
14 14
     // The price of a ticket from this machine.
15 15
     private int price;
16
+    // The amount that you get off with coupon
17
+    private int coupon;
16 18
     // The amount of money entered by a customer so far.
17 19
     private int balance;
18 20
     // The total amount of money collected by this machine.
19 21
     private int total;
22
+    // The total amount of tickets sold
23
+    private int ticketsSold = 0;
20 24
     
21
-    private int score;
25
+    //private int score;
22 26
 
23 27
     /**
24 28
      * Create a machine that issues tickets of the given price.
@@ -47,7 +51,7 @@ public class TicketMachine
47 51
     }
48 52
     
49 53
     public void prompt() {
50
-        System.out.println("Please inser the correct amount of money");
54
+        System.out.println("Please insert the correct amount of money");
51 55
     }
52 56
     
53 57
     public void showPrice(){
@@ -57,17 +61,13 @@ public class TicketMachine
57 61
     public void discount(int amount){
58 62
         price = price - amount;
59 63
     }
60
-    
61
-    public void increase(int points){
62
-        score += points;
63
-    }
64 64
 
65 65
     /**
66 66
      * Return the price of a ticket.
67 67
      */
68 68
     public int getPrice()
69 69
     {
70
-        return price;
70
+        return coupon != 0 ? price - coupon : price; 
71 71
     }
72 72
 
73 73
     /**
@@ -78,19 +78,17 @@ public class TicketMachine
78 78
     {
79 79
         return balance;
80 80
     }
81
+    
82
+    public void insertCoupon(int couponAmount){
83
+        coupon = couponAmount;
84
+    }
81 85
 
82 86
 
83 87
     /**
84 88
      * Receive an amount of money in cents from a customer.
85 89
      */
86 90
     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
-
91
+        balance += amount;
94 92
     }
95 93
 
96 94
     /**
@@ -100,29 +98,39 @@ public class TicketMachine
100 98
      */
101 99
     public void printTicket() {
102 100
         
103
-        if(balance >= price) {
101
+        int salePrice = coupon != 0 ? price - coupon : price; 
102
+        
103
+        int change = balance - salePrice;
104
+        
105
+        if(change >= 0) {
104 106
             // Simulate the printing of a ticket.
105 107
             System.out.println("##################");
106 108
             System.out.println("# The BlueJ Line");
107 109
             System.out.println("# Ticket");
108
-            System.out.println("# " + price + " cents.");
110
+            System.out.println("# " + salePrice + " cents.");
111
+            if(coupon != 0){
112
+                System.out.println("# You have been discounted " + coupon + " cents.");
113
+            }
109 114
             System.out.println("##################");
115
+            if(change > 0){
116
+                System.out.println("You have been refunded " + change);
117
+            }
110 118
             System.out.println();
111
-    
112 119
             // Update the total collected with the balance.
113
-            total = total + balance;
120
+            total = price;
114 121
             // Clear the balance.
115
-            balance = 0;        
122
+            balance = 0;
123
+            coupon = 0;
124
+            ticketsSold++;
125
+            
116 126
         } else {
117 127
             System.out.println("You must insert at least: " + 
118
-                                   (price - balance) + " cents.");
119
-                                        
128
+                                (salePrice - balance) + " cents to purchase a ticket.");          
120 129
         }
121 130
     }
122
-    public int refundBalance() {
123
-        int amountToRefund;
124
-        amountToRefund = balance;
131
+    public void refundBalance() {
132
+        System.out.println(balance + " cents Has just been refunded to you");
125 133
         balance = 0;
126
-        return amountToRefund;
134
+        
127 135
     }
128 136
 }

+ 7
- 7
bluej.pkg View File

@@ -1,16 +1,16 @@
1 1
 #BlueJ package file
2
-editor.fx.0.height=684
3
-editor.fx.0.width=870
4
-editor.fx.0.x=391
5
-editor.fx.0.y=23
2
+editor.fx.0.height=923
3
+editor.fx.0.width=1036
4
+editor.fx.0.x=884
5
+editor.fx.0.y=28
6 6
 objectbench.height=101
7
-objectbench.width=776
7
+objectbench.width=461
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=480
13
-package.editor.y=23
12
+package.editor.x=40
13
+package.editor.y=94
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=684
3
-editor.fx.0.width=870
4
-editor.fx.0.x=391
5
-editor.fx.0.y=23
2
+editor.fx.0.height=923
3
+editor.fx.0.width=1036
4
+editor.fx.0.x=884
5
+editor.fx.0.y=28
6 6
 objectbench.height=101
7
-objectbench.width=776
7
+objectbench.width=461
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=480
13
-package.editor.y=23
12
+package.editor.x=40
13
+package.editor.y=94
14 14
 package.frame.height=600
15 15
 package.frame.width=800
16 16
 package.numDependencies=0