1 Instructions
Practice Problems
Problem 1
Problem 2
5.3.5

Assignment 2: Designing methods for complex data

Goals: Learn to design methods for complex class hierarchies. Practice designing the representation of complex data.

Please note changes in the second problem: modified method countArgs and a new method countFuns. The original problem was too complex.

The change has been posted on Friday, 17 January at 5:37 pm

1 Instructions

The names of the classes must be exactly the same as specified. The same is the case for the names and types of the fields within the class, as well as the order in which they are defined and listed as the constructor arguments. This allows us to design our own Examples class that tests your program.

Make sure you follow the style guidelines that WebCAT enforces. For now the most important ones are: using spaces instead of tabs, indenting by 4 characters, following the naming conventions (data type names start with a capital letter, names of fields and methods start with a lower case letter), and having spaces before curly braces.

You will submit this assignment by the deadline using the Web-CAT submission system. You may submit as many times as you wish. Be aware of the fact that close to the deadline the WebCAT system may slow down to handle many submissions - so try to finish early.

With each homework you will also submit your log file named pair-user1-user2.txt where you replace user1 and user2 with the usernames of the two partners.

On top of both files you will have five lines of comments as follows:

// assignment 2

// partner1-last-name partner1-first-name

// partner1-username

// partner2-last-name partner2-first-name

// partner2-username

(In the text file you do not need the two slashes)

There will be a separate submission for each problem - it makes it easier to grade each problem, and to provide you with the feedback for each problem wou work on.

The two submissions will be organized as follows:

Due Date: Tuesday, January 21st, 10:59 pm.

Practice Problems

Work out these problems on your own. Save them in an electronic portfolio, so you can show them to your instructor, review them before the exam, use them as a reference when working on the homework assignments.

Problem 1

The following DrRacket data definition describes the contents of a web site:

;;A Web Page (WP) is (make-wp String String [Listof Item (ILoItem)])

(define-struct wp (url title items))

 

;; An Item is one of

;; -- Text

;; -- Image

;; -- Link

 

;; A Text is (make-text String)

(define-struct text (contents))

 

;; An Image is (make-image String int String)

(define-struct image (file-name size file-type))

 

;; A Link is (make-link String WP)

(define-struct link (name page))

We are giving you the names of the classes or interfaces you will probably need — make sure you use these names to define your interfaces and classes.

For lists of data, the names of the interface should be always starting with ILo, the names two classes should be always starting with MtLo for the empty lists and ConsLo for the nonempty lists, each of these followed by the name of the datatype of the elements of the list. So we would have ILoString, MtLoString, ConsLoString to represent lists of Strings, ILoBook, MtLoBook, ConsLoBook to represent lists of Books, etc.

Problem 2

Define the file ExcelCells.java that will contain the entire solution to this problem.

For this problem we use classes that represent data in the cells of a spreadsheet. For each cell we record its row and column, where the cell is located, and the data (IData) stored. An IData item is either a number (int) or a Formula.

Each formula can be one of three possible functions: - (representing subtraction), max (producing the maximum of the two cells), or * (computing the product) and involves two other cells in the computation.