Browse Source

Ticket Meachine

Yesoda Sanka 6 years ago
parent
commit
40b7f14634
6 changed files with 130 additions and 23 deletions
  1. BIN
      .DS_Store
  2. 33
    0
      Heater.java
  3. 18
    5
      TicketMachine.java
  4. 23
    9
      bluej.pkg
  5. 23
    9
      package.bluej
  6. 33
    0
      student.java

BIN
.DS_Store View File


+ 33
- 0
Heater.java View File

1
+
2
+/**
3
+ * Write a description of class Heater here.
4
+ *
5
+ * @author (your name)
6
+ * @version (a version number or a date)
7
+ */
8
+public class Heater
9
+{
10
+    // instance variables - replace the example below with your own
11
+    private int x;
12
+
13
+    /**
14
+     * Constructor for objects of class Heater
15
+     */
16
+    public Heater()
17
+    {
18
+        // initialise instance variables
19
+        x = 0;
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
+}

+ 18
- 5
TicketMachine.java View File

12
 public class TicketMachine
12
 public 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;
16
     // The amount of money entered by a customer so far.
16
     // The amount of money entered by a customer so far.
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
+    private int status;
21
+   
20
 
22
 
21
     /**
23
     /**
22
      * Create a machine that issues tickets of the given price.
24
      * Create a machine that issues tickets of the given price.
23
      * Note that the price must be greater than zero, and there
25
      * Note that the price must be greater than zero, and there
24
      * are no checks to ensure this.
26
      * are no checks to ensure this.
25
      */
27
      */
26
-    public TicketMachine(int ticketCost)
28
+    public TicketMachine()
27
     {
29
     {
28
-        price = ticketCost;
29
-        balance = 0;
30
+        price = 1000;
31
+        balance = 100;
30
         total = 0;
32
         total = 0;
31
     }
33
     }
32
 
34
 
64
     {
66
     {
65
         // Simulate the printing of a ticket.
67
         // Simulate the printing of a ticket.
66
         System.out.println("##################");
68
         System.out.println("##################");
67
-        System.out.println("# The BlueJ Line");
69
+        System.out.println("# The BlueJ Line"); 
68
         System.out.println("# Ticket");
70
         System.out.println("# Ticket");
69
         System.out.println("# " + price + " cents.");
71
         System.out.println("# " + price + " cents.");
70
         System.out.println("##################");
72
         System.out.println("##################");
75
         // Clear the balance.
77
         // Clear the balance.
76
         balance = 0;
78
         balance = 0;
77
     }
79
     }
80
+
81
+public void prompt ()
82
+{
83
+     System.out.println( "Please insert the correct amount of money.");
84
+}
85
+
86
+public void showPrice ()
87
+{
88
+     System.out.println( "The price of a ticket is :" + price + " cents..");
89
+}
90
+
78
 }
91
 }

+ 23
- 9
bluej.pkg View File

1
 #BlueJ package file
1
 #BlueJ package file
2
-editor.fx.0.height=722
2
+editor.fx.0.height=714
3
 editor.fx.0.width=800
3
 editor.fx.0.width=800
4
-editor.fx.0.x=709
5
-editor.fx.0.y=113
4
+editor.fx.0.x=240
5
+editor.fx.0.y=23
6
 objectbench.height=101
6
 objectbench.height=101
7
 objectbench.width=461
7
 objectbench.width=461
8
 package.divider.horizontal=0.6
8
 package.divider.horizontal=0.6
9
 package.divider.vertical=0.8007380073800738
9
 package.divider.vertical=0.8007380073800738
10
 package.editor.height=427
10
 package.editor.height=427
11
 package.editor.width=674
11
 package.editor.width=674
12
-package.editor.x=1067
12
+package.editor.x=480
13
 package.editor.y=119
13
 package.editor.y=119
14
 package.frame.height=600
14
 package.frame.height=600
15
 package.frame.width=800
15
 package.frame.width=800
16
 package.numDependencies=0
16
 package.numDependencies=0
