home—info—lectures—exams—hws—archive
hw02
book background; scheme structs
due Sep.18 (Fri)
Due Sep.18 (Fri) (hardcopy, and on WebCT)
Your name and the assignment-number
must be in a comment at the start of the file.
(These are the reading-questions originally from hw01,
but deferred for those who ordered a textbook used after
the course started.)
- (9pts)
Chapter 1,
Review Questions1
…
- #6
- #9
- #10
- #11
- #14
- #15
- (3pts)
Chapter 1, Problem Set 18.
“Our criteria”
might include:
readability vs writability; various costs; orthogonality vs. feature multiplicity.
- (2pts)
Which languages might be involved in
setting up an on-line
order system, for a store?
(Feel free to chat with people who have taken
Software Engineering.)
- (6 pts)
Chapter 1 gives six costs associated with a programming language.
Which single cost do you think is most important for…
-
code controlling the space shuttle launch
-
code for a payroll program to be used by a Coca-Cola International.
-
code for a scientific simulation of proteins in a cell,
to help develop new drugs.
-
code to compute what percentage of RU students
have more than one picture on their RU home web page.
(Suppose that a friend is writing a report for a Media Studies
project, and wants to include this statistic.)
-
Code for maintaining all aspects of a course gradebook
(entering and editing information,
adding new features on demand like
“replace-lowest-hw-with-exam-percentage”,
generating web-views for instructor and students,
adding new features to the web-views as requested,
etc.).
(Just give the name of the category,
e.g. “compiling programs”.)
Which of the five example programs above is most “typical”
do you think,
of the sort of programs most programmers tend to work on?
The following problems deal with
frogger.
Follow all steps of the design recipe
(from lect02c—design recipe; functions returning structs and/or
How to Design Programs).
-
We start by representing trucks, and writing a method involving them.
-
Give a Java class to represent
a truck
(non-static fields and constructor only).
Note that no images are involved
(since the image doesn't vary from one truck to another2).
-
Give some Java statements which
create two different Truck objects.
-
The static method move will
which takes in a truck object,
and returns a whole new truck object which has traveled for
one unit of time (a "tick").
-
Write a stub method.
- Write two test cases.
(You'll need to print out the actual and expected results
of calling your method; presumably3 you'll want to
write a toString to help with this.)
You can put those test cases in Truck.main.
- After writing the test cases and getting them to compile,
now complete the method.
You should have a single .java file (which compiles
and runs);
it should be less than a page of well-spaced, commented code.
-
Repeat all parts of the previous question using
scheme structs and functions,
rather than Java classes and methods.
(Use check-expect for your test cases, of course.)
-
Now that we understand how to represent and process trucks,
we'll do the similar thing for a princess.
Write a scheme struct for a princess.
Following the design recipe,
write the function udpate-princess which
returns a new princess one tick later (in the same location,
but a little closer to disappearing.)
Note that you don't have to worry about what to
do when the princess's time has run out, if you don't want;
other later code can check for whether a princess should
disappear/teleport.
1
Short correct answers get more credit than long correct answers;
use a single word when possible.
↩
2
In your future game, you may want to have trucks moving both
left-to-right and right-to-left.
Even there, the image being used depends on the truck's direction/speed,
and is not an independent quantity.
[If you wanted to have different trucks use entirely different icons,
then that would require a field, but we'll decline doing that for now.]
↩
3
If you want to be fancier than just printing out
results, you can use JUnit tests.
This will require overriding equals.
↩
home—info—lectures—exams—hws—archive