Skim Adages on Software Design and Development (I expect you to read all this stuff eventually, at your own pace.)
Write a few paragraphs on your reaction to the above reading assignments, and turn them in by email to Dr. Bloch. Be sure to include your name!
This looks like a lot of methods to write, but each one is pretty short and simple. They'll probably each be ten to twenty lines long, and most of this is contracts, examples, and inventories.
For all the programming assignments, be sure to follow the design recipe.
First, create a class; for now, all your methods will be in one class
(let's suppose it's called Homework1
.
Then, for each method, follow the design
recipe to design, code, and test it.
Be sure to choose meaningful names for methods and parameters, and watch for opportunities to re-use methods you, I, or the textbook have already written.
Also turn in a log of how many errors of different kinds you encountered in the assignment, with brief comments describing each one ("mismatched parentheses" is self-explanatory, but more complex errors might need more description). You may do this using the PSP forms, or simply by keeping track in a text file or on paper and turning it in.
This part can be done from any computer that has BlueJ and our
customizations installed, but it'll be easiest from your
computer rather than a lab computer.
Once you've written your methods and test cases, you should have two
classes: Homework1
and Homework1Test
. From
BlueJ's "Tools" menu, choose "Submit..." (which should be at the bottom
of the menu). Browse to "Computer Science Courses" -> "CSC 171
Introduction to Computer Science", then click the "Submit" button.
It'll ask for your name and any message you want to attach, then
(perhaps) your Adelphi e-mail address and password (it needs this in
order to send mail). It will then package up all the classes in the
current project and mail them to both Dr. Bloch and Dr. Stemkoski.
For now, I recommend putting all of these in one class (say,
Homework1
).
Develop a method named twist
which
takes in an image and returns a 10-degree-rotated copy of it overlaid
onto the center of a 10%-larger copy of it. Include a test case showing
what happens when you call twist
on the result of
twist
on the result of twist
.
Develop a method named caption
which takes in an image, a String, and a number, and produces an image
in which the specified String is overlaid on the image, with its center
the specified number of pixels down from the top of the image (and on
the center line).
Develop a method named hoursToMinutes
which takes in a number of hours and returns the number of minutes in that
many hours.
Develop a method named
daysToHours
which takes in a number of days and returns the
number of hours in that many days.
Develop a method named
daysToMinutes
which takes in a number of days and returns the
number of minutes in that many days.
Hint: re-use previously-written methods. You should
be able to write this method with no numbers or arithmetic
operators in the method body
(although you'll need numbers in your test cases, of course).
Develop a method named
squarePerim
which takes in the length of a side of a
square, and returns its perimeter.
Develop a method named
circleArea
which takes in the radius of a circle and
returns its area. The formula is π r2; use
the predefined variable Math.PI
as the value of π.
Develop a method named
dhmToMinutes
that takes in three numbers: how many days,
how many hours, and how many minutes, in that order, and returns the
total number of minutes.
Hint: You should be able to write this with no
numbers or multiplications in the body of the method, by
re-using previously-written methods.
Develop a method named
celsiusToKelvin
that takes in a number of degrees Celsius
and returns the same temperature as written in Kelvin. (A degree
Kelvin is the same size as a degree Celsius, but 0 Kelvin is approximately
-273.15 Celsius. This gives you at least one example:
Homework1.celsiusToKelvin(-273.15) should be about 0.
Come up with at least two more examples of your own.)
Note that the method should handle fractional degrees, not only
integers.
Develop a method named
fahrenheitToCelsius
that takes in a number of degrees
Fahrenheit
and returns the same temperature as written in Celsius. (The formula
is C = (F-32)*5/9 .) For example,
Homework1.fahrenheitToCelsius(68)
should produce 20.
Develop a method named
fahrenheitToKelvin
that takes in a number of degrees
Fahrenheit and returns the same temperature in Kelvin.
Hint: You should be able to write this with no
numbers or arithmetic operators in the body of the method, by
re-using previously-written methods.
Develop a method named
convert3digits
that takes in the "hundreds",
"tens", and "ones" digits of a number, in that
order, and returns the number. For example,
Homework1.convert3digits(5,2,8) should be 528
Develop a method named
convert3reversed
that takes in the "ones",
"tens", and "hundreds" digits of a number, in that
order, and returns the number. For example,
Homework1.convert3reversed(7,0,1) should be 107.
Hint: You should be able to do this with no
numbers or arithmetic operators in the body of the method, by
re-using previously-defined methods.
Develop a method named
quadraticFormula
that takes in the coefficients
a
, b
, and c
of a quadratic, and
computes the value of the largest real root. You may
assume that there is at least one real root.
The formula is (-b+sqrt(b2-4ac))/(2a).
Office visit:
/5
Did you do it?
Essay:
/25
(Grading primarily on content: convince me that you've read
the articles and some of the adages and thought about them.)
Error log: /10
(I'm not grading on how many or how few errors you encountered,
only on whether you recorded them adequately.)
Programming: To save time and get you feedback more quickly, I probably won't grade all of the methods, but a random selection of them. For each method, I'll award
Following directions | /10 |
Writing contracts from word problems | /10 |
Choosing test cases | /10 |
Choosing names; readability | /10 |
Coding | /10 |
Code re-use and function composition | /10 |
So if I were to grade 8 of the methods, the assignment would be worth 300 points: 5 for the office visit, 25 for the essay, 10 for the error log, 25 for each of 8 methods, and 60 for the "general skills".