CSE 341 -- Programming LanguagesAutumn 2001 |
Department of Computer Science and Engineering, University of WashingtonSteve Tanimoto (instructor) |
Assignment 5Version 1.0 of November 16 (Subject to Change) |
A Sip* of JavaDue date and time: Wednesday, November 21, 2001 (at the beginning of class).Turn in this assignment by putting all your files in a subdirectory of your cubist www directory, named a5. You should have a web page (containing your applets) named index.html in that directory. |
Instructions:
Read Chapters 1-9 of Learning Java.
* "Sip of Java" -- All right, perhaps we should have
called this "A Single Short Latte."
Group Work: This assignment
should be performed individually (not in groups).
Part A: Applications
1.
(Simple, imperative coding in Java.)
Write a Java application that prints out the first
50 Fibonnaci numbers.
2.
(Working with inheritance and info hiding)
Write a Java application that constructs several
instances of 3-D figures as software objects and prints
out their descriptions by invoking their describe methods.
Use the following guidelines:
Part B: Applets
3.
(Basic applet structure)
Write a Java applet that determines the nth fibonnaci
number by letting the user enter an integer (n) in a
text field and then click on a button labeled Nth Fib.No.
It should then draw the number on a drawing area
(such as a JPanel or a Canvas) under the
text field and button. Put the applet on a web page
and turn in both a URL to the web page and hardcopy of
your code. You can put the web page in your Cubist
account, in your www subdirectory.
Optional variation 1: instead of returning the Nth
Fibonnaci number, return the nth Prime number. In this
case your button should be labeled Nth Prime.
Optional variation 2: return not a number but a
string that spells the number out in English words.
For example, if the user enters 365 and clicks the
button (labeled "to English words"), it should
display "three hundred sixty-five". You should
handle numbers up to 999,999.
4.
(Applets and Inheritance)
Choose one of the following two options.
User selects Natural and types in 59 + 0 and clicks "Compute".
Applet responds:
This is 59 speaking. I'm insulted to have a ZERO added to me!
Hi, my name is Nought. See how easy it is to count me in!
OK. 59 again. At least I didn't have to change.
User selects Real and types 3.1 * 5.7 and clicks "Compute".
Applet responds:
I'm 3.1, and you might be confusing me with Pi, who is a friend of
mine.
It's 5.7 here. I love to participate in REAL multiplication!
This is 17.67. I'm happy to have been produced.
User selects Natural and types in 5 - 6 and clicks "Compute".
Applet responds:
I'm a natural 5.
And I'm a natural 6.
Hello world, I'm -1, an Integer.
It's up to you to decide what the numbers "say", but ideally their
comments may take into account their values, their types, what
operations they are participating in, and possibly the value(s) of
the other operands. This behavior should be defined to take advantage
of your inheritance hierarchy, so that if no special behavior is
available for one type of number, then it inherits something
appropriate from its parent.
Use your imagination. Show that you understand inheritance and
can take advantage of it.