Browse Source

exercises complete

Shivam Patel 6 years ago
parent
commit
3e310e94d7
2 changed files with 41 additions and 56 deletions
  1. 41
    5
      TicketMachine.java
  2. 0
    51
      TicketMachineTest.java

+ 41
- 5
TicketMachine.java View File

@@ -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,19 +17,28 @@ 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
+    private int status;
21
+
22
+    public class Student {
23
+
24
+    }
25
+
26
+    public class LabClass{
27
+
28
+    }
20 29
 
21 30
     /**
22 31
      * Create a machine that issues tickets of the given price.
23 32
      * Note that the price must be greater than zero, and there
24 33
      * are no checks to ensure this.
25 34
      */
26
-    public TicketMachine(int ticketCost)
35
+    public TicketMachine()
27 36
     {
28
-        price = ticketCost;
37
+        price = 1000;
29 38
         balance = 0;
30 39
         total = 0;
31 40
     }
32
-
41
+    
33 42
     /**
34 43
      * Return the price of a ticket.
35 44
      */
@@ -38,6 +47,25 @@ public class TicketMachine
38 47
         return price;
39 48
     }
40 49
 
50
+    public void setPrice(int ticketCost){
51
+        ticketCost = price;
52
+    }
53
+
54
+    public void discount(int amount){
55
+        amount = price - amount;
56
+
57
+    }
58
+    
59
+    public void prompt(){
60
+        System.out.println("Please insert correct amount of money");
61
+
62
+    }    
63
+    
64
+    public void showPrice(){
65
+        System.out.println("The price of the ticket is " + price + " cents");
66
+
67
+    }
68
+
41 69
     /**
42 70
      * Return the amount of money already inserted for the
43 71
      * next ticket.
@@ -47,6 +75,10 @@ public class TicketMachine
47 75
         return balance;
48 76
     }
49 77
 
78
+    public int getTotal() {
79
+        return total;
80
+    }
81
+
50 82
     /**
51 83
      * Receive an amount of money in cents from a customer.
52 84
      */
@@ -54,7 +86,9 @@ public class TicketMachine
54 86
     {
55 87
         balance = balance + amount;
56 88
     }
57
-
89
+    public void empty(){
90
+        total = 0;
91
+    }
58 92
     /**
59 93
      * Print a ticket.
60 94
      * Update the total collected and
@@ -67,6 +101,8 @@ public class TicketMachine
67 101
         System.out.println("# The BlueJ Line");
68 102
         System.out.println("# Ticket");
69 103
         System.out.println("# " + price + " cents.");
104
+        System.out.println("# " + "price" + " cents."); 
105
+        System.out.println("#   price  cents."); 
70 106
         System.out.println("##################");
71 107
         System.out.println();
72 108
 

+ 0
- 51
TicketMachineTest.java View File

@@ -1,51 +0,0 @@
1
-
2
-
3
-import static org.junit.Assert.*;
4
-import org.junit.After;
5
-import org.junit.Before;
6
-import org.junit.Test;
7
-
8
-/**
9
- * The test class TicketMachineTest.
10
- *
11
- * @author  (your name)
12
- * @version (a version number or a date)
13
- */
14
-public class TicketMachineTest
15
-{
16
-    /**
17
-     * Default constructor for test class TicketMachineTest
18
-     */
19
-    public TicketMachineTest()
20
-    {
21
-    }
22
-
23
-    /**
24
-     * Sets up the test fixture.
25
-     *
26
-     * Called before every test case method.
27
-     */
28
-    @Before
29
-    public void setUp()
30
-    {
31
-    }
32
-
33
-    /**
34
-     * Tears down the test fixture.
35
-     *
36
-     * Called after every test case method.
37
-     */
38
-    @After
39
-    public void tearDown()
40
-    {
41
-    }
42
-
43
-    @Test
44
-    public void testTicket()
45
-    {
46
-        TicketMachine ticketMa1 = new TicketMachine(50505);
47
-        ticketMa1.insertMoney(699605);
48
-        assertEquals(0, ticketMa1.toString());
49
-    }
50
-}
51
-