Преглед на файлове

final version of naiveticket

William Simkins преди 6 години
родител
ревизия
574c3f2101
променени са 4 файла, в които са добавени 80 реда и са изтрити 29 реда
  1. BIN
      .DS_Store
  2. 56
    5
      TicketMachine.java
  3. 12
    12
      bluej.pkg
  4. 12
    12
      package.bluej

BIN
.DS_Store Целия файл


+ 56
- 5
TicketMachine.java Целия файл

@@ -9,7 +9,7 @@
9 9
  * @author David J. Barnes and Michael Kolling
10 10
  * @version 2008.03.30
11 11
  */
12
-public class TicketMachine
12
+class TicketMachine
13 13
 {
14 14
     // The price of a ticket from this machine.
15 15
     private int price;
@@ -17,17 +17,30 @@ 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
+    // The amount of money taken off of a payment
21
+    private int discount;
22
+    // The amount of money being saved by user
23
+    private int saving;
24
+    //The value of total divided by count
25
+    private int mean;
26
+    //the value divided by total to get mean
27
+    private int count;
28
+    private int budget;
20 29
 
21 30
     /**
22 31
      * Create a machine that issues tickets of the given price.
23 32
      * Note that the price must be greater than zero, and there
24 33
      * are no checks to ensure this.
25 34
      */
26
-    public TicketMachine(int ticketCost)
35
+    public TicketMachine()
27 36
     {
28
-        price = ticketCost;
37
+        price = 0;
29 38
         balance = 0;
30 39
         total = 0;
40
+        discount = (int)(.10);
41
+        mean = 0;
42
+        count = 500;
43
+        budget = 0;
31 44
     }
32 45
 
33 46
     /**
@@ -38,6 +51,11 @@ public class TicketMachine
38 51
         return price;
39 52
     }
40 53
 
54
+    public int setPrice(int newPrice)
55
+    {
56
+        return newPrice;
57
+    }
58
+
41 59
     /**
42 60
      * Return the amount of money already inserted for the
43 61
      * next ticket.
@@ -56,6 +74,14 @@ public class TicketMachine
56 74
     }
57 75
 
58 76
     /**
77
+     * Returns total amount of money this machine has collected
78
+     */
79
+    public int getTotal()
80
+    {
81
+        return total;
82
+    }
83
+
84
+    /**
59 85
      * Print a ticket.
60 86
      * Update the total collected and
61 87
      * reduce the balance to zero.
@@ -69,10 +95,35 @@ public class TicketMachine
69 95
         System.out.println("# " + price + " cents.");
70 96
         System.out.println("##################");
71 97
         System.out.println();
72
-
98
+        
99
+        mean = total / count;
100
+        //Update the total combined with discount.
101
+        saving = price * discount;
73 102
         // Update the total collected with the balance.
74 103
         total = total + balance;
75 104
         // Clear the balance.
76 105
         balance = 0;
106
+        
107
+        if (price > budget){
108
+            System.out.println("Too expensive. Your budget is: " + budget + ".");
109
+    } else {
110
+        System.out.println("Just right.");
111
+    }
112
+    }
113
+
114
+    public void prompt()
115
+    {
116
+        System.out.println("Please insert the correct amount of money.");
117
+    }
118
+
119
+    public void showPrice(int ticketPrice)
120
+    { 
121
+        System.out.println("The price of a ticket is " + price + " cents.");
122
+    }
123
+
124
+    public void empty()
125
+    {
126
+        total = 0;
77 127
     }
78
-}
128
+   
129
+}

+ 12
- 12
bluej.pkg Целия файл

@@ -1,18 +1,18 @@
1 1
 #BlueJ package file
2 2
 editor.fx.0.height=722
3
-editor.fx.0.width=800
4
-editor.fx.0.x=709
5
-editor.fx.0.y=113
6
-objectbench.height=101
7
-objectbench.width=461
3
+editor.fx.0.width=663
4
+editor.fx.0.x=315
5
+editor.fx.0.y=23
6
+objectbench.height=199
7
+objectbench.width=589
8 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
9
+package.divider.vertical=0.6199261992619927
10
+package.editor.height=329
11
+package.editor.width=487
12
+package.editor.x=24
13
+package.editor.y=56
14 14
 package.frame.height=600
15
-package.frame.width=800
15
+package.frame.width=613
16 16
 package.numDependencies=0
17 17
 package.numTargets=1
18 18
 package.showExtends=true
@@ -23,7 +23,7 @@ readme.name=@README
23 23
 readme.width=47
24 24
 readme.x=10
25 25
 readme.y=10
26
-target1.height=50
26
+target1.height=60
27 27
 target1.name=TicketMachine
28 28
 target1.showInterface=false
29 29
 target1.type=ClassTarget

+ 12
- 12
package.bluej Целия файл

@@ -1,18 +1,18 @@
1 1
 #BlueJ package file
2 2
 editor.fx.0.height=722
3
-editor.fx.0.width=800
4
-editor.fx.0.x=709
5
-editor.fx.0.y=113
6
-objectbench.height=101
7
-objectbench.width=461
3
+editor.fx.0.width=663
4
+editor.fx.0.x=315
5
+editor.fx.0.y=23
6
+objectbench.height=199
7
+objectbench.width=589
8 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
9
+package.divider.vertical=0.6199261992619927
10
+package.editor.height=329
11
+package.editor.width=487
12
+package.editor.x=24
13
+package.editor.y=56
14 14
 package.frame.height=600
15
-package.frame.width=800
15
+package.frame.width=613
16 16
 package.numDependencies=0
17 17
 package.numTargets=1
18 18
 package.showExtends=true
@@ -23,7 +23,7 @@ readme.name=@README
23 23
 readme.width=47
24 24
 readme.x=10
25 25
 readme.y=10
26
-target1.height=50
26
+target1.height=60
27 27
 target1.name=TicketMachine
28 28
 target1.showInterface=false
29 29
 target1.type=ClassTarget