Developed by Susan Haller and Timothy Fossum, University of Wisconsin-Parkside, to accompany Chapter 4 of An Introduction to Object-Oriented Programming with Java by C. Thomas Wu. Adapted by Pete Sanderson
Update your repository public folder, then copy folder Lab2 from public into your account. You will not turn it back in, so you do not need to keep it in the repository.
Launch jGRASP.
Go into the subdirectory ConvertDistance. You will use the Demo class (in the file Demo.java) to test the MetricConverter class (in the file MetricConverter.java). Examine the implementation of MetricConverter carefully.
The MetricConverter class has several methods, some unfinished. To answer some of these questions, we need to explain how to identify a program stub. A stub is a method which is not finished, but has enough code to be compiled and work with other methods. When one or more programmers are writing code, they frequently use stubs as placeholders until the programmer responsible has finished the work. In a stub, the body of the method usually contains only a comment saying 'this is a stub'. If the method needs to return a value in order to compile successfully, the programmer will add a line to return a dummy value such as 0.
Write your answers to these questions on your answer sheet:
As you have seen from the earlier question, the centimetersToInches() method is not yet implemented. Using the inchesToCentimeters() method as a model, implement the centimetersToInches() method. Make sure to change the comments as well!
Examine the Demo class implementation. When you run this program, the main() method creates a MetricConverter object and tests the inchesToCentimeters() and centimetersToInches() methods.
1 Run the demo for me and show me your finished code for the centimetersToInches() method.
At this time, you should finish the implementation of the feetAndInchesToCentimeters() method. As you write it, follow these guidelines:
Close the files containing the Demo and MetricConverter classes.
Modify this program so that the output is consistent with values used to construct the OurPoint object q. You are not allowed to change anything in the main() method.
Write your answers to these questions on your answer sheet:
Now open the file Demo.java. This is the same file that you used to test your first version of the MetricConverter class in subdirectory ConvertDistance. Compile and run the Demo program and observe what happens.
Modify Demo.java to use this second version of MetricConverter in which all the methods are class methods. You are not allowed to change anything in the file MetricConverter.java.
Write your answers to these questions on your answer sheet:
Compile and run the Demo program and observe the results. Notice, in particular, that the Rolls becomes dirty after Nigel drives it.
This directory has a file CarWash.java that contains most of the implementation of the CarWash class. Open this file and complete the implementation. In the Demo.java program, make a suitable instance of a CarWash object and finish the program by washing the Rolls and filling it with gas (at the appropriate place at the end of your Demo code indicated by comments).
Compile and run your Demo program and observe your results.
3 When you are ready, call me over and show me your completed code for Demo.java and the output of your program.