Programming Assignment 6
Due: Week of Feb. 27 before lab
-
(25 points) Problem 12.7 of the book.
NumberFormatException
. Write thebin2Dec(String binaryString)
method to convert a binary string into a decimal number. Implement thebin2Dec
method to throw aNumberFormatException
if the string is not a binary string. In main, allow a user to enter a binary string and test your method.- Name the file and program
ch12pr7.java
. - Example execution (
java ch12pr7
) user provides input:
Enter a binary number: 1001
Decimal value is 9 - Example execution (
java ch12pr7
) user provides input:
Enter a binary number: 1001a1001
Error. Input was not a binary number.
- Name the file and program
-
(25 points) Based on problem 12.11 of the book.
Remove text. Write a program that removes all occurrences of a specified
string from a text file. You should take three inputs from the user, first
an input filename, second a string to remove, and third an output filename
to output the new text. You should assume the string to remove is a single
word without spaces and that the input file only has occurrences of the
string as whole words (as in it will not appear in the middle of a string).
- Name the file and program
ch12pr11.java
. - Example execution (
java ch12pr11
) user provides input, example file:
Enter an input filename: withJLD.txt
Enter a string to remove: JLD
Enter an output filename: withoutJLD.txt
Hello class! - Example execution (
java ch12pr11
) user provides input:
Enter an input filename: nothing
Enter a string to remove: JLD
Enter an output filename: withoutJLD.txt
Error. Cannot find input filename.
- Name the file and program
-
(25 points) Problem 12.19 of the book.
Count words. Write a program that counts the number of words in President
Abraham Lincoln's Gettysburg address.
- Name the file and program
ch12pr19.java
. - Example execution (
java ch12pr19
):
There are 277 words in the Gettysburg Address.
- Name the file and program
-
(25 points) Problem 12.21 of the book.
Data sorted? Write a program that reads the strings from a file and reports
whether the strings in the files are sorted in alphabetical order. If the
strings are not sorted in the file, the program displays the first two
strings that are out of order.
- Name the file and program
ch12pr21.java
. - Example execution (
java ch12pr21
) user provides input, example file:
Please enter a filename: Scrabble.txt
File 'Scrabble.txt' lists words out of order.
The first two out of order words are 'ZA' and 'AAH'. - Example execution (
java ch12pr21
) user provides input, example file:
Please enter a filename: LongScrabble.txt
File 'LongScrabble.txt' lists words in order.
- Name the file and program
-
Bonus.
(10 points) Based on problem 12.25 of the book.
Process large dataset. A university posts its employees' salaries
here. Each line in the file consists of a faculty
member's first name, last name, rank, and salary. Write a program that
outputs a file named
Summary.txt
that contains the total salary for assistant professors, associate professors, full professors, and all faculty, respectively, and contains the average salary for assistant professors, associate professors, full professors, and all faculty, respectively.- Name the file and program
ch12pr25.java
. - Example execution (
java ch12pr25
) note the program itself does not display any output:
Resulting file:total average
assistant 20246511.91 65949.55
associate 28844146.58 83849.26
full 35678051.41 102229.37
all 84768709.90 84768.71
- 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).