Computer Science 501
Data Structures and Algorithm Analysis
Fall 2014, The College of Saint Rose
Lab 1: Conway's Day of the Week Calculator
Due: 6:00 PM, Tuesday, September 2, 2014
This week's lab exercise is intended to bring you up-to-speed or back
up-to-speed, as the case may be, with Java programming.
There are some questions to answer, practice programs to write, and
one more substantial programming assignment to complete.
You may work alone or with a partner on this lab. Only one submission
per group is needed.
Getting Set Up
To get your BlueJ environment set up for this week's lab assignment,
start BlueJ and choose "New Project" from the "Project" menu.
Navigate to your folder for this course and choose the name
"Lab1" (no spaces) for the project.
Create a document where you will record
your answers to the lecture assignment and lab questions. If you
use plain text, call it "lab1.txt". If it's a Word
document, you can call it whatever you'd like, but when you submit,
be sure you convert it to a PDF document "lab1.pdf"
before you submit it.
Lecture Assignment Questions
We will usually discuss these questions at the start of class on the
lab due date, so no credit can be earned for late submissions of
lecture assignment questions.
LA Question 1: I would like to get a better sense of everyone's backgrounds
coming in. Please answer each of the following. (4 points)
- Which degree program are you in, if any?
- What other computer sciences have you taken, either before
or at Saint Rose?
- Briefly describe your programming experience. Which
programming languages have you used and how complex were the
programs you developed?
- What is your favorite restaurant in your home town and what
should I order there?
- What types of computers (e.g., PC running Windows, Mac) have
you used?
- If you plan to use computers other than those in
Saint Rose labs for course work, what type of computer
do you plan to use?
LA Question 2: Bailey Problem 1.2, p. 26. (2 points)
LA Question 3: a. Show the steps needed to compute the GCD of 31415 and
14142 using Euclid's algorithm. b. How much faster is this than the
more naive algorithm that checks consecutive integers starting at
14142 (the smaller of the two numbers whose GCD we are computing)
until the GCD is found. (5 points)
LA Question 4: Once upon a time a farmer went to market and purchased a
fox, a goose, and a bag of beans. On his way home, the farmer came
to the bank of a river and rented a boat. But in crossing the river
by boat, the farmer could carry only himself and a single one of his
purchases - the fox, the goose, or the bag of the beans. If left
together, the fox would eat the goose, or the goose would eat the
beans. The farmer's challenge was to carry himself and his
purchases to the far bank of the river, leaving each purchase
intact. Find the shortest sequence of crossings you can (where the
farmer can carry 0 or 1 of his purchases in the board on each
crossing) that solve the problem. (See if you can work it out -
don't just look it up!) (5 points)
Practice Programs
Practice Program: Write the class described by Bailey Problem
1.8, p. 27, in a file PhoneNumber.java. In addition to fields
and constructors as required, include an appropriate toString
method, and write a main method that thoroughly tests your
implementation. (7 points)
Practice Program: Write the class described by Bailey Problem
1.12, p. 27, in a file ComboLock.java. Again, include a
main method that thoroughly tests your implementation. (10
points)
Programming Assignment
Write the program for the lab exercise at the end of Chapter 1 of
Bailey.
- Write your entire program in a single Java source file
Date.java. The main method required by step 4 of the
procedure might normally be more appropriate in a separate class,
but keep it in the Date class here for simplicity.
- Avoid large switch statements by using arrays from which
you can look up information such as the day-of-week adjustment table
and the number of days in each month.
- Don't forget to answer the thought questions as well. Please
put the answers to these in your lab1.txt or
lab1.pdf file.
Submitting
Before 6:00 PM, Tuesday, September 2, 2014, submit your lab
for grading. There are two things you need to do to complete the
submission: (i) Copy your file with the answers to the lecture
assignment and lab questions into your project directory. Be sure
to use the correct file name. If you prepared your answers in Word,
export to a PDF file and submit that. (ii) Upload a copy of your lab (a
.7z or .zip file containing your project directory) using
Submission
Box under assignment "Lab1".
Grading
This assignment is worth 75 points, which are distributed as follows:
>
Feature | Value | Score |
Lecture assignment questions | 16 | |
PhoneNumber.java instance variables | 1 | |
PhoneNumber.java constructors | 2 | |
PhoneNumber.java toString method | 1 | |
PhoneNumber.java complete main method | 3 | |
ComboLock.java instance variables | 2 | |
ComboLock.java general constructor | 1 | |
ComboLock.java default constructor | 1 | |
ComboLock.java press/reset/lock/isLocked | 4 | |
ComboLock.java complete main method | 3 | |
Basic Date class | 5 | |
Date constructor to generate an arbirtrary date | 3 | |
Date constructor to generate valid random dates | 5 | |
Method in Date to compute day of week | 5 | |
main method to play Conway's game | 8 | |
Date.java comments | 5 | |
Date.java naming conventions | 3 | |
Date.java formatting | 2 | |
Thought questions | 5 | |
Total | 75 | |
|