![]() |
JR's HomePage |
Java Home | Site Map |
Page Bottom Short Problems | Unix-like Tools | Command Interpreter FlatFile Reporter | File Conversion | WebProjects |
Java Projects
This page offers some short review problems for student study as well as non-GUI Java projects that I have developed or modified. Most have source code that has been compiled, tested and documented. Feel free to download and adapt the code to your own needs. Feedback on usefulness, bugs detected and enhancements is appreciated.
Some projects remain undeveloped and are marked as pending. If you are interested in obtaining the current code for any of the pending projects, looking at what I am doing or pushing me to complete a specific project, please use the button at the bottom of the page. You can also check my web developer projects page for more stuff.
| Some Short Projects Covered in Tutorials | |||
|---|---|---|---|
| Basic Problems Metric Converter |
Circle Class NameReader |
Longest Line TextIO Class |
GUI Case Studies WebFile Grabber |
Short Problems
Here are a few problems that involve passing object references as parameters. You may want to review the tutorial on arrays, the new operator and assigning variable values. Keyboard input requires the file io class. Formatted numeric output requires the DecimalFormat class
- Write a program that allows you to input 10 numbers into an array. Then create a method that will return and print the average, sum, smallest value, largest value and printout those below the average and values above average.
- Write a program that creates the following methods
[Assume that your array has 10 elements]:
A). A method to input the content of an array. B). A method to return the sum. C). A method to return the average D). A method to return the average of negative numbers. E). A method to return the average of positive numbers. F). A method to return the average, smallest and largest.
- Write a program that asks the user to enter any number of grades (such as A, B, C, D, or F). Remember to uppercase and validate input. It should then call a method that calculates and displays the GPA for the list of grades using the scale A=4.0, B=3.0, C=2.0, D=1.0 and F=0.0. The program should provide clear instructions to the console and also display the original list of grades entered by the user.
- Write a program that searches a 2D array and returns the largest number from each row [Assume 6 rows and 4 columns] by building single dimension row objects and then finding the largest(row_obj).
- Write a method to interchange any two rows of a two-dimensional array passed to it.
- Write a method to determine if a two-dimensional array passed to it is symmetric, that is A[i][j]==A[j][i] for all valid i and j.
- Write a method to transpose a matrix, that is the method should make rows into columns, and vice-versa.
- Write a method to multiply two conformable matrices. Use your method to find the product P=M x M x M for the matrix M given by {{4,9,2},{3,5,7},{8,1,6}}
- Write a program that allows you fill a tabulated 3x3 matrix with random numbers range from 0 to 50. Write a method that will display a message BINGO if the array element has at least 2 numbers divisible by 5.
- Write a program that generates a random North American style phone number. These consist of 3 digit area code, 3 digit exchange code, and 4 digit user number. Area and exchange codes can't begin with a 0 or 1.
Unix-like Tools
Unix-like tools are command line utilities for text-based systems that do simple tasks using standard io streams which can be piped or chained together to accomplish more complex operations. For examples of Unix philosophy modular system, look at FlatFile Inventory Reporter and CipherTools. Cloning the original Unix toolbox makes a great set of problems for non-gui Java tutorial review. Tools and filters that I find most useful are implemented here.
The detab filter changes tab characters into spaces. Switches are: /# for # of spaces to use and /i(nform only).
include scans files looking for lines containing #include filename markers. These markers are then removed and the contents of filename is inserted in the scanned file. The command line argument of include can contain filename globs like * and ?. Switches are: /i(ncluded file folder), /o(utput folder) and /x(tension name for output filename). include is a useful tool for adding boiler plate copy to multiple web pages but suffers from the requirement of source and destination folders. Check out includers for possible alternative utilities.
The justify filter trims and right or left justifies lines. Switches are /l|/r line_length [filler_char].
pr is a print formatter that makes files into pages with headers, offsets and other prettyPrint stuff. It also overcomes the problem of the java \f formfeed not working with many printers. Switches are: /d (double space) /lines=n (lines per page [default 55]), /head=n (lines used as heading [default 0]) /offset=n (left margin indent [default 0]) and /title="string" (one line title [default none]).
spell is a system of piped filters. tr [lowercase] | tr [space to newlines | sort | uniq pending
tar packages/unpackages files into a single block for archiving or distribution. This guarantees that all project files are delivered in a single bundle. No compression is applied. This project uses a trivial token file marker (*** <name>). Switches are: /create | /delete | /title | /update | /xtract. One enhancement is to use a whitelist to add or extract files.
touch updates the last_modified field of all files in the current directory to the current date. This overcomes a flaw in XP that sometimes deletes older files without informing the user. Programmers can also use touch to make sure libraries are recompiled with the latest version of the compiler.
tr transliterates characters. Simple uses are to lowercase, remove or change spaces into newlines. pending
uniq reduces duplicate lines to single instances. pending
wc counts the number of lines, words and characters in a file. Words are delimited by whitespace. Switches: /l (show only line count), /w (show only word count), /c (show only character count).
head | tail display the first or last number of lines in a file.
Command Line Interpreter
cli is a generic argument option|switch handling routine that is as user tolerant as possible regarding pathnames (including glob expansions for batch runs), options|switches and parameters. include, pr, tar and wc are examples of utilities using cli. Design requirements are:
- Returns argument error flag
- Options|switches are indicated by either - or / characters
- Valid options|switches can set flags
- Option|switch names can be any length
- Option|switch names can contain name=param format
- Order of switches, pathnames and parameters is flexible
UNIX-centric options are arguments with a prefix of - (dash). By custom they precede pathnames in the command line. Options are often a single character but sometimes are a number or followed by a number. Examples of command line options are:
pr -d *.htm ; print double spacing lines head -10 *.htm ; show first 10 lines head -c 10 *.htm ; show first 10 characters
msDOS-centric switches are arguments with a prefix of / (slash). They normally toggle boolean flags but can be found in many variations such as a following argument qualifier or a parsing situation. Depending on program, they may precede or follow file arguments. Examples are:
find /p fred *.htm ;page pause requested progname /help ;help or man page requested format /head=4. *.htm ;include 4 lines of header space print -lines 45 *.htm ;print first 45 lines of file(s)
FlatFile Reporter
FlatFile Inventory Reporter scans tab delimited files created by a spreadsheet and produces both raw item quantity reports and item location reports. The design approach for the project is modular (Unix-like) in that several utilities are chained together rather than the msDOS technique of one big hack. No GUI is needed in this project as a batch file ties the modules together with appropriate system utilities. The working example provides canada.bat, ca1.txt, etc, where each file is a stamp album, each column is a page, and each entry is a catalog (aka inventory) number. I use this system to track stamps for my club circuit books.
todb reads a flat file line by line and parses each column by tab delimiter. The first row of the file is assumed to be a heading line with associated location markers. The data items have file/column markers appended for later tracking purposes. Each enhanced data item is then output to a intermediate file on a single entry per line basis. System utilities are then used to merge intermediate files and sort the resulting combined file.
tocount makes a report of the number of occurrences of each item. This is useful in spotting inventory items that are low or out of stock as well as those overstocked. It also makes an intermediate item count file for spotting worst overstock items.
tofind makes a report of items with x or fewer occupancies plus the first y locations. If more than x items of a specific catalog number are available, it is assumed that they can be found in the traditional 'bible' (aka seek and ye shall find) method.
File Conversion
Data file records are normally formatted in one of three structures: character (eg space, tab or comma) delimited fields; fixed column fields; and tagged field with each line being a separate field prefaced with its field tag. One expandible, adaptable format is illustrated by the Cabrillo structure which has a leading instruction tag followed by variable fields defined by that tag.
Files may require field resizing, removal or rearrangement. Headings or field items may need replacement, case changes, date or number formatting etc. Tag formatted files often require conversion to fixed column format for reports.
jawk, an extended Java clone of the unix awk (gnu gawk) filter can handle each structure. Character delimited files are handled by default. Fixed length fields can be parsed with the sprintf function.
At present I have found no need for a Java utility for data file conversion. If you have a particular need please contact me and I will see if jawk can handle it. If not then a new java project will be defined as pending eh!
Java Projects Source Code
Obtain source for detab, head, include, pr, tail, tar, touch, wc, cli, tocount, todb, tofind, etc. here.
