HI all,
I am working on a program that will print out my initials 'A' and 'T' using arrays. I am asked to initialize the first intial to '*' and the second intial to '@'. I wrote the code but the output is wrong. Can someone help me by letting me know what I am doing wrong in my arrray?I just get back my array of 30X30. I also wrote a driver but when I run the program, I really appreciate it so much.
public class Initial
{
private char whichinitial ;
private int MAX =30;//Maximum amount for 2-d Matrix
char[][] letterMatrix = new char[MAX][MAX];//2-d Array 30 x30
private boolean first = true;
public Initial()
{ //FIlls Array full of '*'s
whichinitial = '*';
for(int i=0;i< MAX;i++)
for(int j=0;i< MAX;i++)
letterMatrix[i][j] = whichinitial;
}
public void setLetter(char letter)
{//Setter for Letter
whichinitial = letter;
}
public char getLetter()
{//Getter for Letter
return whichinitial;
}
public void firstLetter()
{ //Creates an A shape
for(int i=0;i< MAX;i++)
{
for(int j=0;j< MAX;j++)
{
if((i>0)|| ((i<6) || ((j>0) && (j<29))))
{
letterMatrix[j] =whichinitial;
}
}
}
}
public void secondLetter()
{//Creates an T shape
first = false;
for(int i=0;i <MAX;i++)
{
for(int j=0;j <MAX;j++)
{
if((i>1) ||(j < 29)||(j>5)||(i>10))
{
letterMatrix[i][j] = whichinitial;
}
}
}
}
public void display()
{//Displays the Initials
if(first)
{
System.out.println("\n \n \n My First Initial," + whichinitial + ", follows:");
}
else
{
System.out.println("\n \n \n My Last Initial," + whichinitial + ", follows:");
}
for(int i=0;i <MAX;i++)
{
System.out.println();
for(int j=0;j <MAX;j++)
{
if(letterMatrix[i][j] == '*')
{
System.out.print(" ");
}
else
{
System.out.print(letterMatrix[i][j]);
}
}
}
}
}