Kr Younger 6 gadus atpakaļ
vecāks
revīzija
6f18bc5155
7 mainītis faili ar 139 papildinājumiem un 1 dzēšanām
  1. Binārs
      .DS_Store
  2. 14
    0
      README.TXT
  3. 3
    1
      README.md
  4. 78
    0
      TicketMachine.java
  5. 24
    0
      bluej.pkg
  6. 20
    0
      bluej.pkh
  7. Binārs
      doc/BlueJ-objects-first-ch2.pdf

Binārs
.DS_Store Parādīt failu


+ 14
- 0
README.TXT Parādīt failu

@@ -0,0 +1,14 @@
1
+Project: naive-ticket-machine
2
+Authors: David Barnes and Michael Kolling
3
+
4
+This project is part of the material for the book
5
+
6
+   Objects First with Java - A Practical Introduction using BlueJ
7
+   Fourth edition
8
+   David J. Barnes and Michael Kolling
9
+   Pearson Education, 2008
10
+
11
+It is discussed in chapter 2.
12
+
13
+Purpose of project: To illustrate the basics of fields, constructors, and methods.
14
+How to start this project: Create one or more TicketMachine objects.

+ 3
- 1
README.md Parādīt failu

@@ -1,3 +1,5 @@
1 1
 # NaiveTicket
2 2
 
3
-the second Objects lab.
3
+the second Objects lab.
4
+
5
+look for the Chapter reading you need in the doc folder.

+ 78
- 0
TicketMachine.java Parādīt failu

@@ -0,0 +1,78 @@
1
+/**
2
+ * TicketMachine models a naive ticket machine that issues
3
+ * flat-fare tickets.
4
+ * The price of a ticket is specified via the constructor.
5
+ * It is a naive machine in the sense that it trusts its users
6
+ * to insert enough money before trying to print a ticket.
7
+ * It also assumes that users enter sensible amounts.
8
+ *
9
+ * @author David J. Barnes and Michael Kolling
10
+ * @version 2008.03.30
11
+ */
12
+public class TicketMachine
13
+{
14
+    // The price of a ticket from this machine.
15
+    private int price;
16
+    // The amount of money entered by a customer so far.
17
+    private int balance;
18
+    // The total amount of money collected by this machine.
19
+    private int total;
20
+
21
+    /**
22
+     * Create a machine that issues tickets of the given price.
23
+     * Note that the price must be greater than zero, and there
24
+     * are no checks to ensure this.
25
+     */
26
+    public TicketMachine(int ticketCost)
27
+    {
28
+        price = ticketCost;
29
+        balance = 0;
30
+        total = 0;
31
+    }
32
+
33
+    /**
34
+     * Return the price of a ticket.
35
+     */
36
+    public int getPrice()
37
+    {
38
+        return price;
39
+    }
40
+
41
+    /**
42
+     * Return the amount of money already inserted for the
43
+     * next ticket.
44
+     */
45
+    public int getBalance()
46
+    {
47
+        return balance;
48
+    }
49
+
50
+    /**
51
+     * Receive an amount of money in cents from a customer.
52
+     */
53
+    public void insertMoney(int amount)
54
+    {
55
+        balance = balance + amount;
56
+    }
57
+
58
+    /**
59
+     * Print a ticket.
60
+     * Update the total collected and
61
+     * reduce the balance to zero.
62
+     */
63
+    public void printTicket()
64
+    {
65
+        // Simulate the printing of a ticket.
66
+        System.out.println("##################");
67
+        System.out.println("# The BlueJ Line");
68
+        System.out.println("# Ticket");
69
+        System.out.println("# " + price + " cents.");
70
+        System.out.println("##################");
71
+        System.out.println();
72
+
73
+        // Update the total collected with the balance.
74
+        total = total + balance;
75
+        // Clear the balance.
76
+        balance = 0;
77
+    }
78
+}

+ 24
- 0
bluej.pkg Parādīt failu

@@ -0,0 +1,24 @@
1
+#BlueJ package file
2
+package.editor.height=275
3
+package.editor.width=400
4
+package.editor.x=420
5
+package.editor.y=175
6
+package.numDependencies=0
7
+package.numTargets=1
8
+package.showExtends=true
9
+package.showUses=true
10
+readme.editor.height=487
11
+readme.editor.width=610
12
+readme.editor.x=0
13
+readme.editor.y=22
14
+target1.editor.height=735
15
+target1.editor.width=648
16
+target1.editor.x=50
17
+target1.editor.y=60
18
+target1.height=50
19
+target1.name=TicketMachine
20
+target1.showInterface=false
21
+target1.type=ClassTarget
22
+target1.width=110
23
+target1.x=80
24
+target1.y=50

+ 20
- 0
bluej.pkh Parādīt failu

@@ -0,0 +1,20 @@
1
+#BlueJ package file
2
+package.editor.height=286
3
+package.editor.width=408
4
+package.editor.x=419
5
+package.editor.y=319
6
+package.numDependencies=0
7
+package.numTargets=1
8
+package.showExtends=true
9
+package.showUses=true
10
+target1.editor.height=735
11
+target1.editor.width=648
12
+target1.editor.x=50
13
+target1.editor.y=60
14
+target1.height=50
15
+target1.name=TicketMachine
16
+target1.showInterface=false
17
+target1.type=ClassTarget
18
+target1.width=110
19
+target1.x=80
20
+target1.y=50

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