소스 검색

Lab completed

Rachelle 6 년 전
부모
커밋
a1f89267f1
6개의 변경된 파일69개의 추가작업 그리고 19개의 파일을 삭제
  1. BIN
      .DS_Store
  2. 53
    3
      TicketMachine.java
  3. 8
    8
      bluej.pkg
  4. BIN
      doc/.DS_Store
  5. BIN
      doc/BlueJ-objects-first-ch2.pdf
  6. 8
    8
      package.bluej

BIN
.DS_Store 파일 보기


+ 53
- 3
TicketMachine.java 파일 보기

@@ -17,15 +17,23 @@ 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
+    //Exercise 2.15
21
+    private int status;
20 22
 
21 23
     /**
22 24
      * Create a machine that issues tickets of the given price.
23 25
      * Note that the price must be greater than zero, and there
24 26
      * are no checks to ensure this.
25 27
      */
26
-    public TicketMachine(int ticketCost)
28
+    public TicketMachine()
27 29
     {
28
-        price = ticketCost;
30
+        price = 1000;
31
+        balance = 0;
32
+        total = 0;
33
+    }
34
+
35
+    public TicketMachine(int ticketPrice){
36
+        price = ticketPrice;
29 37
         balance = 0;
30 38
         total = 0;
31 39
     }
@@ -42,12 +50,26 @@ public class TicketMachine
42 50
      * Return the amount of money already inserted for the
43 51
      * next ticket.
44 52
      */
45
-    public int getBalance()
53
+    public int getAmount()
46 54
     {
47 55
         return balance;
48 56
     }
49 57
 
50 58
     /**
59
+     * Returns the total amount of money inserted into the machine.
60
+     */
61
+    public int getTotal(){
62
+        return total;
63
+    }
64
+
65
+    /**
66
+     * Sets the price of the ticket.
67
+     */
68
+    public void setPrice(int ticketCost){
69
+        price = ticketCost;
70
+    }
71
+
72
+    /**
51 73
      * Receive an amount of money in cents from a customer.
52 74
      */
53 75
     public void insertMoney(int amount)
@@ -56,6 +78,34 @@ public class TicketMachine
56 78
     }
57 79
 
58 80
     /**
81
+     * Reduces the price of the ticket.
82
+     */
83
+    public void discount(int amount){
84
+        price = price - amount;
85
+    }
86
+
87
+    /**
88
+     * Removes all money from the machine.
89
+     */
90
+    public void empty(){
91
+        total = 0;
92
+    }
93
+
94
+    /**
95
+     * Prompts the user to enter money.
96
+     */
97
+    public void prompt(){
98
+        System.out.println("Please insert the correct amount of money.");   
99
+    }
100
+
101
+    /**
102
+     * 
103
+     */
104
+    public void showPrice(){
105
+        System.out.println("The price of a ticket is " + price);   
106
+    }
107
+
108
+    /**
59 109
      * Print a ticket.
60 110
      * Update the total collected and
61 111
      * reduce the balance to zero.

+ 8
- 8
bluej.pkg 파일 보기

@@ -1,16 +1,16 @@
1 1
 #BlueJ package file
2
-editor.fx.0.height=722
2
+editor.fx.0.height=709
3 3
 editor.fx.0.width=800
4
-editor.fx.0.x=709
5
-editor.fx.0.y=113
6
-objectbench.height=101
4
+editor.fx.0.x=437
5
+editor.fx.0.y=23
6
+objectbench.height=223
7 7
 objectbench.width=461
8 8
 package.divider.horizontal=0.6
9
-package.divider.vertical=0.8007380073800738
10
-package.editor.height=427
9
+package.divider.vertical=0.5756457564575646
10
+package.editor.height=305
11 11
 package.editor.width=674
12
-package.editor.x=1067
13
-package.editor.y=119
12
+package.editor.x=107
13
+package.editor.y=131
14 14
 package.frame.height=600
15 15
 package.frame.width=800
16 16
 package.numDependencies=0

BIN
doc/.DS_Store 파일 보기


BIN
doc/BlueJ-objects-first-ch2.pdf 파일 보기


+ 8
- 8
package.bluej 파일 보기

@@ -1,16 +1,16 @@
1 1
 #BlueJ package file
2
-editor.fx.0.height=722
2
+editor.fx.0.height=709
3 3
 editor.fx.0.width=800
4
-editor.fx.0.x=709
5
-editor.fx.0.y=113
6
-objectbench.height=101
4
+editor.fx.0.x=437
5
+editor.fx.0.y=23
6
+objectbench.height=223
7 7
 objectbench.width=461
8 8
 package.divider.horizontal=0.6
9
-package.divider.vertical=0.8007380073800738
10
-package.editor.height=427
9
+package.divider.vertical=0.5756457564575646
10
+package.editor.height=305
11 11
 package.editor.width=674
12
-package.editor.x=1067
13
-package.editor.y=119
12
+package.editor.x=107
13
+package.editor.y=131
14 14
 package.frame.height=600
15 15
 package.frame.width=800
16 16
 package.numDependencies=0