![]() |
|
Assignments |
To complete the assignments, you will need to use the Java 2 SDK (software development kit) to compile and run your programs. This is installed on machines in student labs. You may install it on your own machine from the CD that accompanies the textbook. Alternatively, you can download the SDK from Sun. To write your programs, you may use a text editor. I suggest Textpad.
Please see the instructions on downloading and installing the Java 2 SDK package. My thanks to Steve Jost for providing this information.
Please follow these syntax rules when writing your programs. Not doing so will cost points.
// // CSC 224, section 501 // Assignment 1 // Programming exercise 16(a) // // John Rogers // jrogers@cs.depaul.edu //
index
, counter
, scoresAverage
, amountToPay
;
examples of invalid names include:INDEX
, cnter
, Index
,
scoresaverage
, scores_average
, amt2pay
. A
name like index2
is acceptable as long as there is a variable named index1
in the same scope.sort
, computeAverage
,
makeChange
, swapValues
; examples of invalid names include: srt
,
computeaverage
, mkChnge
, valueSwap
.Student
, VendingMachine
,
BankAccount
; invalid examples include: student
, vendingMachine
,
Bank_Account
. Complete exercises 16 and 24 from pp. 133-134 in the text. Submit a single zip file with all four programs. Make sure that the name each file and the name of the class it contains are the same.
Write the definition of a Warehouse
class as specified in exercises 16,
20, and 21 on p. 247. Also write a program to test each of the methods in the
class.
Write the definition of a Fraction
class as called for in exercise 23 on
p. 248. Add to it a method called toString
that converts a fraction to
a String. Write the methods so that the fraction is always stored in lowest
terms. Use FractionTest.java to test
your Fraction
objects.
Submit a single zip file with three files: Warehouse.java
, TestWarehouse.java
,
and Fraction.java
.
Write an applet to draw a chessboard, which is an 8-by-8 collection of squares whose colors alternate between black and red.
Write the applet described in problem 24 on p. 338 of the textbook.
Write the applet described in problem 21 on p. 337 of the textbook. I will have more to say about this one in class.
Write a program that reads a list of integers from a file and displays the following statistics in a dialog box:
The program should try to get the name of the file to open from the command line.
If it can't do this, it should prompt the user for the file name. If it is
unable to open the file, it should display an error message in a dialog box and exit.
Otherwise, it should proceed with the rest of the calculations.
The program should be structured, which means that such operations as opening the file and
computing the average should be done in methods separate from main.
For this assignment, continue with the implementation of a Matrix class hierarchy. Please define a Matrix class and an IntMatrix subclass. As discussed in class, include instance variables that keep track of the dimensions of a matrix and instance variables for storing the matrix values. Provide at least the following methods:
There are a variety of exceptions that can occur and that your code must detect. For example, trying to create a matrix with a non-positive dimension or trying to access an entry not in the matrix are two situations where an exception should be thrown.
Write a program to test your class. I have posted an example test program.
Submit your files in a zip archive.