Khalil Saboor 6 anos atrás
pai
commit
5b967ae529
5 arquivos alterados com 114 adições e 23 exclusões
  1. BIN
      .DS_Store
  2. 97
    4
      Labch2.rtf
  3. 3
    5
      TicketMachine.java
  4. 14
    14
      bluej.pkg
  5. BIN
      doc/BlueJ-objects-first-ch2.pdf

BIN
.DS_Store Ver arquivo


+ 97
- 4
Labch2.rtf Ver arquivo

@@ -2,7 +2,7 @@
2 2
 {\fonttbl\f0\fswiss\fcharset0 Helvetica;}
3 3
 {\colortbl;\red255\green255\blue255;}
4 4
 {\*\expandedcolortbl;;}
5
-\margl1440\margr1440\vieww10800\viewh8400\viewkind0
5
+\margl1440\margr1440\vieww12800\viewh8400\viewkind0
6 6
 \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0
7 7
 
8 8
 \f0\fs24 \cf0 2.1 ##################\
@@ -31,10 +31,103 @@
31 31
 # 500 cents.\
32 32
 ##################\
33 33
 \
34
-The same value is printed.\
35 34
 \
36 35
 \
36
+2.5 the printed value is different\
37 37
 \
38
-2.5\
39 38
 \
40
-2.6}
39
+2.6 \
40
+\
41
+\{\
42
+Methods\
43
+Const\
44
+Variables \
45
+\}\
46
+\
47
+2.7 Yes this will cause an error\
48
+\
49
+2.8 It is possible no syntactical error. \
50
+\
51
+2.9    private int price;\
52
+   \
53
+    private int balance;\
54
+    \
55
+    private int total;\
56
+\
57
+        const - \
58
+        price \
59
+        balance\
60
+        total \
61
+\
62
+	TicketMachine\
63
+	getPrice\
64
+	balance\
65
+	insertMoney\
66
+	printTicket\
67
+	\
68
+\
69
+2.10  price = ticketCost;\
70
+        balance = 0;\
71
+        total = 0;\
72
+	the prices seems to be set \
73
+\
74
+\pard\pardeftab720\partightenfactor0
75
+\cf0 Exercise 2.11 What do you think is the type of each of the following fields?\
76
+private int count;   	INT\
77
+private Student representative; 	STRING\
78
+private Server host;	STRING\
79
+\
80
+Exercise 2.12 What are the names of the following fields?\
81
+private boolean alive;\
82
+private Person tutor;\
83
+private Game game;\
84
+\
85
+Exercise 2.13 In the following field declaration from the TicketMachine class\
86
+private int price;\
87
+does it matter which order the three words appear in? Edit the TicketMachine class to\
88
+try different orderings. After each change, close the editor. Does the appearance of the\
89
+class diagram after each change give you a clue as to whether or not other orderings are\
90
+possible? Check by pressing the Compile button to see if there is an error message.\
91
+Make sure that you reinstate the original version after your experiments!\
92
+\
93
+Exercise 2.14 Is it always necessary to have a semicolon at the end of a field declaration?\
94
+Once again, experiment via the editor. The rule you will learn here is an\
95
+important one, so be sure to remember it. \
96
+\
97
+	YES, the java lang read needs a semicolon to read statements\
98
+\
99
+Exercise 2.15 Write in full the declaration for a field of type int whose name is\
100
+status.\
101
+ \
102
+\
103
+\
104
+Exercise 2.16 To what class does the following constructor belong?\
105
+public Student(String name)\
106
+\
107
+Exercise 2.17 How many parameters does the following constructor have and\
108
+what are their types?\
109
+public Book(String title, double price)\
110
+\
111
+2 params, String & double\
112
+\
113
+Exercise 2.18 Can you guess what types some of the Book class\'92s fields might\
114
+be? Can you assume anything about the names of its fields?\
115
+\
116
+Exercise 2.19 Suppose that the class Pet has a field called name that is of type\
117
+String. Write an assignment statement in the body of the following constructor so\
118
+that the name field will be initialized with the value of the constructor\'92s parameter.\
119
+public Pet(String petsName)\
120
+\{\
121
+...\
122
+\}\
123
+Exercise 2.20 Challenge exercise What is wrong with the following version of the\
124
+constructor of TicketMachine?\
125
+public TicketMachine(int ticketCost)\
126
+\{\
127
+int price = ticketCost;\
128
+balance = 0;\
129
+total = 0;\
130
+\}\
131
+TICKETCOST IS ALREADY ASSIGN AS AN INT.\
132
+\
133
+}

+ 3
- 5
TicketMachine.java Ver arquivo

@@ -35,12 +35,12 @@ public class TicketMachine
35 35
      */
36 36
     
37 37
    
38
-    public TicketMachine(int newPrice);
38
+    //public TicketMachine(int newPrice);
39 39
     
40 40
     
41 41
     public TicketMachine()
42 42
     {
43
-        price = newPrice;
43
+        //price = newPrice;
44 44
         balance = 0;
45 45
         total = 0;
46 46
         budget = 1000;
@@ -91,9 +91,7 @@ the value in budget. If price is greater than budget then print the message ‘T
91 91
 expensive’, otherwise print the message ‘Just right’.
92 92
  */
93 93
 
94
-    //if(price == budget){
95
-        
96
-    }
94
+    //if(price == budget){}
97 95
     /**
98 96
      * Print a ticket.
99 97
      * Update the total collected and

+ 14
- 14
bluej.pkg Ver arquivo

@@ -1,18 +1,18 @@
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
6
-objectbench.height=101
7
-objectbench.width=461
8
-package.divider.horizontal=0.6
9
-package.divider.vertical=0.8007380073800738
10
-package.editor.height=427
11
-package.editor.width=674
12
-package.editor.x=1067
13
-package.editor.y=119
14
-package.frame.height=600
15
-package.frame.width=800
2
+editor.fx.0.height=709
3
+editor.fx.0.width=960
4
+editor.fx.0.x=314
5
+editor.fx.0.y=23
6
+objectbench.height=164
7
+objectbench.width=556
8
+package.divider.horizontal=0.5995740149094781
9
+package.divider.vertical=0.7373271889400922
10
+package.editor.height=473
11
+package.editor.width=833
12
+package.editor.x=0
13
+package.editor.y=23
14
+package.frame.height=709
15
+package.frame.width=959
16 16
 package.numDependencies=0
17 17
 package.numTargets=1
18 18
 package.showExtends=true

BIN
doc/BlueJ-objects-first-ch2.pdf Ver arquivo