Programming Assignment 3
Due: Week of Jan. 30 before lab
-
(30 points) Problem 3.23 of the book.
Geometry: point in a rectangle. Write a program that prompts the user to
enter a point
(x, y)
and checks whether the point is within the rectangle centered at(0, 0)
with width10
and height5
. For example,(2, 2)
is inside the rectangle and(6, 4)
is outside the rectangle.- Name the file and program
ch3pr23.java
. - Example execution (
java ch3pr23
) user provides input:
Enter a point with two coordinates: 2 2
Point (2.0, 2.0) is in the rectangle - Example execution (
java ch3pr23
) user provides input:
Enter a point with two coordinates: 6 4
Point (6.0, 4.0) is not in the rectangle
- Name the file and program
-
(30 points) Problem 4.13 of the book.
Vowel or consonant. Write a program that prompts the user to enter a letter
and check whether the letter is a vowel or a consonant.
- Name the file and program
ch4pr13.java
. - Example execution (
java ch4pr13
) user provides input:
Enter a letter: B
B is a consonant - Example execution (
java ch4pr13
) user provides input:
Enter a letter: a
a is a vowel - Example execution (
java ch4pr13
) user provides input:
Enter a letter: #
# is an invalid input
- Name the file and program
-
(40 points) Problem 4.21 of the book.
Check SSN. Write a program that prompts the user to enter a Social Security
number in the format DDD-DD-DDDD, where D is a digit. Your program should
check whether the input is valid. You must handle all possible inputs.
- Name the file and program
ch4pr21.java
. - Example execution (
java ch4pr21
) user provides input:
Enter a SSN: 232-23-5435
232-23-5435 is a valid social security number - Example execution (
java ch4pr21
) user provides input:
Enter a SSN: 23-23-5435
23-23-5435 is an invalid social security number
- Name the file and program
-
Bonus.
(10 points) Problem 3.17 of the book.
Game: scissor, rock, paper. Write a program that plays the popular
scissor-rock-paper game. (A scissor can cut paper, a rock can knock a
scissor, and a paper can wrap a rock.) The program randomly generates
a number
0
,1
, or2
representing scissor, rock, and paper. The program prompts the user to enter a number0
,1
, or2
and displays a message indicating whether the user or the computer wins, loses, or draws. You need to handle invalid input by the user.- Name the file and program
ch3pr17.java
. - Example execution (
java ch3pr17
) user provides input:
scissor (0), rock (1), paper(2): 1
The computer is scissor. You are rock. You won - Example execution (
java ch3pr17
) user provides input:
scissor (0), rock (1), paper(2): 2
The computer is paper. You are paper too. It is a draw
- Name the file and program
General Instructions, Turning in assignments, and Grading
General Instructions
- Name each file and program as listed in the instructions.
- The top of each program should have a comment block where the first line
is your name and following lines are a description of your program.
//Name: Jory Denny
//This program debates Batman vs Superman! - Use proper coding style (described more in Grading below)
- Follow turn-in instructions precisely.
- Failure to complete any of these steps will result in a significant loss of points.
Turn in Instructions
Each assignment will be turned in to both Blackboard (soft copy) and in class (hard copy). Assignments are due BEFORE, let me repeat, before class starts. This does not mean five minutes after class starts.
- Soft copy (Online submission)
- Create a compressed
.zip
file of all Java programs needed to compile your program and all input files (if needed) to run your program.- If you do not know how to create a compressed
.zip
file, there is this cool new website you can use to search for instructions by entering"How to create .zip Windows 10"
or"How to create .zip MAC OSX"
for example.
- If you do not know how to create a compressed
- Submit
.zip
file on Blackboard by the stated due date and time.
- Create a compressed
- Hard copy (In-class submission)
- The first page of your hard copy must be a signed coverpage.
- Next put the programs in order as described in the description.
- If you do not know how to print a java file, there is this cool
new website you can use to
search for instructions by entering
"How to open and print .java file Windows 10"
or"How to open and print .java file MAC OSX"
for example. In combination with this, you may have to consult University of Richmond webpages to learn how to use campus printers. I recommend printing directly from sublime text editor on University computers (has printing feature enabled) and will print with syntax-highlighting (colors).
- If you do not know how to print a java file, there is this cool
new website you can use to
search for instructions by entering
- Staple all pages together.
- Turn in packet before class begins.
- I reserve the right to assign a 0 to any assignment failing to comply with these instructions. Even for something as small as a missing staple.
Points
- Each assignment is graded out of 100 points (not including bonus).
- Criteria and point distribution
- If the code is not named precisely or does not compile, -75% on a problem.
- If the code does not generate the correct output, -50% on a problem.
- Following instructions and algorithm used to solve, 25% on a problem. Following instructions is extremely important in computer science, train yourself to think like a computer. There are many ways to solve a problem, some may be better or worse than others.
- Stylistic elements of written code,
25% of a problem. Style includes (but is not
limited to):
- Descriptive comments on intent and purpose of code
- Descriptive and consistant naming conventions
- Indenting properly (after an opening brace, tab right by 1 indent; after a closing brace, tab left by 1 indent)
- Consistent spacing
- Consistent bracket placement (same line or on new line)
- Avoiding code duplication
- If there are any discrepencies in grades please see the instructor during his office hours or by appointment (do not discuss with the lab assistants or graders).