17
-package.numTargets=1
17
+package.numTargets=3
18
 package.showExtends=true
18
 package.showExtends=true
19
 package.showUses=true
19
 package.showUses=true
20
 project.charset=UTF-8
20
 project.charset=UTF-8
24
 readme.x=10
24
 readme.x=10
25
 readme.y=10
25
 readme.y=10
26
 target1.height=50
26
 target1.height=50
27
-target1.name=TicketMachine
27
+target1.name=student
28
 target1.showInterface=false
28
 target1.showInterface=false
29
 target1.type=ClassTarget
29
 target1.type=ClassTarget
30
-target1.width=120
31
-target1.x=80
32
-target1.y=50
30
+target1.width=80
31
+target1.x=10
32
+target1.y=110
33
+target2.height=50
34
+target2.name=Heater
35
+target2.showInterface=false
36
+target2.type=ClassTarget
37
+target2.width=80
38
+target2.x=100
39
+target2.y=110
40
+target3.height=50
41
+target3.name=TicketMachine
42
+target3.showInterface=false
43
+target3.type=ClassTarget
44
+target3.width=120
45
+target3.x=80
46
+target3.y=50

+ 23
- 9
package.bluej View File

1
 #BlueJ package file
1
 #BlueJ package file
2
-editor.fx.0.height=722
2
+editor.fx.0.height=714
3
 editor.fx.0.width=800
3
 editor.fx.0.width=800
4
-editor.fx.0.x=709
5
-editor.fx.0.y=113
4
+editor.fx.0.x=240
5
+editor.fx.0.y=23
6
 objectbench.height=101
6
 objectbench.height=101
7
 objectbench.width=461
7
 objectbench.width=461
8
 package.divider.horizontal=0.6
8
 package.divider.horizontal=0.6
9
 package.divider.vertical=0.8007380073800738
9
 package.divider.vertical=0.8007380073800738
10
 package.editor.height=427
10
 package.editor.height=427
11
 package.editor.width=674
11
 package.editor.width=674
12
-package.editor.x=1067
12
+package.editor.x=480
13
 package.editor.y=119
13
 package.editor.y=119
14
 package.frame.height=600
14
 package.frame.height=600
15
 package.frame.width=800
15
 package.frame.width=800
16
 package.numDependencies=0
16
 package.numDependencies=0
17
-package.numTargets=1
17
+package.numTargets=3
18
 package.showExtends=true
18
 package.showExtends=true
19
 package.showUses=true
19
 package.showUses=true
20
 project.charset=UTF-8
20
 project.charset=UTF-8
24
 readme.x=10
24
 readme.x=10
25
 readme.y=10
25
 readme.y=10
26
 target1.height=50
26
 target1.height=50
27
-target1.name=TicketMachine
27
+target1.name=student
28
 target1.showInterface=false
28
 target1.showInterface=false
29
 target1.type=ClassTarget
29
 target1.type=ClassTarget
30
-target1.width=120
31
-target1.x=80
32
-target1.y=50
30
+target1.width=80
31
+target1.x=10
32
+target1.y=110
33
+target2.height=50
34
+target2.name=Heater
35
+target2.showInterface=false
36
+target2.type=ClassTarget
37
+target2.width=80
38
+target2.x=100
39
+target2.y=110
40
+target3.height=50
41
+target3.name=TicketMachine
42
+target3.showInterface=false
43
+target3.type=ClassTarget
44
+target3.width=120
45
+target3.x=80
46
+target3.y=50

+ 33
- 0
student.java View File

1
+
2
+/**
3
+ * Write a description of class student here.
4
+ *
5
+ * @author (your name)
6
+ * @version (a version number or a date)
7
+ */
8
+ class student
9
+{
10
+    // instance variables - replace the example below with your own
11
+    private int x;
12
+
13
+    /**
14
+     * Constructor for objects of class student
15
+     */
16
+    public student()
17
+    {
18
+        // initialise instance variables
19
+        x = 0;
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
+}