Skip to content

Repository files navigation

Project: naive-ticket-machine
Authors: David Barnes and Michael Kölling

This project is part of the material for the book

   Objects First with Java - A Practical Introduction using BlueJ
   Seventh edition
   David J. Barnes and Michael Kölling
   Pearson Education

It is discussed in chapter 2.

Purpose of project: To illustrate the basics of fields, constructors, and methods.
How to start this project: Create one or more TicketMachine objects.

Answers:
2. 0
3. If you insert too much money into the machine there is no refund. When I don't insert enough, it still prints a ticket. 
5. The ticket shows that the price is different than the other machine.
7. It does matter whether we write public or private class ticketmachine because when I switched it to private an error occcurs. The class diagram has Red lines over it indicating that there's an error. Error message says that the modifier private is not allowed here.
8. It is possible to leave out the word public from the outer wrapper of the TicketMachine class.
9. It is not possible to leave out the word class.
10. Contructers: public ticketmachine (int cost) Methods: public int getPrice(), public int getBalance(), public void insertMoney(int amount), public void printTicket(). Fields: private int price; private int balance; private int total; return price; return balance;
11. Capital letters, its public
12. int, student, server
13. alive, tutor, game
14. private server host
15. only the original order works. if you rearange the words and error appears.
16. yes without the semicolon, there's an error.
17. private int status;
18. Student
19. 2, string and double
20. 
21.
23. there are no differences.
24. "How much money is in the machine"
25. Changing the name from getBalance to getAmount does nothing and you can still compile it. This tells me that the name can be anything and it would still most likely work.
27. it says "not a statement"
28. getPrice says "int" while the printTicket says "void" 
29. No they do not have return statements. I think this is because they are not supposed to be returning money but only inserting money and printing tickets. 
30. Yes. Before inserting money the getBalance amount was 0 and after inserting money the getBalance amount was 200.
31. Added a Screenshot.
32. Yes addCredits is a mutator 
33. Added a Screenshot.
34. private int age (curent age)
35. public void alive;
36.
37. My cat has green eyes.
39. I think the word "price" would be printed out along with the number of cents.
40. I think "# price cents" would be printed out.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages