the second Objects lab.

Labch2.rtf 3.3KB

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