Programming Assignment 04
Due: Week of Sep. 19 in lab
-
Problem 1.3.11 on page 78 of your book. Name the file and program
ch1sec3prob11.java
. Worth 10pts. Do not output any values of2^N
. When usingMath.log(N)
immediately cast down to anint
type.
Examples:-
Input: $ java ch1sec3prob11
Output: log N N N log N N^2 N^3 2 16 32 256 4096 3 32 96 1024 32768 4 64 256 4096 262144 4 128 512 16384 2097152 5 256 1280 65536 16777216 6 512 3072 262144 134217728 6 1024 6144 1048576 1073741824 7 2048 14336 4194304 8589934592
-
-
Problem 1.3.27 on page 81 of your book. Name the file and program
ch1sec3prob27.java
. Worth 20pts. TakeN
as a command-line argument.
Examples:-
Input: $ java ch1sec3prob27 4
Output: * *
* *
* *
* * -
Input: $ java ch1sec3prob27 5
Output: * *
* * *
* *
* * *
* *
-
-
Write a program which takes a single
String
(no spaces) from standard input. First, your program should remove all duplicate letters (Hint: usesubstring()
to decompose a string and concatenation to recompose it). Second, your program should reverse the String (Hint: convert theString
to achar[]
withtoCharArray()
). Last, output the modified string. Name the file and programch1sec4prob00.java
. Worth 30pts. You cannot use the Java class/utilityStringBuilder
. Also note that'e'
is NOT a duplicate of'E'
.
Examples:-
Input: $ java ch1sec4prob00
Output: (user enters string after prompt...) Enter a string without spaces: Hello
oleH -
Input: $ java ch1sec4prob00
Output: (user enters string after prompt...) Enter a string without spaces: elephAntwalk
kawtnAhple
-
-
Problem 1.4.30 on page 118 of your book. Name the file and program
ch1sec4prob30.java
. Worth 40pts. TakeM
,N
, andp
as command-line arguments in that order. Hint: you only need a single multidimensional array of booleans to solve this problem, the output is analysis of those booleans.
Examples:-
Input: $ java ch1sec4prob30 3 5 0.2
Output: .*.*.
.....
**...
1*2*1
33311
**100 -
Input: $ java ch1sec4prob30 8 3 0.5
Output: ***
**.
...
.**
.**
...
...
.*.
***
**3
343
2**
2**
122
111
1*1
-
-
Bonus. Problem 1.5.19 on page 157 of your book.
Worth 10 pts. However, each way you improve the solution beyond the basic
specification will earn you more points. Be sure to write comments in your
program about how it is improved. Ideas include animating the drawing of the
lines infinitely, making the lines have an artistic coloring, or allowing
keyboard input to alter the probability p. Name your file and program
ch1sec5prob19bonus.java
.
Examples:-
Input: $ java ch1sec5prob19bonus 20 .33
Output:
-
Grading
Each assignment is graded out of 100% based on a combination of the criteria listed in the assignment description and programming style (e.g., good comments and naming) -- following instructions is extremely important in computer science, train yourself to think like the computer; programming style is important to be able to communicate your solutions to another programmer; both of which you are graded upon.
Specific instructions. Failure to do these steps will result in a loss of points.
- Name each file and program as listed in the instructions.
- Name all variables descriptively.
- Indent all programs appropriately.
- Use comments to help explain the steps and logic of your program.
- The top of your program should have a comment block where the first line
is your name, second line is your section, and third line is a description
of your java program.
//Name: Jory Denny
//Section: 00
//This program debates Batman vs Superman!
Turn in instructions. Each programming assignment is to be turned in before your lab section. You will turn in a soft copy of the assignment (.java or .zip for multiple java files) through blackboard. You will also turn in a hard copy of the assignment in your lab section with a signed coverpage (each program should start a new page of the hard copy).
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).