Please, make sure that you have added the honor code statement at the top of your Java file:
/* THIS CODE IS MY OWN WORK, IT WAS WRITTEN WITHOUT CONSULTING CODE WRITTEN BY OTHER STUDENTS. _Your_Name_Here_ */ |
The deadline for completing this lab assignment is midnight, today.
mkdir ~/cs170/lab7
cp ~cs170002/share/lab7/* ~/cs170/lab7
cd ~/cs170/lab7
|
In this lab, we will use gedit and javac (not BlueJ !).
(You could use BlueJ, but you must figure out how to compile and run the program on your own.)
gedit Sample.java &
|
|
/* ===============================================================
How to use indentCharLine() to draw a square:
printSquare(i, c, n):
Prints out a square - indented by i spaces -
of height and width equal to n, using character c
=============================================================== */
public static void printSquare(int i, char c, int n)
{
int row, col;
/* -----------------------------------------
Print n rows of character c of width n
----------------------------------------- */
for ( row = 0; row < n; row++ )
{
indentCharLine(i, c, n);
}
}
|
public static void main(String[] args)
{
printSquare(4, 'O', 2);
System.out.println();
printSquare(4, 'X', 3);
}
|
javac Sample.java
java Sample
|
gedit AsciiArt.java & |
/* ================================================================
TODO: write this method
printColumn(i, w, h, c):
Prints out a column - indented by i positions-
of width w and heigh h.
The character used to print is passed as a parameter to
the method by the variable c.
*** NOTE: This method uses the "indentCharLine" method inside.
================================================================ */
public static void printColumn(int i, int w, int h, char c)
{
...
}
|
javac AsciiArt.java
java AsciiArt
|
and if correct, you should see this output:
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
|
(You don't need to do this if the program AsciiArt.java is still open in the gedit window):
gedit AsciiArt.java & |
/* ================================================================
TODO: write this method
printTriangle(h, c):
Prints out a triangle with heigh equals to h using char c
Example:
printTriangle(3, 'A'):
A
AAA
AAAAA
*** NOTE: This method uses the "indentCharLine" method inside.
================================================================ */
public static void printTriangle(int h, char c)
{
....
}
|
(Hint: how many lines does it print ? How many characters does it print on line i ? How many spaces does it indent on line i ?
Write a for-loop using the answer of the above questions.)
javac AsciiArt.java
java AsciiArt
|
and if correct, you should see this output:
A
AAA
AAAAA
AAAAAAA
AAAAAAAAA
AAAAAAAAAAA
AAAAAAAAAAAAA
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
|
cd ~/cs170/lab7 /home/cs170002/turnin-lab AsciiArt.java lab7 |
before midnight today.
For the Lead TA:
|