Preparation
Do the following before arriving at lab:
- Read chapter 2
- Bring your textbook to lab
- Perhaps get started early, this lab is much longer than previous ones
Objectives
After completing this lab, you should be able to:
- invoke object methods
- inspect the state of an object
- make simple changes to the source code and recompile
Exercises
Read Chapter 2 and perform each of the following exercises. Write your
responses to any questions on this paper.
- Open the Naive-Ticket-Machine project in Chapter 2
- Add your name as author to the source code
- Exercise 2.1
- Exercise 2.2 - What value is returned?
- Exercise 2.3
- Exercise 2.5
- Exercise 2.7 - What error message do you see?
- Exercise 2.8 - Is it possible?
- Exercise 2.10 - What is unique about the constructor?
- Exercise 2.13
- Exercise 2.14 - Is the semi-colon necessary?
- Exercise 2.20 - What is wrong with the code?
- Exercise 2.23 - Does the return statement need to be changed?
- Exercise 2.24 - WRITE THE "GET TOTAL" METHOD
- Exercise 2.25 - What error message do you see?
- Exercise 2.27
- Exercise 2.28
- Exercise 2.33 - WRITE THE "PROMPT" METHOD
- Exercise 2.34 - WRITE THE "SHOW PRICE" METHOD
- Exercise 2.39
- Exercise 2.40 - WRITE THE "EMPTY" METHOD
- Exercise 2.41 - WRITE THE "SET PRICE" METHOD
- Exercise 2.42 - WRITE A SECOND CONSTRUCTOR
- Read sections 2.11 and 2.12 about using "if statements"
- Modify the insertMoney method using an if statement so that only positive values are accepted. Zero or negative values cause an error message to be printed.
- Modify the printTicket method using an if statement so that the ticket is only printed if enough money has been inserted. If sufficient money has not been entered then print a message explaining how much is still required (i.e. price - balance).
- Make any necessary changes to have the source code meet our Java Style Guide requirements. Remember to add method headers!
- Print the final source code (include your name as author).
Grading Criteria
This lab is worth a possible 10 points.
- Turn in this printed page with your hand written answers and the printed source code.
- Correct answers to the questions (3 pts)
- Source code (4 pts)
- Style (3 pts)
|