Browse Source

{practice}

Jacqueline Joson 6 years ago
parent
commit
5e0294cc19
3 changed files with 55 additions and 30 deletions
  1. 29
    4
      TicketMachine.java
  2. 13
    13
      bluej.pkg
  3. 13
    13
      package.bluej

+ 29
- 4
TicketMachine.java View File

@@ -17,12 +17,18 @@ 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
-
20
+    public void prompt() 
21
+    {
22
+        System.out.println("Please insert the correct amount of money.");
23
+    }
24
+    
25
+   
21 26
     /**
22 27
      * Create a machine that issues tickets of the given price.
23 28
      * Note that the price must be greater than zero, and there
24 29
      * are no checks to ensure this.
25 30
      */
31
+    
26 32
     public TicketMachine(int ticketCost)
27 33
     {
28 34
         price = ticketCost;
@@ -52,7 +58,12 @@ public class TicketMachine
52 58
      */
53 59
     public void insertMoney(int amount)
54 60
     {
55
-        balance = balance + amount;
61
+        if (amount >= 0) {
62
+            balance = balance + amount;
63
+        }
64
+        else {
65
+            System.out.println("Use a positive amount: " + amount);
66
+        }
56 67
     }
57 68
 
58 69
     /**
@@ -62,6 +73,7 @@ public class TicketMachine
62 73
      */
63 74
     public void printTicket()
64 75
     {
76
+        if (balance >= price) {
65 77
         // Simulate the printing of a ticket.
66 78
         System.out.println("##################");
67 79
         System.out.println("# The BlueJ Line");
@@ -71,8 +83,21 @@ public class TicketMachine
71 83
         System.out.println();
72 84
 
73 85
         // Update the total collected with the balance.
74
-        total = total + balance;
75
-        // Clear the balance.
86
+        total = total + price;
87
+        // new balance
88
+        balance = balance - price;
89
+    }
90
+        else {
91
+            System.out.println("You must insert at least: " + (price - balance) + " cents.");
92
+        }
93
+    }
94
+    
95
+    //Balance life//
96
+    public int refundBalance()
97
+    {
98
+        int amountToRefund;
99
+        amountToRefund = balance;
76 100
         balance = 0;
101
+        return amountToRefund;
77 102
     }
78 103
 }

+ 13
- 13
bluej.pkg View File

@@ -1,18 +1,18 @@
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=800
3
+editor.fx.0.width=638
4
+editor.fx.0.x=642
5
+editor.fx.0.y=0
6 6
 objectbench.height=101
7
-objectbench.width=461
8
-package.divider.horizontal=0.6
9
-package.divider.vertical=0.8007380073800738
10
-package.editor.height=427
11
-package.editor.width=674
12
-package.editor.x=1067
13
-package.editor.y=119
14
-package.frame.height=600
15
-package.frame.width=800
7
+objectbench.width=614
8
+package.divider.horizontal=0.6003236245954693
9
+package.divider.vertical=0.8586387434554974
10
+package.editor.height=649
11
+package.editor.width=512
12
+package.editor.x=0
13
+package.editor.y=0
14
+package.frame.height=800
15
+package.frame.width=638
16 16
 package.numDependencies=0
17 17
 package.numTargets=1
18 18
 package.showExtends=true

+ 13
- 13
package.bluej View File

@@ -1,18 +1,18 @@
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=800
3
+editor.fx.0.width=638
4
+editor.fx.0.x=642
5
+editor.fx.0.y=0
6 6
 objectbench.height=101
7
-objectbench.width=461
8
-package.divider.horizontal=0.6
9
-package.divider.vertical=0.8007380073800738
10
-package.editor.height=427
11
-package.editor.width=674
12
-package.editor.x=1067
13
-package.editor.y=119
14
-package.frame.height=600
15
-package.frame.width=800
7
+objectbench.width=614
8
+package.divider.horizontal=0.6003236245954693
9
+package.divider.vertical=0.8586387434554974
10
+package.editor.height=649
11
+package.editor.width=512
12
+package.editor.x=0
13
+package.editor.y=0
14
+package.frame.height=800
15
+package.frame.width=638
16 16
 package.numDependencies=0
17 17
 package.numTargets=1
18 18
 package.showExtends=true