assignment #1

COP2800
Homework #1 Assignment
Spring 2013
YOUR NAME:_________________________________________________ DATE: ______________
LAST FOUR DIGITS OF YOUR UF-ID: ___ ___ ___ ___ Please Print Clearly (Block Letters)
Date Assigned:
18 January 2013
IN CLASS
Date Due:
01 February 2013
E-SUBMISSION of Parts II and III
This homework assignment must be completed by you alone. You may not copy from others,
and you may not copy code from the Internet, textbook, or other sources.
However, you may study with others or read your textbook to determine general solutions. Then
you must complete the problems as your own work, not copying others’ work.
Questions about this homework should be addressed to your TA first. You can find your TA’s email at
the class website: http://www.cise.ufl.edu/~mssz/JavaNM/TA-hours.html
This homework has three parts: (I) Vocabulary Questions, (II) Regular Program, (III) Advanced
Program.
There is no penalty for guessing.
Part I. Vocabulary Questions
[10 points total]
Vocabulary: (terms you need to know to discuss the subject intelligently) – Define the following
terms using 1-3 sentences (and a diagram, if needed):
[2 points each]
a. Flow of control
b. Precondition loop
c. Class (in Java language)
d. Postcondition loop
e. Object (in Java language)
Part II. Regular Program
Carefully print or write (legibly) these
vocabulary words and their definitions on
a paper that you hand in at the beginning
of class on the due date. Your paper must
have in the upper right-hand corner: (i)
“COP2800-S13-HW1”, (ii) your name,
and (iii) last four digits of your UFID.
[20 points total]
TASK: Create a Java Program that converts temperature values from degrees C to
degrees F, and vice versa.
PROGRAMMING PROCEDURE:
(1) Use the following code as the basis for making a Java Class called TemperatureConverter, with
method C2F. Note that comments are in green typeface, and reserved keywords are in bold blue
typeface, and bold red typeface shows where you should insert your name and code. The text that
you will output to the screen is shown in brown typeface.
(2) Enter the code as shown in the example below (“Line#” denotes the statement number).
COP2800
Homework #1 Assignment
Spring 2013
(3) Save your code in file “TemperatureConverter.java” (save frequently to avoid work loss), then
compile using the Java tools that you downloaded to your laptop computer. Make sure it runs.
Java
Code
Line#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* Conversion between temperatures in Celsius and Fahrenheit
* Uses conversion forumulas from the Wikipedia entry:
* http://en.wikipedia.org/wiki/Temperature_conversion_formulas
* COP2800, Spring 2013 -- Student: <Your Name Goes Here>
* Date: 18-Jan-2013
*/
public class TemperatureConverter {
public TemperatureConverter()
{
}
// Method to convert from degrees Celsius to degrees Fahrenheit
public static float C2F(float degC)
{
float degF;
degF = degC * 9/5 + 32;
return degF;
}
// Method to convert from degrees Fahrenheit to degrees Celsius
… Please program method F2C using this line and next four lines
…
.
…
.
…
.
…
.
// Main method demonstrating usage of above methods
public static void main(String[] args)
{
System.out.print("91 degrees Celsius in Fahrenheit is: ");
System.out.println(C2F(91));
System.out.print("98.6 degrees Fahrenheit in Celsius is: ");
System.out.println(F2C(98.6));
//Test the accuracy of your program by combining the two methods
System.out.print("27.937 degrees Celsius using F2C(C2F(T)) is: ");
System.out.println( F2C( C2F(27.937) ) );
// Be polite when you end your program
System.out.print("Goodbye. ");
}
}
After you have entered, compiled, and tested the given code (minus lines 20-24, which you may
leave blank for purposes of testing), then do the following:
COP2800
Homework #1 Assignment
Spring 2013
(4) Create the method F2C in Lines 20-24, using the following equation:
degC = (degF - 32) * 5/9;
which is the standard formula for Celsius to Fahrenheit termperature conversion.
(5) Compile your code and run it.
(6) Submit your code electronically with your solution to Part III, as described below.
Part III. Advanced Program
[40 points total]
Programming with Java Classes and Objects. Perform the following steps:
(1) Create two subclasses of TemperatureConverter , and a Test class, as described below.
Superclass:TemperatureConverter
Subclass 1:
F2C
with method convert that has the functionality of method F2C in Part II
Subclass 2:
C2F
with method convert that has the functionality of method C2F in Part Ii
Class:
Test
with a method main that implements the same functionality as the main
method from Part II, using the convert method of the subclasses.
(2) For the Test class keep the method main that you used in Part II, for testing of your code. But you
might want to change the way the procedures F2C and C2F are invoked… [Hint: Remember how
we invoked class.method in the “HelloWorld” class during our first week of this course.]
(3) Document your code fully (as in the example in Part II). Compile your code and get it running.
Electronic Submission of Parts II and III. Put all files you created in Parts II and III in a single
ZIP file. Your ZIP file should contain TemperatureConverter.java, F2C.java, C2F.java, and
Test.java. Submit this ZIP file electronically per the instructions at:
http://www.cise.ufl.edu/~wchapman/COP2800/submit
Grading: Code does not compile or run
= 0 points.
Code compiles but does not run
= < 20 percent of points.
Code runs but wrong results
= 21 to 50 percent of points.
Code runs with correct results but no documentation (e.g., green comments in Part II)
= 51 to 70 percent of points.
Code compiles and runs, correct results, documentation present
= 71 to 100 percent of points.