CSCE 302, HW 1 Explanation and Check-Off

HW 1
Kirk Scott
1
2
• Remember, the ultimate authority for what this
assignment consists of for any given semester is
the Word document posted on the course Web
site
• In general the assignment covers:
• toString(), equals(), clone()
• Singleton
• Prototype
• Builder
• Proxy
3
• The contents of the Word document (at some
point in time) are given on the following
overheads
• The is just for use as an in-class reference
• It is representative of the assignment and
illustrates in general the kind of requirements
and check-offs there are for the homework
4
• CSCE 302, HW 1
• Explanation and Check-Off
•
•
• Name:
_________________________________
5
• Preliminary explanation of the assignment:
• The first three parts of this assignment allow a
lot of latitude in how you do them.
• The fourth and fifth parts are set up in a more
structured way.
• Whether for relatively structured or relatively
unstructured parts, the general purpose of the
assignment can be described in this way:
6
• A. You need to sort through the material, the
design patterns, until you’ve got a clear mental
picture of what they are.
• B. You need to make up your own examples or
follow the specifications given and do the
implementation.
• C. When turning in your assignment you need to
demonstrate your examples to me, explaining
how they correctly reflect the pattern,
characteristics, or specifications that they’re
supposed to represent.
7
• When you hand in your homework, it is
reasonable to expect that you will show me
code, run the code, show the results, and use
both the source and the outcome to explain
what you accomplished.
• I will not collect anything from you.
• Evaluation will be done on this check-off sheet
in real time.
8
• In other situations I am known to simply do
black box testing.
• But in this case, if it’s helpful to show code,
then plan on showing it.
• It’s your call on what you show and how you
explain it.
9
• In some courses you are expected to do a formal
presentation or write a paper explaining some
development work you’ve done.
• In this course, in addition to writing the code
itself, you’re expected to practice the skill of
describing what you’ve done on a one-on-one,
piece-by-piece basis, with someone who is
knowledgeable about what the code was
supposed to do.
10
• In other words, the motivation behind the
assignment is both to do some development
work and also to get experience in expository
presentation by talking to an individual rather
than doing a PowerPoint presentation to a
group.
• The individual parts of the assignment are
given below.
11
• 1. ______ 10 pts. toString(), equals(), clone():
• Write the code for two classes.
• You may name these classes whatever you want to and
you may include in them whatever you want to.
• These two classes should be in a superclass-subclass
relationship.
• For each of the classes, implement toString(), equals(),
and clone() methods.
• Write a test program which will confirm that each of
these three methods works for each of the two classes.
12
• 2. ______ 10 pts. Singleton:
• Use either of the two classes you made for
part 1, copy it, and modify it so that it is a
Singleton class.
• Write a test program which demonstrates that
you can construct one instance of the class.
• The test program should also demonstrate
that it’s not possible to successfully construct
another instance of the class.
13
•
•
•
•
3. ______ 10 pts. Prototype:
Once again, this is pretty free-form.
Choose one of the classes you made above.
Write a prototype(), or partialCopy() method for
it.
• It’s your choice which instance variable values are
default and which are taken from the implicit
parameter.
• Write a test program that demonstrates the use
and outcome of using the method.
14
• 4. ______ 10 pts. Builder:
• This part comes with detailed instructions.
• It is too much of a mess to have you make up
your own example.
• The goal of this part of the assignment is to get
rid of the distractions of parsing and everything
else extraneous to the basic pattern.
• By getting rid of everything extraneous, no actual
reason remains which would cause you want or
need to do building.
15
• But the basics of the pattern will be illustrated.
• Your goal is to follow the specifications to a T and
include the testing elements so that it’s
straightforward to show that the pattern was
implemented.
• You may refer to the UML diagrams on overheads
number 70 and 71 to see an illustration of the
very basic version of the pattern which the
specifications ask for.
16
• I.
•
•
•
•
Let there be a base class named MyBaseClass.
Let it be a normal, concrete class with these
characteristics:
A. It has three integer instance variables simply
named baseA, baseB, and baseC.
B. It has a constructor which takes input
parameters for each of the instance variables.
C. It has get and set methods for each of the
instance variables.
D. It has a toString() method.
17
• II.
Let there be a builder class named
MyBuilderClass. Let it be a normal, concrete class
with these characteristics:
• A. Like MyBaseClass, it has three integer
variables. For clarity’s sake, let them be named
builderA, builderB, and builder.
• B. It has a default constructor which initializes
the three instance variables to zero.
• C. It has set methods for the three instance
variables. (Get methods are not necessary.)
18
• D. It has a build() method with these characteristics:
• The method tests to see if these conditions are true:
– builderA >= 1
– builderB >= 10
– builderC >= 100
• If all these conditions hold true, the method calls the
MyBaseClass constructor with the builder variables as
construction parameters and returns the MyBaseClass
object which is constructed.
• If any of the conditions doesn’t hold true, the method
constructs and throws an instance of the
MyBuilderException class (see below).
19
• III. Let there be a class named
MyBuilderException with these
characteristics:
• A. It extends the system supplied Exception
class.
• B. It has a default constructor consistent with
its superclass so that in your code it’s possible
to construct an instance of it.
20
• IV.
•
•
•
•
Let there be a test program named MyBuilderTest
with these characteristics:
A. It constructs a MyBuilderClass object.
B. It calls the set method for the variables on the
builder, passing in values that would be valid for a
MyBaseClass object.
C. In a try/catch block, it calls the build() method on
the builder.
D. It prints out the result of calling the toString()
method on the MyBaseClass object that’s returned.
21
• E. It creates another MyBuilderClass object.
• F. It calls the set methods on the builder object,
passing in at least one parameter value which is
out of range.
• G. In a try/catch block, it calls the build() method
on this builder object.
• H. It should catch the exception and all that the
catch block needs to contain is a line of code
which causes a message to printed out
announcing that building has failed.
22
• 5. ______ 10 pts. Proxy: Like Builder, this part
comes with detailed instructions.
• It is also too much of a mess to have you make up
your own example.
• Because the book example is relatively complex
by itself, and also because the example involves
Threads and Swing, it is not easy to come up with
logical specification which will allow you to
design a homework solution without a lot of
guidance.
23
• You may certainly refer to the overheads that cover
Threads and Swing, plus the overheads which cover the
Proxy design pattern when trying to figure out how to
do this part of the assignment.
• In general though, whether the overall purpose is very
clear, you should try to follow the specific instructions
given below.
• For better or worse, because of the nature of the
problem, the approach is pretty much to lead you by
the nose and hope that the end result is functional.
24
• I.
Let there be a base class named TestProxy. Let
it be a normal, concrete class with a main()
method. Inside the main() method, you should
do the following:
• A. Construct an instance of JFrame.
• B. Construct an instance of MyEditorPaneProxy
(see below) with two construction parameters, a
String containing this URL,
“http://ic.payap.ac.th/” and a reference to the
frame.
25
• C. Add the pane proxy object to a JScrollPane
object and add this to the frame.
• D. Set the frame size to something suitable
and set the frame to be visible.
• E. For the purposes of effective testing, insert
a Thread.sleep() call into your code.
• F. Call the load() method (see below) on the
pane proxy object.
26
• II. Let there be a proxy class named
MyEditorPaneProxy. Let it be a normal,
concrete class with these characteristics:
• A. It extends JEditorPane.
• B. It implements Runnable.
27
• C. It has two instance variables, String
URLPath and JFrame myFrameReference.
– It has a constructor with these characteristics:
– It takes parameters for the two instance variables.
– It sets the values of the parameters.
– It then sets its page to “https://www.yahoo.com”.
– It then repaints the frame.
28
• D. The class has a load() method with these
characteristics:
– It sets the page to “http://uaa.alaska.edu”.
– It then repaints the frame.
– It includes a time delay.
– It then creates a thread based on the pane and
calls start() on it.
29
• E. The class has a run() method with these
characteristics:
– It sets the page to the URLPath value that was
passed in when the pane object was constructed.
– It then repaints the frame.
30
Black box testing and observable
results:
• If you get the mess above to work, what will it do;
what will you see?
• First it should bring up the Yahoo Web page.
• This is the equivalent of “Absent” in the book.
• Next it should bring up the UAA Web page.
• This is the equivalent of “Loading” in the book.
• Finally, it should bring up the Payap University
Web page.
31
• Remember, the JEditorPane displays Web
pages poorly, so the contents may not be
recognizable.
• But it should be recognizable that different
things are being shown in sequence.
• Also remember that you will probably need to
put in calls to sleep() so that your life doesn’t
flash before your eyes too quickly to see it.
32
• A successful implementation will make it clear
that you’re sequencing through three different
Web pages, even if the display of the Web
pages is so poor that you can’t tell exactly
what they are.
• If the delays are long enough, there might be
time to use the scroll bars to look at some
content and verify which page you’re looking
at at any given time.
33
The End
34