next up previous
Up: Unit 03 Previous: Use of toString() in

Exercises

Exercise 03.1 Define a class Book to handle the information associated to books. The information of interest for a book are: the title, the authors, and the price. The methods of interest are:

Exercise 03.2 Write a Java class implementing an example client for the class Book of Exercise 3.1. The example class should perform the following operations:

  1. read from the keyboard the title and authors of a first book, and create a corresponding object;
  2. read from the keyboard the title and authors of a second book, and create a corresponding object;
  3. show the information about the first book;
  4. show the information about the second book;
  5. read the price of the first book and update the object accordingly;
  6. show the information about the first book, including the price.

Exercise 03.3 We want to realize a system for composing messages to send via a cell phone. Each message corresponds to a code. For example, to the code "ily" corresponds the complete message "I love you, darling.". Define the class MessageText to handle messages. The class must have:

Exercise 03.4 A message must contain the number to call, the number of the sender, and the message text. Define a class Message, with:

Exercise 03.5 Write an example program that uses the two classes MessageText and Message. The program should:

  1. inizialize a variable of type String that corresponds to the phone number of the sender;
  2. read the text and the code of a message, and store them in an object of type MessageText;
  3. read the phone number of the receiver;
  4. create an object of type Message;
  5. show the information about the object of type Message.

Define (and use) an auxiliary static method for reading a phone number from the keyboard. Solve the exercise so as to use all methods that have been defined in the classes MessageText and Message (possibly by creating and printing various messages).

Exercise 03.6 Modify the classes Book (Exercise 3.1) and MessageText (Exercise 3.3) by defining static methods to read the input from the keyboard. Test these methods by suitably modifying the example programs.


next up previous
Up: Unit 03 Previous: Use of toString() in