Problem 1E: Create a TicketMachine object on the object bench and take a look at its methods. You should see the... Problem 2E: What value is returned if you get the machine's balance after It has printed a ticket? Problem 3E Problem 4E Problem 5E: Create another ticket machine for tickets of a different price; remember that you have to supply... Problem 6E Problem 7E: Does it matter whether we write publicclassTicketMachineorclasspublicTicketMachine in the outer... Problem 8E Problem 9E: Put back the word public, and then check whether it is possible to leave out the word class by... Problem 10E: From your earlier experimentation with the ticket machine objects within BlueJ, you can probably... Problem 11E Problem 12E Problem 13E Problem 14E Problem 15E: In the following field declaration from the TicketMachine class private int price; does it matter... Problem 16E Problem 17E Problem 18E: To what class does the following constructor belong?
public Student (String name)
Problem 19E: How many parameters does the following constructor have, and what are their types?
public Book... Problem 20E Problem 21E: Suppose that the class Pet has a field called name that is of the type String. Write an assignment... Problem 22E: Challenge exercise The following object creation will result in the constructor of the Date class... Problem 23E: Compare the header and body of the getBalance method with the header and body of the getPrice... Problem 24E: If a call to getPrice can be characterized as "What do tickets cost?" how would you characterize a... Problem 25E: If the name of getBalance is changed to getAmount, does the return statement in the body of the... Problem 26E Problem 27E: Try removing the return statement from the body of getPrice. What error message do you see now when... Problem 28E: Compare the method headers of getPrice and printTicket in Code 2.1. Apart from their names, what is... Problem 29E: Do the insertMoney and printTicket methods have return statements? Why do you think this might be?... Problem 30E: Create a ticket machine with a ticket price of your choosing. Before doing anything else, call the... Problem 31E: How can we tell from just its header that setPrice is a method and not a constructor?
public void... Problem 32E: Complete the body of the setPrice method so that it assigns the value of its parameter to the price... Problem 33E Problem 34E: Is the increase method a mutator? If so, how could you demonstrate this? Problem 35E Problem 36E: Write down exactly what will be printed by the following statement: System. out. Println ("My cat... Problem 37E: Add a method called prompt to the TicketMachine class. This should have a void return type and take... Problem 38E Problem 39E: What about the following version?
Problem 40E Problem 41E: Add a showPrice method to the TicketMachine class. This should have a void return type and take no... Problem 42E: Create two ticket machines with differently priced tickets. Do calls to their showPrice methods show... Problem 43E: Modify the constructor of TicketMachine so that it no longer has a parameter. Instead, the price of... Problem 44E: Give the class two constructors. One should take a single parameter that specifies the price, and... Problem 45E: Implement a method, empty, that simulates the effect of removing all money from the machine. This... Problem 46E Problem 47E: Predict what you think will happen if you change the test in insertMoney to use the greater-than or... Problem 48E: Rewrite the if-else statement so that the method still behaves correctly but the error message is... Problem 49E Problem 50E: In this version of printTicket, we also do something slightly different with the total and balance... Problem 51E: Is it possible to remove the else part of the if-statement in the printTicket method (i.e., remove... Problem 52E: After a ticket has been printed, could the value in the balance field ever be set to a negative... Problem 53E: So far, we have introduced you to two arithmetic operators, that can be used in arithmetic... Problem 54E: Write an assignment statement that will store the result of multiplying two variables, price and... Problem 55E: Write an assignment statement that will divide the value in total by the value in count and store... Problem 56E Problem 57E: Modify your answer to the previous exercise so that the message includes the value of your budget if... Problem 58E: Why does the following version of refundBalance not give the same results as the original?... Problem 59E: What happens if you try to compile the TIcketMachine class with the following version of... Problem 60E: What is wrong with the following version of the constructor of TIcketMachine?
Try out this... Problem 61E: Add a new method, emptyMachine, that is designed to simulate emptying the machine of money, it... Problem 62E: Rewrite the printTicket method so that it declares a local variable, amountLeftloPay. This should... Problem 63E: Challenge exercise Suppose we wished a single TicketMachine object to be able to issue tickets of... Problem 64E: List the name and return type of this method:
Problem 65E Problem 66E: Write out the outer wrapping of a class called Person. Remember to include the curly brackets that... Problem 67E: Write out definitions for the following fields:
Problem 68E: Write out a constructor for a class called Module. The constructor should take a single parameter of... Problem 69E Problem 70E: Correct the error in this method: publicvoidgetAge()returnage; Problem 71E: Write an accessor method called getName that returns the value of a field called name, whose type is... Problem 72E: Write a mutator method called setAge that takes a single parameter of type int and sets the value of... Problem 73E: Write a method called printDetails for a class that has a field of type String called name. The... Problem 74E: Draw a picture of the form shown in Figure 2.3, representing the initial state of a Student object... Problem 75E Problem 76E: Create a Student with name "djb" and id "859012". What happens when getLoginName is called on this... Problem 77E Problem 78E: Challenge exercise Modify the getLoginName method of Student so that it always generates a login... Problem 79E: Consider the following expressions. Try to predict their results, and then type them in the Code Pad... Problem 80E: Open the Code Pad in the better-ticket-machine project. Type the following in the Code Pad:
Take... Problem 81E: Now add the following in the Code Pad: TicketMachinet2=t1; What would you expect a call to... Problem 82E: Add the following: t1.InsertMoney500; What would you expect the following to return? Think carefully... Problem 83E Problem 84E Problem 85E: Add a field, pages, to the Book class to store the number of pages. This should be of type int, and... Problem 86E: Are the Book objects you have implemented immutable? Justify your answer.
Problem 87E: Add a method, printDetails, to the Book class. This should print details of the author, title, and... Problem 88E: Add a further field, refNumber, to the Book class. This field can store a reference number for a... Problem 89E: Modify your printDetai 1 s method to include printing the reference number. However, the method... Problem 90E Problem 91E: Add a further integer field, borrowed, to the Book class. This keeps a count of the number of times... Problem 92E Problem 93E Problem 94E format_list_bulleted