Scott Grissom
School of Computing & Info Systems
Grand Valley State University
picture

Lab: Naive Ticket Machine

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.

  1. Open the Naive-Ticket-Machine project in Chapter 2
  2. Add your name as author to the source code
  3. Exercise 2.1
  4. Exercise 2.2 - What value is returned?
  5. Exercise 2.3
  6. Exercise 2.5
  7. Exercise 2.7 - What error message do you see?
  8. Exercise 2.8 - Is it possible?
  9. Exercise 2.10 - What is unique about the constructor?
  10. Exercise 2.13
  11. Exercise 2.14 - Is the semi-colon necessary?
  12. Exercise 2.20 - What is wrong with the code?
  13. Exercise 2.23 - Does the return statement need to be changed?
  14. Exercise 2.24 - WRITE THE "GET TOTAL" METHOD
  15. Exercise 2.25 - What error message do you see?
  16. Exercise 2.27
  17. Exercise 2.28
  18. Exercise 2.33 - WRITE THE "PROMPT" METHOD
  19. Exercise 2.34 - WRITE THE "SHOW PRICE" METHOD
  20. Exercise 2.39
  21. Exercise 2.40 - WRITE THE "EMPTY" METHOD
  22. Exercise 2.41 - WRITE THE "SET PRICE" METHOD
  23. Exercise 2.42 - WRITE A SECOND CONSTRUCTOR
  24. Read sections 2.11 and 2.12 about using "if statements"
  25. 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.
  26. 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).
  27. Make any necessary changes to have the source code meet our Java Style Guide requirements. Remember to add method headers!
  28. 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)