What did I submit? Check this listing.
The first line should contain when it was last updated. Look for the
group(s) that end with your userid.
The short list of only .java
programs in the current project directories. Really make sure your
files show up here!
Final grades should be posted no later than Sunday (12/22/02). If you
would like to know what yours is ahead of time, you can email me.
These are all the grades I have as of Saturday, Dec. 14. If you
see anything amiss, please notify me BEFORE Friday! If you would
like to pick up any previous projects, quizzes, or exams that I may still
have, I will be in my office from noon to 1:00 pm on Monday, Dec. 16.
You can probaby arrange something else by email if necessary.
A11 was the "quiz" from last Wednesday. If you don't know what I'm
talking about, you should have attended lecture. :)
As promised, here is the code to my board game engine: Checkers.java. Except for the code for the
mouse-driven player, there is nothing in it that we have not covered at
some point. Loops, arrays, multidimensional arrays, objects,
inheritance, graphics, polymorphism... Hmmm...
Project 10
- NOTE! Recursion and static variables do not mix!
- Part 1: Points will be deducted if you only only calculate the GCD
for one pair of inputs (i.e. you do not have a loop). Similarly points
will be deducted if this does not terminate at all.
- Part 1: Please name your file and test class with main()
GCDTest.
- Part 2: Use this test
class to test your palindrome implementation. Please submit this
file with your modifications.
- Part 2: This says create a method. Try to do it without any
helper methods. Think about what a palindrome is. Then think about the
shortest examples of palindromes. Is there a systematic way of getting
to these base cases? Write out your basic algorithm in your
comments (or by hand on the printout). Be sure to include your base
case(s) and recursive calls.
- Part 2: For fun, you can try writing _another_ method that
pre-processes the string so it works with phrases also. The classic one
is "A man, a plan, a canal - Panama!".
- Part 3: Yes, you will have to implement this.
- Part 3: Use this test
class to test your mergeSort implementation. Please submit this
file with your modifications. (Return the sorted array. If the array
only has one element, return that array -- it's already sorted.)
(Note that the code expects the sorted array to be returned. This
anticipates creating new subarrays before the recursive call. You may, of
course, alter it to something like void mergeSort(int[]a, int f, int
l),
provided you also make appropriate changes in the main() program.
Or you could do something like the quicksort call in the book, where it
just calls the "real" sorting method.)
- Part 3: This should look familiar (hint:
see proj 5).
- Part 3: Note that this is not the same as Quicksort!
While both use a divide-and-conquer methodology, their similarity
ends there. Quicksort works by moving the pivot value to its
correct location and other values to the correct sides of the pivot, while
MergeSort does its work on the return from the recursive calls, when it
re-combines the subarrays. (Also note that there are a number of ways you
can represent the subarrays you pass to the recursive calls.)
- As usual, your programs must at least compile for any credit, and a
printout is required on Tuesday.
Project 9
- Make one of the SUVs "excessively high" (your definition), and
the other one "normal-sized".
- Your repriduced picture does not need to be an exact replica
of the original, but should be close enough to tell that it is the same
picture with a quick glance -- a close approximation. You have a small
amount of leeway if you want to beautify it somewhat.
- Try to make use of loops to handle the repetition. You may
lose points if you have 30 separate blocks of code to draw each of
the 30 framing squares, for example. I don't want to be swimming in
outputs. It should fit on approximately 2-3 pages.
- It is possible to draw image files on the screen using java.
Feel free to explore this on your own, but please don't do it for this
project.
- If you suffer from colorblindness and feel that this will
impact your ability to reproduce the image, please email me ahead of time
(before break). Otherwise if we have any serious disagreements as to what
color should be where, my judgement will be correct.
11/19/02: No discussion sections!
I will have office hours from 2:30-3:30, and will probably be around
from 8:30-9:30 in the morning if you have any questions, but there is no
official class meeting Tuesday.
Here is the altered version of
the practice trace from Thursday. Try to figure out the output, then run
it to check your answers. Note the shadowed variable in Obj2.
Another problem. Create a class Goldfish that describes goldfish. It
should have instance variables the describe the color and size of the
goldfish. It should also have a class variable that tells us how many
goldish we have. It should also have an amountOfFood method that
calculates the amount of food a goldfish eats each day (a goldfish eat 0.5
lbs of food per pound of size).
Now create a java program that asks the user for a number of fish to
put in the pool, and the size of each fish in lbs. It should then print
out the number of fish, the amount of food each fish eats per day, and
the total amount of food we need per week.
An extension: create a subclass of Goldfish called Carp. Carp should
also have a luck variable, but you should arrange it so that there is
exactly one lucky carp. If you create another carp that is lucky, the
previous ones should immediately become unlucky. Create an equals method
that returns true if neither fish is the lucky one.
Here is the practice quiz I gave out on
Thursday (the 3:30 version). Try to figure out the output, then run it to
check your answers. Note the use of type promotion ("upcasting") from
Obj2 to its superclass Obj1 in the copy() command. This will be covered
in more detail when we go over polymorphism.
Project 8
- It might be a good idea to include a copy of an existing
employee (make a new object) in order to test your equality function.
- calcYearsService(int year): returns the number of years from
when the employee started to year.
- totalPay is the total amount of money the employee has
recieved to date.
- equals() should at least compare names and social security
numbers.
- Do not rename the file. Do not modify existing code
unless instructed to do so, either in the comments or adding to the main
method in part II.
- Output should be in a similar format for all types of
employees.
- We will determine the test data for the new classes in
Thursday's discussion. This probably will not be posted. Points may be
deducted if you do not use these test entries. If you cannot make
Thursday's discussion, email me ahead of time.
Be Warned!
The class drop deadline for undergrads is THIS MONDAY, November 4, at
4:30 pm.
Grades for the first half of the semester have been posted here.
If you have a total score below 290, I strongly suggest you talk to
either myself (you can set up an appointment by email) or Professor Bruell
before this deadline.
Project 7
- Having the user enter the numerator then the denominator is
fine.
- It should go without saying that entering something like "10"
or "-7" in the menu will not cause the program to crash.
- Make sure you check for invalid rational numbers when you do
your operations! These include divide-by-zero errors and rational numbers
with a negative sign in the denominator. Do not output invalid answers
(error messages are appropriate in the case of divide by zero errors).
- It is your choice what to do if a person attempts to do an
operation before they have input two numbers, however, the program should
not halt. You may output error messages or you may load up "default"
values at the start of your program.
- Please only create ONE INSTANCE of TextInput. No more.
There should only be one line that contains new TextInput(), and it
should not be in a loop or in a method that is called more than once.
It may be a class or instance variable ,or you can pass it into
apppropriate methods as a parameter.
- Use the keyword this to have an object refer to itself.
So, for example, inside of a Rational number
object, if you have a method that take
another rational number r as an explicit parameter
System.out.println(this+" : "+r); should print out both implicit
(this) and explicit (r) parameters.
- Note that this is not a cumulative arithmetic machine
like a normal calculator. The only time you save information is
for menu option 1. None of the other menu options require you to keep track
of the work after you have output your result. So if you have the numbers
1 and 2 entered, if you choose "add" it should print out 3. If you then
choose "multiply" it should then print out 2.
- If you need to, discard the oldest data you have.
- When order matters in an operation (like subtraction or
division), the older data should be considered to be on the
left hand side of the operator symbol. For example: If I enter
1/2 and then 2/3, subtraction should result in -1/6 ((1/2) - (2/3) =
-1/6). If I then enter 2/5, division should print out 5/3 ((2/3) / (2/5)
= 5/3). (Previously I had "right hand side." That was a typo.)
- Note this should only be submitted as only one file. Please
put some sort of comment block between all class definitions that makes it
easy to separate them, for example a line of 60 or 70 *'s.
- Include a comment block at the beginning of your file as per
proj 6.
- Once you get a block of code working, remove or comment out
any debugging messages you may have inserted to test it. Points will be
deducted for extraneous clutter.
Recent files worked on during class:
Timer class (modified)
TimerTrial class (uses Timer)
initial BlackJack class (contains
Card and Deck)
next BlackJack class (contains
Card, Deck, and Hand)
How's this for a metaphore? A CLASS is sort of like a mold in a
foundry. You only need one of them, and it describes (after a fashion) the
shape of the many OBJECTS you can create using it. Each INSTANCE may
be made out of a different alloy (different constructors make
different state variable values), and
may have different things put in it (different values in instance
variables), but it will still have the same holes (instance variables) and
pointy bits (methods).
Project 6
- A word of warning: the HP-UX java compiler is case-sensitive
with respect to filenames. Make sure they match your class names exactly
in case. If they don't, you may be seeing me about compiler errors on
things that seem to work perfectly in JCreator (you'll probably get all
your points back, but it will be a hassel to have to visit me to do this).
- A note on compiling multiple files: in the past the Java compiler has
sometimes had difficulty determining which files it needs to re-compile.
If you change your program but this is not reflected in its behavior,
especially if you'd gotten a compilation error at some point, possibly
in another file, this may have happened to you. If you think this might
have happened, go into your Project06 directory and delete all the files
ending in .class (NOT any .java files!), then try re-compiling your
program.
- Problem 1: Please only submit one file, appropriately named.
PS: there is a simple typo in the book's code.
- Problem 2: You may submit this either in a single file (similar to
problem 1) or in more than one file. However your main()
method should be in a class called ShapeTest. Please output the
results from your tests (don't just do internal number assignments, print
out the results as well). You may assign random numbers to the dimensions
of your shape objects or you may hard-code in numbers as long as they are
different for each object. You do not need to ask for user input.
- Note that you should have no more than one public class
in every file!* (It is generally better programming practice to put one
class per file, unless they are "helper" classes.)
- All files for both problems should be submitted in the same Project06
directory. If they do not show up in the
short list above (assuming it's
been updated since you submitted a file), it means they
aren't where they should be.
- All files you submit must contain at least one comment block
including your name and a brief (a few words long, a sentence at most)
description of what the file contains --
this should itself include all of the classes in the file. Failure to
include this comment block may result in a deduction of points.
- If any of your files do not compile, you will recieve a 0 for that
problem. It is possible that I may award points even if this is the case,
however you will have to see me during my office hours in order to have
this opportunity.
- As usual, hand in printouts in your discussion section. No
printout = no grade until I get a printout. And you can't wait until the
last week of class to hand these in.
* Actually a file may compile if there is no public class, but don't
get into the habit of doing this, especially as the compilers here
sometimes don't recognize non-public class files correctly. This
counts as a compilation error, so don't forget to include a public
class!
(The default permission is "package," out of private, protected, package,
public). FOLLOWUP: Actually the HP-UX compiler does seem to handle a file
containing a "package" class all right. It was my error in setting up
my command line arguments for it that resulted in this mistake.
If you did not hand in a printout for project 5, you will get a 0 until
you do so. I will grade it when you hand in the printout to me. If one
of your problems did not compile and you did not mention any problems in
comments/on the printout, you recieced 0 points for that problem. This
time you may see me in person during office hours (or appt.) and I will
take another look at this and possibly give some points back. I may not
give this second chance in the future. So Domino/DominoTest WILL work as
listed if put in two files (in the same directory).
Practice problems
- Write a complete Java program that takes arbitrary user input and returns the ten most frequently entered
tokens, in order, along with the number of times they had been entered. Stop reading input when the user enters the token
"-1". Hint: we can't use an array until we know how many types of tokens are entered. Try storing the input tokens in a
StringBuffer, and then use indexOf(s,i) and substring(i,j) to extract the tokens.
- Write a complete Java program that generates an array of 1000 random real numbers in the range -1000 >= x
> 1000.
Then write methods to compute an array's mean, median, minimum, and maximum values. Print out those
values, without rounding, for the array you generated. The median is the middle ordered value. The mean is the
average.
- Write a complete Java program that generates 1,000,000 random integers between 1 and 10,000,000. It
should prompt the user to guess a number. If the user guesses a number that had been generated, the user wins, otherwise
the user gets to guess again. Keep track of the number of guesses needed for the user to win. Minimize the amount of time
it takes to tell if a guess is correct or not.
- Write a complete Java program that randomly places a (black) king and 6 (white) queens on a chess board.
Repeatedly generate these boards until you get one that does not have the king in check, then print out that board.
Use a two dimensional array to represent the chess board and pieces. All board generated should be valid ones (so no stacking of the
queens allowed!)
Project 5:
- If you get compiler errors concerning Math.random(), try
adding the line import java.lang.Math; to the very beginning of
your program file, like in the Matrices.java example.
- Problem 1: Mergesort is basically:
- Given arrays a & b:
- Sort a, sort b
- create an empty array c big enough to holdall elements
of both a & b
- compare elements of a & b, adding the smaller to c.
Continue to do this until you have considered all elements in a & b.
If you reach the end of one array, just add the rest of the remaining one.
(EX: let's say your arrays are {4,5} and {1,3,7,8}. Compare 4 & 1.
Add 1. Compare 4 and 3. Add 3. Compare 4 and 7. Add 4. Compare 5 and
7. Add 5. This is the end of the first array, so just add 7 and 8.)
- return c
- Problem 1: Please only create one TextInput object (in
main, probably). Please only instantiate it once. Please pass it to any
methods that might need to use it to read in numbers.
- Problem 1: Make sure your output lines up nicely. The tab
character is \t.
- Problem 1: Do not assume that the user will enter a valid
input. Make sure your program will not crash if a number outside the
stated range is entered.
- Problem 2: Try the sets A=({5,4,4,3,6},
{6,6,6,6,6,6,3,4,5,4,5}) and B=({9,3,2,6000}, {3,2,6000,8}) in addition
to any others you would like to test. I may put some others up here
before Monday. Hard code the test arrays into your program -- user input
is not required, however meaningful output is.
- Problem 3: Make sure your output lines up nicely. The tab
character is \t.
- Problem 3: Some people are confused about the "i,j-th
element". This just means the element with the subscripts i,j. It's
referring to a specific element in a 2-d array, especially if you are
going to iterate through all of the elements. Think of it like
coordinates in the array "grid", if that helps.
In this case, if colors are being stored in the array and I am asking what
the color of the element with i=1, j=0 holds, it is red. For this problem
it means the values in the cells are based on their coordinates.
- Printout, as usual, due in discussion (or at least handed to
me before 4:20pm). Unlike previous projects, I will not grade any
projects that I do not have a printout for. You will recieve a 0 until
I get a printout, and may recieve a deduction in points for turning in
the printout late when I do grade it. (This is, of course, assuming that
it is electronically submitted on time.)
Matrix example program (The problem
from 8:30 was one of validation!
I was trying to multiply matrices that were not of matching size.
Frustrating, no?)
Project 4:
- Non-terminating loops are not acceptable. If I can catch your
project in one, I shall be less than pleased. You might want to
double-check this and if your program falls into this trap, possibly
re-submit a corrected version (before 8:30 AM) *cough*cough*.
- Problem 1 (counting input numbers): If the user enters an
invalid number (like 60, or -3), just discard that input. (You may
include an error message if you want, but do not have to.) Do not make
the program halt on any integer input except -1. ALSO: please do not use
more than one TextInput object! (Re-use that sucker, and make it earn
it's keep!)
- Problem 2 (histogram): I'll note that the array does not need
to be as big as the one in problem 1.
- As always, please hand in a printout in discussion (this is
now a standard part of the assignment, just like the 8:30 electronic
submission deadline). However, yould you please put your section time and
citrix userid on the printouts? It would make sorting them much easier.
Thanks. Also please staple multiple pages together -- I will not have a
stapler in 205.
8:30 section GetVowels class
If JCreator is acting strangely -- it suddenly gives you new and
unusual errors (like the JDK one) -- or you've somehow altered it
accidently and want it back to the way it was, you can reset it from the
start menu. So far this has cleared up all problems people have been
having:
- Exit JCreator
- Go to the Windows Start menu and choose: Start > Programs
> Development > Java > JCreator Settings > Reset JCreator Settings
- Then re-start JCreator
Next time... search & replace in a string? Censoring revisited!
Here is the source code for part of
the Factoring problem I am going to go over on Thursday. Take a look at
this version of the prime number generator (nextPrime()) and try to come
up with the code for the (missing) factor() method on your own.
8:30 section solution
3:30 section solution
These solutions are different. It might be helpful to take a look at
both of them.
Here are some notes from the
quizzes. Also here is some general
notes on programming, or at least some basic background information that
you should keep in the back of your mind.
Also, Paula has been nice enough to post some answers for some of
the the homework problems here. If you would like
to go over any of these (or other problems) stop by my office hours, but
really the best way to do this is to type out your solution in JCreator
and make sure it compiles and runs (and if it doesn't, keep at it until it
does).
Finally, I'll note that this course is very incremental. We will be
constantly using things covered earlier in the course. If there is
anything so far that you do not understand, now is the time to make
sure you correct that! Don't get caught in a snowball effect because you
didn't understand something from two or three weeks ago -- if you don't
keep up, it will come back to haunt you!
Project 3:
- Program development does not stop when it compiles without
errors! Once that is done, you still have to make sure it really does
what you wanted it to!
- All of these problems are numerical, not string-based, so
please try to come up with appropriate solutions.
- You should be doing any calculations you need in the body of
the loop, not in, for example, the for header. Doing unnecessary
calculations in the loop header usually just makes things more confusing
than they need to be.
- Yes, you do have to give me a print out of your source code.
Almost everyone managed this last time, there's no reason you can't do it
this time. The printout is due in my hand during your discussion section.
If you can't make it for some reason, email me by 9:00 pm on Monday. Lack
of a printout will be result in a deduction of points, at least.
- Problem 1 (Fibonacci) should use the loops that the method
names indicate. Getting the first few numbers in the series is a little
tricky and may take some thought. And the first number in the sequence is
zero, so you need 19 additional sequence numbers.
- You should also realize that problem 2 (eggs) is pretty
pointless if you do not produce any output. Take the hint.
- When setting these problems up, have the computer find the
solutions for you. You should not go into the problem assuming that you
know, for example, how many eggs are going to be in the basket. You want
to create as general a solution as is reasonable for the problem. So if I
ask you to find the first 30 Fibonacci numbers, you should only have to
change one number (the counter limit), and it should not require any
additional calculation on your part.
- Test your code before you submit it, not after! If you find
an error afterwards (but before the deadline), re-submit it!
- As has been mentioned many times, late projects will not be
accepted. The deadline is 8:30 AM on the date it is due. If you
re-submit something after this, it will be considered LATE, even if you
had previously submitted something before the deadline.
- Only .java files will be accepted. If you messed up and
opened a "project file" in JCreator, it is your responsibility to extract,
test, and submit the code you have actually written.
- Only submit your own work! We will be checking this.
- There are a finite amount of computing resources available.
On occasion the citrix server may go down temporarily or become full.
Keep this in mind, and don't leave things to the last minute -- lots of
other people will probably be doing just that, and you don't want to be
competing with them. If, for some reason, you can't log in, try again in
a little while (possibly a few minutes, possibly an hour or two). If you
can't log in remotely, try one of the labs on campus (301 MLH or Weeg,
which is supposedly open 24 hours).
Project 2:
- More on printing: You may not be able to directly print
from your home computer. If you have this problem, simply copy and paste the
code from JCreator into something running on your own machine (like
notepad) and print from that. You may run into the same problem on other
machines (Paula mentioned the library computers). Use a similar solution
in those cases.
- Make sure you submit this in a folder called "Project02"!
Only submit java files, not JCreator "project files".
- Not only should your program compile without errors, it should
compile without warnings! JCreator lets you get away with the warnings,
like if your class name and filenames do not match, but the unix version
of Java does not. So I may not be able to compile your programs,
even if you can!
- I noticed for Project 01 a number of prople tried using data
structures and methods not convered in class. Not everyone used them
successfully. Some of this was probably from having made a project
instead of a file in JCreator. Use files!
I'm going to wait on making a ruling on this for now,
except that if you misused a predefined class not covered in the book or
lecture so far, it is still a mistake. Also note that the unix and NT
java compilers are different versions. If it can't run on unix (v. 1.3),
I'm considering it broken. If you are only using things from the book or
lecture, this does not apply to you. (Actually, I'd encourage you to try
jumping ahead, but just be aware that you may need to figure out some
things on your own.)
- This must be electronically submitted by 8:30 AM on
Tuesday. You will also hand in a hardcopy of your code during your
discussion session I will not accept printouts of your programs after
4:20 pm on Tuesday, and will feel sad if I do not have one from you. You
should be able to use the citrix clent to print from your home computer
(it registers local printers) -- I am not sure about the ITC printers.
You can also print on the printer in 301 (assuming it still has toner in
it), called p301, but you need to provide your own paper. When you
try to print in citrix, you can choose what printer you want to use. If
you are not sure how to get something to print in general, try asking one
of the lab monitors. You can print through citrix in the ITC labs.
printers with divms.uiowa.edu in their name (named like p301) are in MLH
building. You don't want to use those unless you can get to them. Local
printers will probably have a really nasty looking name attached to them.
Pick one of those, as a rule. Ask a lab attendant if you need help
identifying which printer on the list is a local one.
- Your code must compile and run properly to recieve full
credit. If your code does not compile or run properly, you must
indicate this on your printout and also indicate where you think the
trouble spots are! ("It keeps making x=5!" and circle some likely code or
something, at least.) I will become vexed if you do not do this, and may
take off additional points! (This is not an excuse to leave things broken.
This is to help me make sure that you actually put some effort into trying
to fix it. You will still lose points for code that does not work.)
- The first problem is very similar to something I went over on
Tuesday. No, I won't repeat it again. :) And yes, both of them are
pretty simple (assuming you understand methods).
- For the second problem, have the method repeat the string
three times, once on each line (like you're testing a microphone).
Project 1:
- This will be electronically submitted. Details on how to
do this are on the main project 01 page.
- Please do not create any more that one java file for each of
the 4 questions. I would like it if you called them something like
project1_21,
project1_22,
project1_32, and
project1_33, but don't worry about it if you've already completed
them with different names.
- You may prompt the user for input if you need to try out a
bunch of different number combinations and it doesn't make sense to
hard-encode them into the program.
- Your programs should compile and run. You may need to
supply some additional information to get them to work.
- If your program has errors, they will show up in a window
below your main editing window. You will probably have to scroll around
in it to get all the information. Also it may be a bit cryptic, but you
should at least get out of it that there is an error and probably* what
line number it is on, to help you narrow it down.
*Though sometimes it gives a later line number if it isn't obviously an
error until that point.
- Note that your programs are supposed to answer the questions
when they are run. You may need to supply additional output.
- You may need to save your work in the JCreator folder
at H:\JCreator. Try moving things there if JCreator complains. If you
already have a different folder (like one called "project1" and things
seem to be working, don't worry about this.
- Every word that is bold in the textbook should
be blue in JCreator (because they are special "reserved
words" in Java).
Quiz 1:
- The class is TextInput. It is of type
TextInput. The method you wanted to use is readInt().
This returns an int. Don't mix and match things of different
types.
- You can think of the open and closed braces as enclosing some
of the code in a box. You need them around code defining classes and
methods.
- For methods headers, the method name must be the last thing
before the parameter list. public static main void() won't work!
JCreator webpage
We use the freeware LE package.
Older announcements
ghagen@cs.uiowa.edu