The objective of this program is to create images or shapes by using 2day arrays. I've created the the maximum size in my constructor but my error is in the the rectangle method.This is my error:
Hw11.java:60: cannot find symbol
symbol : constructor Picture(char[][])
location: class Picture
return new Picture(result);
^
Please help!!!
import java.io.*;
import java.util.Scanner;
////////////////////////////////////////////////////////////////////////////////
class Hw11
{
//------------------------------------------------------------------------------
public static void main (String [] args) throws Exception
{
Scanner kb = new Scanner(System.in);
Picture s = Picture.read(System.out,kb);
Picture s1 = s.rectangle(3,8,4,6,'0');
System.out.println("You entered the MyString \"" + s + "\".");
//System.out.println(s1);
}
//------------------------------------------------------------------------------
} // end class Prog1406
////////////////////////////////////////////////////////////////////////////////
class Picture
{
private int rmax;
private int cmax;
private char background;
private char [][]a;
//------------------------------------------------------------------------------
public Picture(int rmax, int cmax, char background)
{
this.rmax = rmax;
this.cmax = cmax;
this.background = background;
a = new char[rmax][cmax];
for(int row = 0; row<rmax; row++)
{
for(int col = 0; col<cmax;col++)
{
a[row][col]= background;
System.out.print(a[row][col]);
}
System.out.println();
}
}
//------------------------------------------------------------------------------
public Picture rectangle(int rlo,int rhi, int clo,int chi, char color)
{
char[][] result = new char[a.length][a.length];
for(int row = 0; row<rmax; row++)
{
for(int col = 0; col<cmax;col++)
{
if(row>= rlo&&row <=rhi){result[row][col]= color;}
if(col>= clo&& row<=chi){result[row][col] = color;}
System.out.print(result[row][col]);
}
System.out.println();
}
return new Picture(result);//this where my error is at
}
//------------------------------------------------------------------------------
public String toString();
{
String result ="";
for(int row = 0; row<rmax; row++)
{
for(int col= 0; col<cmax; col++)
{
result+=a[row][col];
}
}
return result;
}
//------------------------------------------------------------------------------
public static Picture read(PrintStream ps, Scanner sc)
{
if(ps!=null) ps.print("Enter the maximum # of rows:");
int rmax = sc.nextInt();
if(ps!=null) ps.print("Enter the maximum # of columns:");
int cmax = sc.nextInt();
if(ps!=null) ps.print("Enter the background:");
String background = sc.next();
return new Picture(rmax,cmax,background.charAt(0));
}
//------------------------------------------------------------------------------
}