Question
When submitting this code I get the following error: Compile errors: Test.java:7: error: constructor PGM in class PGM cannot be applied to given types; PGM
When submitting this code I get the following error: Compile errors:
Test.java:7: error: constructor PGM in class PGM cannot be applied to given types; PGM pg = new PGM(); ^ required: String found: no arguments reason: actual and formal argument lists differ in length 1 error
can someon help? The code is below
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class PGM extends Image
{
private int maxColor;
private int[][] image;
public PGM(String file) throws IOException
{
FileReader fr = new FileReader(file);
Scanner sc = new Scanner(fr);
setMagic(sc.nextLine());
setWidth(sc.nextInt());
setHeight(sc.nextInt());
maxColor = sc.nextInt();
image = new int[getHeight()][getWidth()];
for(int i = 0; i < getHeight(); i++)
{
for(int j = 0; j < getWidth(); j++)
{
image[i][j] = sc.nextInt();
}
}
sc.close();
fr.close();
}
public String getMagic() {
return magic;
}
public void setMagic(String magic) {
this.magic = magic;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public int getDepth() {
return depth;
}
public void setDepth(int depth) {
this.depth = depth;
}
@Override
public void flip_horizontally() {
for(int i = 0; i < getHeight(); i++)
{
for(int j = 0; j < getWidth()/2; j++)
{
int temp = image[i][j];
image[i][j] = image[i][getWidth() - 1 -j];
image[i][getWidth() - 1 -j] = temp;
}
}
}
@Override
public void flip_vertically() {
// TODO Auto-generated method stub
for(int i = 0; i < getHeight()/2; i++)
{
for(int j = 0; j < getWidth(); j++)
{
int temp = image[i][j];
image[i][j] = image[getHeight() - 1 -i][j];
image[getHeight() - 1 -i][j] = temp;
}
}
}
@Override
public void rotate_right_90() {
int [][] tempImage = new int[getWidth()][getHeight()];
final int M = getWidth();
final int N = getHeight();
for (int r = 0; r < M; r++) {
for (int c = 0; c < N; c++) {
tempImage[c][M-1-r] = tempImage[r][c];
}
}
image = tempImage;
setWidth(N);
setHeight(M);;
}
public void save(String file) throws IOException
{
FileWriter fw = new FileWriter(file);
fw.write(getMagic() + " ");
fw.write(getWidth() + " " + getHeight() + " ");
fw.write(maxColor + " ");
for(int i = 0; i < getHeight(); i++)
{
for(int j = 0; j < getWidth(); j++)
{
fw.write(image[i][j] + " ");
}
fw.write(" ");
}
fw.close();
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started