IN JAVA my code so far public class FramedSquare { public static String printFra
ID: 3756286 • Letter: I
Question
IN JAVA
my code so far
public class FramedSquare {
public static String printFramed(int frameSize, int innerSize) {
//print a square of that has asterisks as a frame and periods as the inner of the square
//start by making the inner square in order to have a base for the frame
for (int f = 0; f < frameSize + innerSize; f++) {
for (int i = 0; i < innerSize; i++) {
System.out.println(x);
}
}
//add the frame around the inner square , adding innerSize to Framesize to account for the inner square
return "yuh"; }
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Begin Testing");
System.out.println("Testing Value (0, 2)");
System.out.println("Expected output below");
System.out.println("..");
System.out.println("..");
System.out.println("Actual output: " + printFramed(0, 2));
System.out.println("Testing Value (2, 0)");
System.out.println("Expected output below");
System.out.println("**");
System.out.println("**");
System.out.println("Actual output: " + printFramed(2, 0));
System.out.println("Testing Value (1, 1)");
System.out.println("Expected output below");
System.out.println("***");
System.out.println("*.*");
System.out.println("***");
System.out.println("Actual output: " + printFramed(1, 1));
System.out.println("Testing Value (2, 2)");
System.out.println("Expected output below");
System.out.println("******");
System.out.println("******");
System.out.println("**..**");
System.out.println("**..**");
System.out.println("******");
System.out.println("******");
System.out.println("Actual output: " + printFramed(2, 2));
System.out.println("Testing Value (3, 3)");
System.out.println("Expected output below");
System.out.println("*********");
System.out.println("*********");
System.out.println("*********");
System.out.println("***...***");
System.out.println("***...***");
System.out.println("***...***");
System.out.println("*********");
System.out.println("*********");
System.out.println("*********");
System.out.println("Actual output: " + printFramed(3, 3));
}
}
Exercise 7.7. Write a class FramedSquare with static method Takes two arguments frameSize and innerSize Draws a square made of asterixes and periods, where - The asterixes form a frame on the outer edge of the squa The inside of the frame is filled in with a innerSize- SoprintFramed (2, 7) would printExplanation / Answer
// I have made a new code for you and tried the test cases which you have provided. It worked fine !
import java.util.Scanner;
public class FramedSquare {
public static void printFrame(int f, int in) {
int i, j, col;
col = (2 * f) + in;
System.out.println("--------------------------------");
// top frame boundary
for (i = 0; i < f; i++) {
for (j = 0; j < col; j++) {
System.out.print("*");
}
System.out.println();
}
int p = 0, countDots = 0, cd = 0;
// internal frame
for (i = 0; i < in; i++) {
p = 0;
countDots = 0;
for (j = 0; j < col; j++) {
if (p < f) {
System.out.print("*");
p++;
} else {
System.out.print(".");
countDots++;
}
if (countDots == in) {
cd = 0;
while (cd < f) {
System.out.print("*");
cd++;
}
break;
}
}
System.out.println();
}
// lower frame boundary
for (i = 0; i < f; i++) {
for (j = 0; j < col; j++) {
System.out.print("*");
}
System.out.println();
}
}
public static void main(String[] args) {
int frameSize, innerSize;
Scanner sp = new Scanner(System.in);
System.out.print("Enter frame size: ");
frameSize = sp.nextInt();
System.out.print("Enter inner size: ");
innerSize = sp.nextInt();
printFrame(frameSize, innerSize);
sp.close();
}
}