123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- {\rtf1\ansi\ansicpg1252\cocoartf1561\cocoasubrtf400
- {\fonttbl\f0\fswiss\fcharset0 Helvetica;}
- {\colortbl;\red255\green255\blue255;}
- {\*\expandedcolortbl;;}
- \margl1440\margr1440\vieww12800\viewh8400\viewkind0
- \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0
-
- \f0\fs24 \cf0 2.1 ##################\
- # The BlueJ Line\
- # Ticket\
- # 500 cents.\
- ##################\
- \
- 2.2 500 cents\
- \
- 2.3. ##################\
- # The BlueJ Line\
- # Ticket\
- # 500 cents.\
- ##################\
- \
- ##################\
- # The BlueJ Line\
- # Ticket\
- # 500 cents.\
- ##################\
- \
- ##################\
- # The BlueJ Line\
- # Ticket\
- # 500 cents.\
- ##################\
- \
- \
- \
- 2.5 the printed value is different\
- \
- \
- 2.6 \
- \
- \{\
- Methods\
- Const\
- Variables \
- \}\
- \
- 2.7 Yes this will cause an error\
- \
- 2.8 It is possible no syntactical error. \
- \
- 2.9 private int price;\
- \
- private int balance;\
- \
- private int total;\
- \
- const - \
- price \
- balance\
- total \
- \
- TicketMachine\
- getPrice\
- balance\
- insertMoney\
- printTicket\
- \
- \
- 2.10 price = ticketCost;\
- balance = 0;\
- total = 0;\
- the prices seems to be set \
- \
- \pard\pardeftab720\partightenfactor0
- \cf0 Exercise 2.11 What do you think is the type of each of the following fields?\
- private int count; INT\
- private Student representative; STRING\
- private Server host; STRING\
- \
- Exercise 2.12 What are the names of the following fields?\
- private boolean alive;\
- private Person tutor;\
- private Game game;\
- \
- Exercise 2.13 In the following field declaration from the TicketMachine class\
- private int price;\
- does it matter which order the three words appear in? Edit the TicketMachine class to\
- try different orderings. After each change, close the editor. Does the appearance of the\
- class diagram after each change give you a clue as to whether or not other orderings are\
- possible? Check by pressing the Compile button to see if there is an error message.\
- Make sure that you reinstate the original version after your experiments!\
- \
- Exercise 2.14 Is it always necessary to have a semicolon at the end of a field declaration?\
- Once again, experiment via the editor. The rule you will learn here is an\
- important one, so be sure to remember it. \
- \
- YES, the java lang read needs a semicolon to read statements\
- \
- Exercise 2.15 Write in full the declaration for a field of type int whose name is\
- status.\
- \
- \
- \
- Exercise 2.16 To what class does the following constructor belong?\
- public Student(String name)\
- \
- Exercise 2.17 How many parameters does the following constructor have and\
- what are their types?\
- public Book(String title, double price)\
- \
- 2 params, String & double\
- \
- Exercise 2.18 Can you guess what types some of the Book class\'92s fields might\
- be? Can you assume anything about the names of its fields?\
- \
- Exercise 2.19 Suppose that the class Pet has a field called name that is of type\
- String. Write an assignment statement in the body of the following constructor so\
- that the name field will be initialized with the value of the constructor\'92s parameter.\
- public Pet(String petsName)\
- \{\
- ...\
- \}\
- Exercise 2.20 Challenge exercise What is wrong with the following version of the\
- constructor of TicketMachine?\
- public TicketMachine(int ticketCost)\
- \{\
- int price = ticketCost;\
- balance = 0;\
- total = 0;\
- \}\
- TICKETCOST IS ALREADY ASSIGN AS AN INT.\
- \
- }
|