Selaa lähdekoodia

ommited NaiveTicketi

Navya Sanal 6 vuotta sitten
vanhempi
commit
7c785e7ca6
4 muutettua tiedostoa jossa 128 lisäystä ja 30 poistoa
  1. 33
    0
      Pet.java
  2. 55
    4
      TicketMachine.java
  3. 20
    13
      bluej.pkg
  4. 20
    13
      package.bluej

+ 33
- 0
Pet.java Näytä tiedosto

@@ -0,0 +1,33 @@
1
+
2
+/**
3
+ * Write a description of class Pet here.
4
+ *
5
+ * @author (your name)
6
+ * @version (a version number or a date)
7
+ */
8
+public class Pet
9
+{
10
+    // instance variables - replace the example below with your own
11
+    private int x;
12
+
13
+    /**
14
+     * Constructor for objects of class Pet
15
+     */
16
+    public Pet(String petName)
17
+    {
18
+        // initialise instance variables
19
+        String name = petName;
20
+    }
21
+
22
+    /**
23
+     * An example of a method - replace this comment with your own
24
+     *
25
+     * @param  y  a sample parameter for a method
26
+     * @return    the sum of x and y
27
+     */
28
+    public int sampleMethod(int y)
29
+    {
30
+        // put your code here
31
+        return x + y;
32
+    }
33
+}

+ 55
- 4
TicketMachine.java Näytä tiedosto

@@ -9,23 +9,29 @@
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;
16 16
     // The amount of money entered by a customer so far.
17
-    private int balance;
17
+
18 18
     // The total amount of money collected by this machine.
19 19
     private int total;
20
+    private int balance;
21
+    //private int status;
22
+    private int score;
23
+
20 24
 
21 25
     /**
22 26
      * Create a machine that issues tickets of the given price.
23 27
      * Note that the price must be greater than zero, and there
24 28
      * are no checks to ensure this.
25 29
      */
26
-    public TicketMachine(int ticketCost)
30
+    public TicketMachine()
27 31
     {
28
-        price = ticketCost;
32
+        //int price = ticketCost;
33
+        //this.price = ticketCost;
34
+        price = 1000;
29 35
         balance = 0;
30 36
         total = 0;
31 37
     }
@@ -55,6 +61,50 @@ public class TicketMachine
55 61
         balance = balance + amount;
56 62
     }
57 63
 
64
+    public int getTotal(){
65
+        return total;
66
+    }
67
+
68
+    public void setPrice(int ticketCost){
69
+        price = ticketCost;
70
+    }
71
+
72
+    public void increase(int points){
73
+        score = score + points;
74
+    }
75
+
76
+    public void discount(int amount){
77
+        price = price - amount;
78
+    }
79
+
80
+    public void prompt(){
81
+        System.out.println("Please insert the correct amount of money");
82
+    }
83
+
84
+    public void showPrice(){
85
+        System.out.println("The price of the ticket is " + price + "cents");
86
+    }
87
+
88
+    public void empty(){
89
+        total = 0;
90
+    }
91
+
92
+    public int refundBalance()
93
+    {
94
+        int amountToRefund;
95
+        amountToRefund = balance;
96
+        balance = 0;
97
+        return amountToRefund;
98
+    }
99
+    public int emptyMachine(){
100
+        //int total = 0;
101
+        return total;
102
+        
103
+    }
104
+    public int printTicket(){
105
+        int amountLeftToPay = price - balance;
106
+    
107
+
58 108
     /**
59 109
      * Print a ticket.
60 110
      * Update the total collected and
@@ -62,6 +112,7 @@ public class TicketMachine
62 112
      */
63 113
     public void printTicket()
64 114
     {
115
+
65 116
         // Simulate the printing of a ticket.
66 117
         System.out.println("##################");
67 118
         System.out.println("# The BlueJ Line");

+ 20
- 13
bluej.pkg Näytä tiedosto

@@ -1,20 +1,20 @@
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=813
3
+editor.fx.0.width=1440
4
+editor.fx.0.x=0
5
+editor.fx.0.y=23
6 6
 objectbench.height=101
7
-objectbench.width=461
8
-package.divider.horizontal=0.6
7
+objectbench.width=264
8
+package.divider.horizontal=0.5995575221238938
9 9
 package.divider.vertical=0.8007380073800738
10 10
 package.editor.height=427
11
-package.editor.width=674
12
-package.editor.x=1067
13
-package.editor.y=119
11
+package.editor.width=346
12
+package.editor.x=962
13
+package.editor.y=97
14 14
 package.frame.height=600
15
-package.frame.width=800
15
+package.frame.width=472
16 16
 package.numDependencies=0
17
-package.numTargets=1
17
+package.numTargets=2
18 18
 package.showExtends=true
19 19
 package.showUses=true
20 20
 project.charset=UTF-8
@@ -28,5 +28,12 @@ target1.name=TicketMachine
28 28
 target1.showInterface=false
29 29
 target1.type=ClassTarget
30 30
 target1.width=120
31
-target1.x=80
32
-target1.y=50
31
+target1.x=60
32
+target1.y=40
33
+target2.height=50
34
+target2.name=Pet
35
+target2.showInterface=false
36
+target2.type=ClassTarget
37
+target2.width=80
38
+target2.x=10
39
+target2.y=110

+ 20
- 13
package.bluej Näytä tiedosto

@@ -1,20 +1,20 @@
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=813
3
+editor.fx.0.width=1440
4
+editor.fx.0.x=0
5
+editor.fx.0.y=23
6 6
 objectbench.height=101
7
-objectbench.width=461
8
-package.divider.horizontal=0.6
7
+objectbench.width=264
8
+package.divider.horizontal=0.5995575221238938
9 9
 package.divider.vertical=0.8007380073800738
10 10
 package.editor.height=427
11
-package.editor.width=674
12
-package.editor.x=1067
13
-package.editor.y=119
11
+package.editor.width=346
12
+package.editor.x=962
13
+package.editor.y=97
14 14
 package.frame.height=600
15
-package.frame.width=800
15
+package.frame.width=472
16 16
 package.numDependencies=0
17
-package.numTargets=1
17
+package.numTargets=2
18 18
 package.showExtends=true
19 19
 package.showUses=true
20 20
 project.charset=UTF-8
@@ -28,5 +28,12 @@ target1.name=TicketMachine
28 28
 target1.showInterface=false
29 29
 target1.type=ClassTarget
30 30
 target1.width=120
31
-target1.x=80
32
-target1.y=50
31
+target1.x=60
32
+target1.y=40
33
+target2.height=50
34
+target2.name=Pet
35
+target2.showInterface=false
36
+target2.type=ClassTarget
37
+target2.width=80
38
+target2.x=10
39
+target2.y=110