Pārlūkot izejas kodu

committing NaiveTicket

chitraBegerhotta 6 gadus atpakaļ
vecāks
revīzija
08c39105b9
6 mainītis faili ar 70 papildinājumiem un 16 dzēšanām
  1. Binārs
      .DS_Store
  2. 58
    4
      TicketMachine.java
  3. 6
    6
      bluej.pkg
  4. Binārs
      doc/.DS_Store
  5. Binārs
      doc/BlueJ-objects-first-ch2.pdf
  6. 6
    6
      package.bluej

Binārs
.DS_Store Parādīt failu


+ 58
- 4
TicketMachine.java Parādīt failu

@@ -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,26 +17,43 @@ 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 status;
22
+    
23
+    private int score;
24
+    
25
+    private int discount;
20 26
 
21 27
     /**
22 28
      * Create a machine that issues tickets of the given price.
23 29
      * Note that the price must be greater than zero, and there
24 30
      * are no checks to ensure this.
25 31
      */
26
-    public TicketMachine(int ticketCost)
32
+    public TicketMachine()
27 33
     {
28
-        price = ticketCost;
34
+        price = 1000;
29 35
         balance = 0;
30 36
         total = 0;
31 37
     }
38
+    
39
+    public TicketMachine(int cost){
40
+        
41
+        price = cost;
42
+    }
32 43
 
33 44
     /**
34 45
      * Return the price of a ticket.
35 46
      */
36 47
     public int getPrice()
37 48
     {
38
-        return price;
49
+       return price;
39 50
     }
51
+    
52
+    public void setPrice(int ticketCost)
53
+    {
54
+        price = ticketCost;
55
+    }
56
+        
40 57
 
41 58
     /**
42 59
      * Return the amount of money already inserted for the
@@ -46,6 +63,11 @@ public class TicketMachine
46 63
     {
47 64
         return balance;
48 65
     }
66
+    
67
+    public int getTotal()
68
+    {
69
+        return total;
70
+    }
49 71
 
50 72
     /**
51 73
      * Receive an amount of money in cents from a customer.
@@ -54,6 +76,31 @@ public class TicketMachine
54 76
     {
55 77
         balance = balance + amount;
56 78
     }
79
+    
80
+    public void empty(int total){
81
+        
82
+        total = 0;
83
+    }
84
+    
85
+    public void increase(int points){
86
+        
87
+        score += points;
88
+    }
89
+    
90
+    public void discount(int amount){
91
+        
92
+        price -= amount;
93
+    }
94
+    
95
+    public void prompt(){
96
+        
97
+        System.out.println("Please insert the correct amount of money.");
98
+    }
99
+    
100
+    public void showPrice(){
101
+        
102
+        System.out.println("The price of a ticket is " + price + " cents.");
103
+    }
57 104
 
58 105
     /**
59 106
      * Print a ticket.
@@ -74,5 +121,12 @@ public class TicketMachine
74 121
         total = total + balance;
75 122
         // Clear the balance.
76 123
         balance = 0;
124
+        int count = 0;
125
+        
126
+        int savings = price * discount;
127
+        
128
+        int mean = total/count;
129
+        
130
+        
77 131
     }
78 132
 }

+ 6
- 6
bluej.pkg Parādīt failu

@@ -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=0
3
+editor.fx.0.width=0
4
+editor.fx.0.x=0
5
+editor.fx.0.y=0
6 6
 objectbench.height=101
7 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=1067
13
-package.editor.y=119
12
+package.editor.x=13
13
+package.editor.y=141
14 14
 package.frame.height=600
15 15
 package.frame.width=800
16 16
 package.numDependencies=0

Binārs
doc/.DS_Store Parādīt failu


Binārs
doc/BlueJ-objects-first-ch2.pdf Parādīt failu


+ 6
- 6
package.bluej Parādīt failu

@@ -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=0
3
+editor.fx.0.width=0
4
+editor.fx.0.x=0
5
+editor.fx.0.y=0
6 6
 objectbench.height=101
7 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=1067
13
-package.editor.y=119
12
+package.editor.x=13
13
+package.editor.y=141
14 14
 package.frame.height=600
15 15
 package.frame.width=800
16 16
 package.numDependencies=0