[Instructions] [Search] [Current] [Syllabus] [Links] [Handouts] [Outlines] [Labs] [More Labs] [Assignments] [Quizzes] [Examples] [Book] [Tutorial] [API]
This page may be found online at
http://www.math.grin.edu/~rebelsky/Courses/CS152/98S/Handouts/exam.01.html.
Distributed: Friday, February 19, 1999
Due: Start of class, Friday, February 26, 1999
No extensions!
There are five questions on the exam, each with an equivalent point value. Note that the different questions are not necessarily of the same complexity or length. You must do four of the five problems. You may do a fifth problem for up to five points of extra credit on the exam. If you do five problems, you should identify which four are to be graded for primary credit. If you do not identify which problems are for primary credit, I will choose four.
This examination is open book, open notes, open mind, open computer, open Web. Feel free to use any and all resources available to you except for other people. As always, you are expected to turn in your own work. If you find ideas in a book or on the Web, be sure to cite them appropriately.
This is a take-home examination. It is likely to take you about four hours. You may use any time or times you deem appropriate to complete the exam, provided you return it to me by the due date. No late exams will be accepted. I will make a solution key soon after the exam.
Because different students will be taking the exam at different times, you are not permitted to discuss the exam with anyone until after I have returned it. If you must say something about the exam, you are allowed to say ``This is definitely the hardest exam I have ever taken.'' You may also summarize these policies.
Answer all of your questions electronically. That is, you must write all of your answers on the computer and print them out. Please put your answers in the same order that the problems appear in.
I will give partial credit for partially correct answers. You ensure the best possible grade for yourself by highlighting your answer and including a clear set of work that you used to derive the answer.
I may not be available at the time you are taking the exam. If you feel that a question is badly worded or impossible to answer, note the problem and attempt to reword the problem in such a way that it is answerable. If it's a reasonable hour (before 10 p.m. and after 8 a.m.), feel free to try to call me in the office (269-4410) or at home (236-7445).
I will also reserve time at the start of classes next week to discuss any general questions you have on the exam.
In some questions, you may be asked to write code. Since this is not an exam on syntax, you need not write working code. Rather you must write enough to convince me that you understand the underlying concepts and, given sufficient time to correct syntax, would be able to write a working program.
Carla and Carl Caffeinated, two of your fellow students, have been
working on a new assignment for CS152. They've decided that they need a
main class, which they call Main, and a utility class
for the stuff that their program manipulates, which they call,
surprisingly enough, Stuff.
As you might guess, the main method of Main
creates a number of Stuff objects and calls some of
the methods those objects provide.
Because they are novice programmers, they've been finding that they
need to make many changes to Stuff. They've noted that
some of the time they recompile Stuff, they also need
to recompile Main for the changes to take effect, but
other times they don't need to. Because they're working on the joyfully
slow HPs in the MathLAN, they'd prefer to avoid recompilation whenever
possible.
Write a short summary of when Carla and Carl will and will not need to
recompile Main after recompiling Stuff.
Your answer cannot be ``they should recompile Main if
the changes seem to have no effect''. Rather, your answer should be
sufficiently clear that they could decide what to do, even if there are
no immediately observable effects of the change.
There are a number of ways in which computer scientists define polymorphism. See how many you can find. Are they all essentially equivalent, or are there substantial differences between the different definitions?
Fillip and Fiona Fictitious are fooling with the Fraction
class that you used for assignment
4. They've had a number of problems, and would like your help.
Fillip has been testing the addition method, and getting what he thinks
are incorrect results. Here's the main method he's
been using.
/** Compute 1/3 + 2/7. */
public static void main(String[] args) {
SimpleOutput out = new SimpleOutput();
Fraction frac = new Fraction(1,3);
frac.add(new Fraction(2,7));
out.println(frac.toString());
} // main(String[])
For some reason, his output is always 1/3. Explain
why Fillip's results are ``incorrect''.
Fiona has noted that there are times when she has been using
Fractions when she really needs real numbers.
She's decided to write a FloatFraction class that
extends the Fraction class to add a
toFloat method which returns the float
equivalent of the current fraction. For example, given the fraction
1/2, toFloat would return 0.5.
Here's what she's written so far.
import Fraction;
/**
* Fractions that can be converted to real numbers.
*
* The original Fraction class is by our beloved professor, Samuel
* A. Rebelsky. We used version 1.0 of February 1999.
*
* The idea to make this modification came from a collaboration
* with the Caffeinateds.
*
* @author Fiona Fictitious
* @author Fillip Fictitious
* @version 0.0 of February 1999
*/
public class FloatFraction
extends Fraction {
/** Convert the current fraction to a float. */
public float toFloat() {
// Help!
return 0;
} // toFloat()
} // class FloatFraction
Help Fiona finish her function.
That is, fill in the body of
toFloat. (You should remove the line that
returns 0; Fiona just put it there as a stub.)
Fillip has suggested that in addition to the toFloat
method, they need a method that adds another fraction to the current
fraction and returns a float. Here's what he's come up with.
/**
* Add another fraction to the current fraction, returning
* the result as a float.
*/
public float add(Fraction another) {
// Help!
return 0;
} // add(Fraction)
i. Help Fillip finish his function. That is, fill in the body of
add. (You should remove the line that returns 0; Fillip
just put it there as a stub.)
ii. Java will complain if Fillip tries to add your improved function
to the FloatFraction class. Why?
Andy and Andrea Analyst have been working with a number of problems that have to do with area. Among other things, they've decided that they'll need to add areas. They've also learned that their analyses are aided by illustrations of areas. Hence, they also have decided to draw areas. At some times, they want to draw areas as circles; at other times they want to draw them as squares.
Putting all of their thoughts together, they've come up with five classes or interfaces they want to build.
DrawableThing, things that can draw themselves using the
draw(Graphics g) method.
AddableThing, things that can be added using the
add method.
Area which is-a DrawableThing and also
is-an AddableThing
CirularArea which is-an Area
SquareArea which is-an Area
Because Java only permits a class to extend one other class, they cannot make all of these classes. Which should be interfaces, and why?
Using these specifications, build the five classes or interfaces.
Irma and Irving have hired you to work on their object-oriented inventory system. They have given you the following specification.
Construct a class we can use to track the inventory of individual products. This class will be used to build an inventory control system.
The class should have fields for a name for the product, an id number (so that we can distinguish products with similar names), retail cost, wholesale cost, and quantity on hand.
They think that you're smart enough to decide which methods you'll need. When you press them, they say ``You'll need methods to report the value of the inventory at retail cost, remove a quantity from the inventory (when things are sold), and other stuff like that.'' It does seem like you'll need to decide on the methods yourself.
Build this class and develop an appropriate test plan. You need not implement the test plan, simply describe it.
[Instructions] [Search] [Current] [Syllabus] [Links] [Handouts] [Outlines] [Labs] [More Labs] [Assignments] [Quizzes] [Examples] [Book] [Tutorial] [API]
Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.
This page may be found at http://www.math.grin.edu/~rebelsky/Courses/CS152/99S/Handouts/exam.01.html
Source text last modified Thu Feb 25 15:00:55 1999.
This page generated on Thu Feb 25 15:02:55 1999 by SiteWeaver. Validate this page's HTML.
Contact our webmaster at rebelsky@math.grin.edu