Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help getting this Java code to compile and run: public class Fence { publ

ID: 3607295 • Letter: I

Question

I need help getting this Java code to compile and run:


public class Fence {
public static void main(String[] args) {

import java.util.Scanner;

public static int fenceCount;

private int height;

private int width;

public Fence()

{


this.fenceCount=0;

this.height=0;

this.width=0;

}

public Fence(int ht, int wt)

{

setHeight(ht);

setWidth(wt);

}

public int getHeight() {

return height;

}

public void setHeight(int height) {

this.height = height;

}

public int getWidth() {

return width;

}

public void setWidth(int width) {

this.width=width;

}

public static int getFenceCount()

{

return fenceCount;

}

public void draw()

{

fenceCount++;

for(int i=1;i<=height;i++)

{

for(int j=1; j<=width;j++)

{

if(i==1||i==height)

{

System.out.print("#");

}

else if(j==1||j==width)

{

System.out.print("#");

}

else{

System.out.print("|");

}

}

System.out.println(" ");

}

}
}

Explanation / Answer

import java.util.Scanner;
import java.util.*;
public class Fence {
public static int fenceCount;

private int height;

private int width;

public Fence()

{


this.fenceCount=0;

this.height=0;

this.width=0;

}

public Fence(int ht, int wt)

{

setHeight(ht);

setWidth(wt);

}

public int getHeight() {

return height;

}

public void setHeight(int height) {

this.height = height;

}

public int getWidth() {

return width;

}

public void setWidth(int width) {

this.width=width;

}

public static int getFenceCount()

{

return fenceCount;

}

public void draw()

{

fenceCount++;

for(int i=1;i<=height;i++)

{

for(int j=1; j<=width;j++)

{

if(i==1||i==height)

{

System.out.print("#");

}

else if(j==1||j==width)

{

System.out.print("#");

}

else{

System.out.print("|");

}

}

System.out.println(" ");

}
}
public static void main(String[] args) {


}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote