Homework 3 : Grid
CMP12a Winter 2002
Thomas Raffill
Due on the evening of Monday, April 15 by midnight.
Note: This assignment is graded, so do your best on it.
Introduction
This program will print out a simple text box like
homework 2., but the box will be in the form of a grid.
The class name is Grid, so
your Java source file name will be Grid.java and your class file name will
be Grid.class.
Input
Number of columns, number of rows. Input will be by
command-line arguments.
You don't need to validate the input! In other words, you
can assume the program will always be run with two command line
arguments which are positive integers.
Output
A rectangular grid of the given dimensions marked off with dots(.),
underscores(_), and pipes(|).
A simple 1 x 1 unit box looks like this:
._.
| |
._.
Your program should draw a grid with as many boxes across as
the number of columns, and as many boxes down as the number
of rows, where the number of columns and number of rows
come from the command line input.
The output will be to standard output.
Several examples of sample input and output
- Input: (At the command line)
java Grid 3 2
Output:
._._._.
| | | |
._._._.
| | | |
._._._.
- Input: java Grid 3 3
Output:
._._._.
| | | |
._._._.
| | | |
._._._.
| | | |
._._._.
- Input: java Grid 5 2
Output:
._._._._._.
| | | | | |
._._._._._.
| | | | | |
._._._._._.
Skeleton code
This is skeleton code for starting your program.
/* Homework 3
* Grid.java
*
* Author : Sung Kim <hunkim@cse>
*/
class Grid {
public static void main (String[] args) {
// Process command-line arguments
// Print text box
}
}
Note
- Start early. Read the newsgroup.
- Do your own work. Don't submit other people's code.
- You don't need to validate input values.
- Use nested loops to print the box.
- Be careful about the input numbers and the box shape.
- Think about the input numbers and loop counter.
- Think about the each position and character pattern.
- Think about the special cases for the edges of the grid.
To Submit Homework
- You only need to submit your source code. DON'T submit other files except your source code. When submitting homework, use the following form (when
logged on to your cats account):
submit cmps012a-tr.s02 hw3 Grid.java
submit is the script on cats you use to turn in your
homework.
cmps012a-tr.s02 is the class locker for this class.
hw3 is for homework 3. This designation will be hwn where n is the
number of the homework assignment.
Grid.java is the source file name.
To Check Homework
peek cmps012a-tr.s02 hw3
Questions ?
- Use the newsgroup ucsc.class.cmps012a.
- Attend labs and office hours.
- Send an email to the instructor or TA.