Browse Source

final version of naiveticket

William Simkins 6 years ago
parent
commit
574c3f2101
4 changed files with 80 additions and 29 deletions
  1. BIN
      .DS_Store
  2. 56
    5
      TicketMachine.java
  3. 12
    12
      bluej.pkg
  4. 12
    12
      package.bluej

BIN
.DS_Store View File


+ 56
- 5
TicketMachine.java View File

9
  * @author David J. Barnes and Michael Kolling
9
  * @author David J. Barnes and Michael Kolling
10
  * @version 2008.03.30
10
  * @version 2008.03.30
11
  */
11
  */
12
-public class TicketMachine
12
+class TicketMachine
13
 {
13
 {
14
     // The price of a ticket from this machine.
14
     // The price of a ticket from this machine.
15
     private int price;
15
     private int price;
17
     private int balance;
17
     private int balance;
18
     // The total amount of money collected by this machine.
18
     // The total amount of money collected by this machine.
19
     private int total;
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
      * Create a machine that issues tickets of the given price.
31
      * Create a machine that issues tickets of the given price.
23
      * Note that the price must be greater than zero, and there
32
      * Note that the price must be greater than zero, and there
24
      * are no checks to ensure this.
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
         balance = 0;
38
         balance = 0;
30
         total = 0;
39
         total = 0;
40
+        discount = (int)(.10);
41
+        mean = 0;
42
+        count = 500;
43
+        budget = 0;
31
     }
44
     }
32
 
45
 
33
     /**
46
     /**
38
         return price;
51
         return price;
39
     }
52
     }
40
 
53
 
54
+    public int setPrice(int newPrice)
55
+    {
56
+        return newPrice;
57
+    }
58
+
41
     /**
59
     /**
42
      * Return the amount of money already inserted for the
60
      * Return the amount of money already inserted for the
43
      * next ticket.
61
      * next ticket.
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
      * Print a ticket.
85
      * Print a ticket.
60
      * Update the total collected and
86
      * Update the total collected and
61
      * reduce the balance to zero.
87
      * reduce the balance to zero.
69
         System.out.println("# " + price + " cents.");
95
         System.out.println("# " + price + " cents.");
70
         System.out.println("##################");
96
         System.out.println("##################");
71
         System.out.println();
97
         System.out.println();
72
-
98
+        
99
+        mean = total / count;
100
+        //Update the total combined with discount.
101
+        saving = price * discount;
73
         // Update the total collected with the balance.
102
         // Update the total collected with the balance.
74
         total = total + balance;
103
         total = total + balance;
75
         // Clear the balance.
104
         // Clear the balance.
76
         balance = 0;
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 View File

1
 #BlueJ package file
1
 #BlueJ package file
2
 editor.fx.0.height=722
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
 package.divider.horizontal=0.6
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
 package.frame.height=600
14
 package.frame.height=600
15
-package.frame.width=800
15
+package.frame.width=613
16
 package.numDependencies=0
16
 package.numDependencies=0
17
 package.numTargets=1
17
 package.numTargets=1
18
 package.showExtends=true
18
 package.showExtends=true
23
 readme.width=47
23
 readme.width=47
24
 readme.x=10
24
 readme.x=10
25
 readme.y=10
25
 readme.y=10
26
-target1.height=50
26
+target1.height=60
27
 target1.name=TicketMachine
27
 target1.name=TicketMachine
28
 target1.showInterface=false
28
 target1.showInterface=false
29
 target1.type=ClassTarget
29
 target1.type=ClassTarget

+ 12
- 12
package.bluej View File

1
 #BlueJ package file
1
 #BlueJ package file
2
 editor.fx.0.height=722
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
 package.divider.horizontal=0.6
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
 package.frame.height=600
14
 package.frame.height=600
15
-package.frame.width=800
15
+package.frame.width=613
16
 package.numDependencies=0
16
 package.numDependencies=0
17
 package.numTargets=1
17
 package.numTargets=1
18
 package.showExtends=true
18
 package.showExtends=true
23
 readme.width=47
23
 readme.width=47
24
 readme.x=10
24
 readme.x=10
25
 readme.y=10
25
 readme.y=10
26
-target1.height=50
26
+target1.height=60
27
 target1.name=TicketMachine
27
 target1.name=TicketMachine
28
 target1.showInterface=false
28
 target1.showInterface=false
29
 target1.type=ClassTarget
29
 target1.type=ClassTarget