April 8, 2003
Purpose: This assignment has two parts called Calculator and Player. It is intended as an introduction to program design and implementation. The objectives are as follows:
· Practice reading other people’s code (Calculator)
· Practice implementing simple classes encapsulating properties and responsibilities (Calculator)
· Practice using conditional statements (Calculator)
· Practice using arithmetic statements (Calculator)
· Practice modeling and turning a model into a software design (Player)
Time: The calculator should take you 1-2 hours to design and implement. The Player design is open-ended and it is up to you to decide how much time to spend on it. We will be discussing this assignment in quiz section this Thursday so you should have started working on it before then – otherwise section will be less useful and the assignment may seem unnecessarily hard.
Seeking help: You should (a) use the discussion board, (b) help each other in the lab, and (c) talk to the lab assistants. The discussion board, along with office hours, is the best way to contact a TA.
Turn-in, grading and due date: The due date is Tuesday April 15 at 6 pm. The turn-in consists of the Calculator Java source (.java) and class (.class) files and a design document for the Player. You don’t have to turn in a design document for the Calculator, but you should still create a rough design before you start coding. Both turn-in and grading are discussed in greater detail below.
Syntax, semantics and style: We will discuss the concepts of syntax, semantics and style in section on Thursday April 10. They form the metrics used by your TA to grade your programming assignments, so you will want to understand them well. Further grading guidelines for the TAs have been posted on the homework page of the course web page, so you can read them if you like.
Do you have to use the IPL? We recommend using the IPL for the implementation work if you had any problems with homework 0. The lab assistants are also a great source of help.
Anything else? Yes – these instructions are much less detailed than the instructions for homework 0. Be ready to experiment, improvise, engage in a little problem solving.
High-level Description: The first part of this assignment is to write a calculator. Your calculator will not have any buttons, a screen or such things, but it should be able to add, subtract, multiply, calculate integer quotients and calculate integer division remainders. It should also be able to store a number and return the stored number. Finally, your calculator should notice division by zero.
Goals: This part of the assignment will teach you about class implementation, methods, instance variables, arithmetic operations and conditionals, and show you an example of a test harness (see below). You will need to read and understand the test harness code.
Design vs. Implementation:
· Your design should include class name(s), method name(s), method parameters and their types, method return value types, instance variables and possibly more. However, you won’t have to (nor can you) make all these decisions yourself. Instead, you will be able to determine what many parts of the calculator design should be like by reading the test harness code (see below).
· During implementation you just have to write the code you already figured out the design for, and then test it to ensure you didn’t make errors. Your code has to work with the test harness.
Test Harness: A test harness (also called a test driver) is a program that checks whether another program works correctly. We are giving you a harness for your calculator, in the form of a Java source file (you won’t be able to compile the harness code until you have written your calculator code). You should read the harness code to determine how to design the calculator. Make sure you don’t change the harness code. Download the harness here.
Operating the Test Harness: Using Dr. Java’s Interactions Pane, type
java CalculatorTestHarness
Operating the Calculator: When you are done coding you can try things like the following in the Interactions Pane:
Calculator c = new Calculator()
c.store(3)
c.add(2, 7)
int stored = c.fetch()
c.add(2, stored)
c.integerQuotient(20, 5)
c.integerQuotient(20, 0)
You should omit the usual semicolons at the end of the statements when using the Interactions Pane, because that way Dr. Java prints out a response to your command. However, omitting semicolons in your Java source files will result in syntax error notifications when you compile.
Turn-in: You will use the course web site to turn in the files Calculator.java and Calculator.class.
Grading: We will use an extended test harness to find out how well each aspect of the calculator works. If your calculator doesn’t work with the harness we provide then it won’t work with the grading harness, which means we can’t give you a grade for that part of the assignment – A Bad Thing. Your TA will also read your code to check that it is cleanly written and well formatted – in other words, written in good style.
Hints:
· Using the Windows Task Bar at the bottom of the screen, select Start -> Programs -> Accessories -> Calculator. Then, using the Windows Calculator’s Menu Bar, select View -> Standard. Your calculator will be a little like this one. It won’t have a graphical user interface though, you will just invoke it using the Interactions Pane.
·
Read chapter 5 of the textbook. Section 5.2.2 talks
about arithmetic operations in Java. Chapter 8 talks about testing, feel free
to skim it if you want to but you don’t have to – we will get to that
later.
·
You will need to use a conditional statement to detect
division by zero. Conditionals are discussed in chapter 6 and will be covered
in lecture next Monday.
·
You only have to support integer types. If you have
extra time and like to play around you can try using decimal numbers as well.
·
Keep it
simple.
High-level Description: The second part of this assignment is to design a media player interface and document your design. The important design aspects are what functionality to include, and the choice of classes, properties and responsibilities to map the desired functionality to.
Goals: Practicing modeling and mapping a model to a software design in terms of classes with properties and responsibilities.
Turn-in: You will use the course web site to turn in a design document. Make sure your TA can read your design! The easiest way to do that is by using a file format that can be opened with a recent version of Microsoft Word. Unfortunately the IPL doesn’t have Word, but it does have Wordpad (Start -> Programs -> Accessories -> Wordpad).
Grading: Grading will be based on the simplicity and quality of your design. The completeness of your selection of functionality to include is much less important than the completeness of your mapping of functionality to a design.
Hints:
· You can use a familiar application like the Windows Media Player, Apple QuickTime or WinAmp for ideas.
· Your design will likely include classes like Player, Song, Band, Playlist and the like.
· This is intended to be somewhat open-ended. Improvise!