it needs to run into Java only. The Initials Class Objectives . Type in a simple
ID: 3875224 • Letter: I
Question
it needs to run into Java only.
The Initials Class Objectives . Type in a simple Java program and execute it. . Use System.out.println. . Copy the output of the program to a file. . Submit a lab folder to Blackboard. Hand-in Requirements All projects and laboratories will be submitted electronically through Blackboard. Zip u (zipped) Folder (or 7-Zip> Add to "labO.zip")) The lab folder should include the following up your entire lab folder to submit as the source. (Right click on the lab folder and follow Send To - Compressed Initials.java InitialsOutput.txt Details Write a program to print a header followed by your initials in block letters like the following 0 written by YOURNAME xXY zzzzzz2 Of course you should substitute YOURNAME with your name. If you only have 2 initials, use Q as your middle initial. Your program should consists of several System.out.println statements, one for each line Include the output of your program in a file named Initielsoutput.txt. In DrJava, one way to do this is to copy-and-paste the text from the Interactions pane to a simple text editor such as Notepad Another way to do this is to right-click in the Interactions pane and select "Save Copy of Interactions" In either case, save the file in your lab folder Rubric Your program should compile without any errors A program with more than one or two compile errors will likely get a zero for the whole assignmentExplanation / Answer
// Defines class Pattern
public class Pattern2
{
// main method definition
public static void main(String[] args)
{
// Prints 'X'
// Loops 6 times for row
for(int x = 0; x < 6; x++)
{
// Loops 6 times for column
for(int y = 0; y < 6; y++)
{
/*
* (x + y == 5) for right diagonal
* (x == y) for left diagonal
* x != 2 for not printing duplicate center 'X' value
*/
if((x + y == 5) || (x == y) && x != 2)
System.out.print("X ");
// Otherwise print space
else
System.out.print(" ");
}// End of inner for loop
System.out.println();
}// End of outer for loop
System.out.println();
// Prints 'Y'
// Loops 3 times for row
for(int x = 0; x < 3; x++)
{
// Loops 6 times for column
for(int y = 0; y < 6; y++)
{
/*
* (x + y == 5) for right diagonal
* (x == y) for left diagonal
* x != 2 for not printing duplicate center 'Y' value
*/
if((x + y == 5) || (x == y) && x != 3)
System.out.print("Y ");
// Otherwise print space
else
System.out.print(" ");
}// End of inner for loop
System.out.println();
}// End of outer for loop
// To print center 'Y' only
// Loops 3 times for row
for(int x = 0; x < 4; x++)
{
// Loops 3 times for column
for(int y = 0; y < 3; y++)
System.out.print(" ");
System.out.println("Y ");
//System.out.println();
}// End of for loop
System.out.println();
// Prints 'Z'
// Loops 6 times for row
for(int x = 0; x < 6; x++)
{
// Loops 6 times for column
for(int y = 0; y < 6; y++)
{
/*
* (x == 0) for first row
* (x == 5) for last row
* (x + y == 5) for right diagonal
*/
if((x == 0) || (x == 5) || (x + y == 5))
System.out.print("Z");
// Otherwise print space
else
System.out.print(" ");
}// End of inner for loop
System.out.println();
}// End of outer for loop
}// End of main method
}// End of class
Sample Run:
X X
X X
X
X X
X X
X X
Y Y
Y Y
Y Y
Y
Y
Y
Y
ZZZZZZ
Z
Z
Z
Z
ZZZZZZ
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.