CS 1054 Introduction to Programming in Java (Spring 2008)

Lab 5: Introduction to Loops and Console Input

Lab Objectives

Instructions

For this lab, you will write a class from scratch and you will complete the implementation of another class that uses a loop and carries out console input. The classes are called CellPhone and CellPhoneConsole. Both classes are due together by the end of your lab section for the week of February 24th. CellPhone will be submitted to web-cat and CellPhoneConsole will be demonstrated to and handgraded by a TA. Begin by downloading Lab5.zip, save the file, and then extract it in a folder you can locate. Open this project in BlueJ.
  1. Check out the CellPhone and CellPhoneConsole classes. The CellPhone class itself is empty. This means that the CellPhoneConsole class (which has been provided almost complete for your convenience) cannot be compiled until the methods of the CellPhone class have been sufficiently defined.
  2. Define the CellPhone class. A cell phone represented by this class is a prepaid phone and supports very minimal functions. The cell phone can make a call, send a text message, add minutes to your cell phone and report how many minutes you have left as well as the number of texts and number of calls you have made. When a call is made you will need to pass a parameter specifying the duration of the call in minutes. A text will always be 1 minute worth of call time. Adding minutes will require a parameter indicating the number of minutes you are adding. You will need to implement the following methods for a CellPhone object: For a complete description of these methods, please visit this Java documentation page .
  3. Compile both classes and then execute CellPhoneConsole. (CellPhoneConsole is a tester program that creates a CellPhone object and uses the Scanner class and a loop to facilitate interactive input. Much of this program has been written for you.)
  4. Everything should compile, but the text message functionality of the CellPhoneConsole is not yet included in this class, which brings us to your next task.
  5. Read through the CellPhoneConsole class. Take note of the while loop: It will keep the program running until the command "quit" is typed and the boolean stop variable is set to true.
  6. Notice that the text message aspect of the CellPhoneConsole has not been implemented. Implement this so that the sendText() and getTextCount() methods are called on the CellPhone object.
  7. Don't forget to comply with the formatting guidelines and include your Javadoc-formatted method comments, particularly for the CellPhone class.
Submission
  1. This lab will only require the CellPhone.java file to be submitted to web-cat
  2. Demonstrate the CellPhoneConsole class to your TA.