Docsity

UNIX Programming Assignment 7: Recursive Java Programs with Command Line Arguments - Prof., Assignments of Information Technology

Toggle sidebar
bg1
ITK 179
Fall, 2005
Califf
Programming Assignment 7
UNIX, Command Lines, and Recursion
Program Due Date: Friday, November 11, 2005 at the beginning of class
Objective: Write Java programs in a UNIX environment. Practice using command line
parameters and writing recursive methods.
For this programming assignment, you’re going to write 3 different small recursive programs.
You are to submit these programs on the Suns. Each of the programs will use command line
parameters.
Problem 1 – Reverse a String (10 points)
Write a program that uses a recursive method to print the reverse of a String. Read the string to
be reversed from the command line. Your main method should be in a class named Reverse.
Problem 2 – Sum Digits (20 points)
Solve problem 6 on page 395 of your text. Read the numbers from the command line. The first
argument will be the desired sum. Your main method should be in a class named Sum.
Problem 3 – Base Conversion (15 points)
One algorithm for converting a base 10 number to base b involves repeated division by the base
b. Initially one divides the number by b. The remainder from this division is the units digit (the
rightmost digit) in the base b representation of the number (it is the part of the number that
contains no powers of b). The quotient is then divided by b on the next iteration. The remainder
from this division gives the next base b digit from the right. The quotient from this division is
used in the next iteration. The algorithm stops when the quotient is 0. Note that at each iteration
the remainder from the division is the next base b digit from the right—that is, this algorithm
finds the digits for the base b number in reverse order.
Here is an example for converting 30 to base 4:
quotient remainder
-------- ---------
30/4 = 7 2
7/4 = 1 3
1/4 = 0 1
The answer is read bottom to top in the remainder column, so 30 (base 10) = 132 (base 4).
Think about how this is recursive in nature: If you want to convert x (30 in our example) to base
b (4 in our example), the rightmost digit is the remainder x % b. To get the rest of the digits, you
perform the same process on what is left; that is, you convert the quotient x / b to base b. If x / b
is 0, there is no rest; x is a single base b digit and that digit is x % b (which also is just x).
pf3
pf4

Partial preview of the text

Download UNIX Programming Assignment 7: Recursive Java Programs with Command Line Arguments - Prof. and more Assignments Information Technology in PDF only on Docsity!

ITK 179 Fall, 2005 Califf

Programming Assignment 7

UNIX, Command Lines, and Recursion

Program Due Date: Friday, November 11, 2005 at the beginning of class Objective: Write Java programs in a UNIX environment. Practice using command line parameters and writing recursive methods. For this programming assignment, you’re going to write 3 different small recursive programs. You are to submit these programs on the Suns. Each of the programs will use command line parameters. Problem 1 – Reverse a String (10 points) Write a program that uses a recursive method to print the reverse of a String. Read the string to be reversed from the command line. Your main method should be in a class named Reverse. Problem 2 – Sum Digits (20 points) Solve problem 6 on page 395 of your text. Read the numbers from the command line. The first argument will be the desired sum. Your main method should be in a class named Sum. Problem 3 – Base Conversion (15 points) One algorithm for converting a base 10 number to base b involves repeated division by the base b. Initially one divides the number by b. The remainder from this division is the units digit (the rightmost digit) in the base b representation of the number (it is the part of the number that contains no powers of b). The quotient is then divided by b on the next iteration. The remainder from this division gives the next base b digit from the right. The quotient from this division is used in the next iteration. The algorithm stops when the quotient is 0. Note that at each iteration the remainder from the division is the next base b digit from the right—that is, this algorithm finds the digits for the base b number in reverse order. Here is an example for converting 30 to base 4: quotient remainder


30/4 = 7 2 7/4 = 1 3 1/4 = 0 1 The answer is read bottom to top in the remainder column, so 30 (base 10) = 132 (base 4). Think about how this is recursive in nature: If you want to convert x (30 in our example) to base b (4 in our example), the rightmost digit is the remainder x % b. To get the rest of the digits, you perform the same process on what is left; that is, you convert the quotient x / b to base b. If x / b is 0, there is no rest; x is a single base b digit and that digit is x % b (which also is just x).

Write a program that uses a recursive method to convert an integer to another base. The integer and the base should be command line arguments to the program. The program should print the original number, the base, and the new representation to the screen. Your main method should be in a class name Converter. Extra credit (worth up to 15 points): Do problem 9 on page 396 of your text. Print out the ASCII board representing the result. Requirements  Tar all of your files and name the resulting file prog7.tar.  Electronically submit the file prog6.tar on the Suns following the directions from your UNIX handout.  Turn in a printout of the final version of your source code that exactly matches files you submitted.  The program must follow the coding guidelines.  The program should be well commented  The program is worth 45 points.

Grading Standards A perfect program will: Run correctly, meeting all specifications from the assignment Will show all output in the proper format (neatly spaced, money with 2 decimals, etc) Use good structured and object-oriented programming Handle files correctly (opening, closing, correct reading loops, etc.) Have correct and complete design materials Be correctly formatted with clear indentation Be well commented, following the coding guidelines for this class Be submitted correctly, both electronically and on paper (in a pocket folder, with grade sheet and all required materials, etc.) An ‘A’ program: Will run correctly, meeting all specifications from the assignment Will show all output in the proper format (neatly spaced, money with 2 decimals, etc) Will use good structured and object-oriented programming Will handle files correctly (opening, closing, correct reading loops, etc.) May have no more than two minor errors in design, format, or submission A ‘B’ program: Will run correctly on any sample data Will use good structured and object-oriented programming Will handle files correctly (opening, closing, correct reading loops, etc.) May have minor errors in execution on alternate data or more than 2 minor errors in design, format, and/or submission or a single major error on alternate data A ‘C’ program: Will compile and run May have multiple minor errors or errors in multiple areas or up to 2 major errors A ‘D’ program Will compile and run Has serious errors in execution and/or design An ‘F’ program Does not compile or does not run or seriously lacks design materials or substantially fails to follow the assignment guidelines or has a number of errors of different kinds