Assignment

CS 161 - Spring 2017
Assignments & Labs
Assignment
Description
Due Date
Assign #1
Worksheet #1
Lab #1
Assign #2
pg 52 Exercises 1.3, 1.14, 1.15, 1.17, 1.20
Java code and Answers to questions
pg 56 Project 1.10
(initials)
pg 106 Exercises 2.4, 2.7, 2.9, 2.10, 2.17
Apr 7
Apr 10
Apr 12
Apr 14
Worksheet #2
Lab #2
Assign #3
Java code and Answers to questions
pg 110 Project 2.14
(Snowman)
pg 155 Exercises 3.1, 3.2, 3.5, 3.7, 3.9
Apr 17
Apr 19
Apr 21
Worksheet #3
Lab #3
Assign #4
Java code and Answers to questions
pg 157 Project 3.1**
(User name)
pg 200 Exercises 4.1, 4.2, 4.5 & SR 4.10, 4.13
Apr 24
Apr 26
May 1
Worksheet #4
Lab #4
Assign #5
Java code and Answers to questions
pg 202 Project 4.4**
(Dog class)
pg ?? SelfReview 4.20,4.24,4.30,4.32,4.34
May 1
May 3
May 5
Worksheet #5
Lab #5
Assign #6
Java code and Answers to questions
pg 204 Project 4.12**
(Crayons )
pg 201 Exercises 4.6, 4.7, 4.8, 4.10, 4.11
May 8
May 10
May 12
Worksheet #6
Lab #6
May 15
May 17
Assign #7
Java code and Answers to questions
pg 263 Projects 5.1 and 5.2 combined **
(Gregorian calendar)
pg 260 Exercises 5.1, 5.4, 5.9, 5.13 ,5.15
Worksheet #7
Lab #7
Assign #8
Java code and Answers to questions
pg 265 Project 5.12 ** (Golf)
pg 294 Exercises 6.1, 6.7, 6.10, 6.14, 6.16
May 22
May 24
May 26
Worksheet #8
Lab #8
Assign #9
Java code and Answers to questions
pg 298 Project 6.18 ** (Quilt)
pg 433 Exercises 8.1, 8.2, 8.3,8.4,8.7
May 31
May 31
June 2
Worksheet #9
Java code and Answers to questions
Lab #9
pg 435 Project 8.1 ** (Array)
Extra Credit Lab pg 299 Project 6.23
(dialog boxes)
All assignments must be typed using a word processor.
FINAL EXAM:
Mon, June 12th 8:00 – 9:50 am
May 19
June 5
June 7
June 9
** Additional Instructions All labs****
TURN IN:
1) An electronic copy of your code, in a folder, uploaded on Moodle.
2) Name your folder with your last name, first initial followed by Lab Number. So: Ima P
Nutt would name her folder for lab #1 as follows: NuttI_Lab1, for her lab 2 folder:
NuttI_Lab2, etc.
3) Zip the folder and upload the zipped folder to Moodle.
HEADER: Be sure to put a proper “header” at the top of your file(s) – There is a sample
on the last page of these instructions as well as a file named: header.java in the
dropbox. All files must have this header!!
TEST ORACLE (unless otherwise noted below…)
Be sure to put a “Test Oracle” in your header: (a Test Oracle is a chart that lists possible
inputs, and the output you would expect from your code - for that input)
The Test Oracle should be created before you write the code. Your program, when
done, should produce the same results. Caution: if you write your Test Oracle AFTER
writing the code (ie – use the running code to create the output values) you will not be
able to tell if your code is producing correct results.
LAB DETAILS:
Lab #1: Initials: Instead of printing your initials, you may choose to print any picture that can
be created with System.out.println() statements.
Lab #2 – Snowman: Be sure to turn in and print out both your .java file and your .html file.
Also: change the color of the “ground” to be either green or orange.
Lab #3 – Your Test Oracle should list several first and last names, and the corresponding
username your program should generate. (you may use XX for the random integers)
For example:
First Name
Daniel
Jonathan
Betsy
Last Name
Wilson
Anderson
Cartright
UserName
dwilsoXX
AprderXX
bcartrXX
Lab #4 – Write your own class Dog, and a driver class Kennel
A. in your Dog class
1) create a method called PeopleYears(), which calculates and returns the age of
the dog in “people years” (DogAge * 7).
2) use only two instance variables: Name and Age
3) create one constructor that receives two arguments: a string and an integer
B. In your driver class (Kennel):
a) Declare at least 4 dog objects.
b) Update three different instance variables (different objects) using “setter”
methods
c) Call at least two “getter” methods
d) Call the PeopleYears method for each object
e) Print the description of each Dog object you have created (using your
toString() method).
C. Create a test oracle for the method PeopleYears().
Lab #5 – Crayons– Use the example that starts on pg 184 in your textbook as a place to start.
(listing #4.7: the classes Splat, SplatPanel and Circle)
You will write three separate classes:
1) A “driver” program called CrayonBox
a) Create the frame, with the words “Crayon Box” in the Title Bar
b) Create a Crayon Panel object and call the constructor for Crayon Panel
c) Add the CrayonPanel object to the Frame
2) A separate panel class called CrayonPanel
a) Will instantiate at least 6 Crayon objects
b) With each object, call the Draw() method to draw it on the screen.
c) Draw a box over the crayons.
d) Draw your name somewhere on the screen
3) A class called Crayon,
a) The constructor will set the height, color and X,Y coordinates for each Crayon
object.
b) The class Crayon will need the method Draw to draw each Crayon object on the
screen. The Draw() method will use the height, and X,Y coordinates for the
Crayon objects’ position on the screen.
c) Write setter and getter methods for each instance variable
4) No test oracle required
5) Extra credit: create a method called RandomColor which returns a Color object.
The method will randomly generate the red, green and blue values for the Color.
Write a setter method that will call Random Color to set the Color for a crayon
Lab #6 – Gregorian Calendar – Leap years…..Combine the instructions for programming
projects 5.1 and 5.2. Your program will include a flag loop (not a sentinel loop) that
will allow the user to continue entering years until they say they are done. You will
also include a verification of input loop that will produce an error message if the year
entered is less than 1582, and ask for another input. When you ask for input from the
user, be sure to tell the user what years are acceptable. After each year is entered,
your program should produce a message telling the user if the year was a leap year or
not.
Test oracle: show the expected output for a number of different years: for examplebefore 1582, after 1582 that are leap years, after 1582 that are not leap years, and after
1582 that are also century marks (1900, 2000…)
Lab #7 –GOLF” Create a Text file with golf scores. Each line in the file will contain five
integer values – the first value is par for that hole, the next four values are scores for
each of the four golfers. The file will contain a total of 18 lines (18 holes). DO NOT
USE an ARRAYLIST for this lab. Your program will:
1)
2)
3)
4)
read information from the file, add the scores from each hole for each golfer
determine each golfers final score and print those scores.
determine the winner of this golf game and print a message saying who won
produce a table showing how each golfer’s score compares to par. (ie: 5 over
par, 2 under par… etc.)
5) Test oracle will use a ‘sample” file – of only 3 or 4 holes of golf… to test for
accuracy of your code.
6) Extra Credit: create the file you will be reading from by randomly generating
the integers needed and writing them to the file. See page 555 for an example
of writing to a file. Be sure to turn in the printed code for this program also,
and Octk it as “Extra Credit”
Lab #8 – QUILT – You must create a Pattern Class and declare two objects of that class. The
constructor for this class will accept a parameter that sets a characteristic of the object
(like the color and width). Alternate those objects when drawing the quilt. Make sure
that your quilt contains at least 5 blocks across and 7 down. (your grid must be at least
5 x 7 squares). Your Pattern class should include a method called Draw() that draws
the pattern on the screen at a specific location. The Draw() method must receive the x
and y coordinates of the location. You must use nested loops to draw the quilt. Test
oracle not needed. (Hint: Use the Splat, SplatPanel and Circle classes as an
example of how to write a Quilt, QuiltPanel and Pattern classes for this project.
Lab #9 – ARRAY: Generate 1000 random integers in the range 0-50. Use an array to hold the
count of how many times each of the values in the range comes up as a random
number. (do not use an array of 1000!) Print the contents of the array in a table that
lists the value (0-50) and then the contents of that array element.
Test oracle: generate 25 random integers in the range 0-10 and print how many times
each value was generated
SAMPLE HEADER
(everything in parenthesis should be replaced with your own information)
// **************************************************************
// Name: (Your Name)
Folder Name:(name of folder in Moodle)
// CS161 Winter 2017
Lab #: (1,2,3,4,5 ...)
// Class time: (Mon/Wed/Fri 8:00) OR (Mon/Wed/Fri 10:00)
// Date: (date done - ready to turn in)
// Program Name: (Name of file to be graded )
// Program Description:
( What does this program do? … short explanation)
//
( Test Oracle goes here! )
//*********************************************************************
public class NAME_OF_YOUR_FILE
{ public static void main(String[] args)
{ // your code goes here……make sure your code will compile before you turn it in!
}
// end main
}
// end class