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

How would I solve this? It is from Starting out with Java 3rd edtiion. Using Jav

ID: 3725276 • Letter: H

Question

How would I solve this? It is from Starting out with Java 3rd edtiion.

Using JavaFX, Write a program that takes a positive integer n and displays an n x x checkerboard. For example, when n = 5, the program displays as in Figure 15-30. Make sure that adjacent squares differ in color regardles of whether n is odd or even. Write the program in such a way that it works for different values of n by changing only one line in your code. Hint: Use un-editable TextField objects in a GridPane, and use CSS to set background colors.

way that it workS IU un-editable TextField objects in a Gridpane, and use CSS re 15-30 Checkerboard (Mark Schrier. Copyright Oracle. Inc Checkr...

Explanation / Answer

import java.swing.*;
import java.awt.*;

public class checkerboard extends JFrame
{
  int n; int x;int y;
  public checkerboard(int p)
  {
   n=p; x=0;y=0;
  }

public void paint(Graphics g)
{
  
  for(int i=0;i<n;i++)
  {
   for(int j=0;j<n-1;j++)
   {
   x=j*22; y=i*22;
   if((i%2)==(j%2))
   g.setColor(Color.WHITE);
   else
   g.setColor(Color.BLACK);

  
   g.fillRect(x,y,22,22);
   }

  }


}


public static void main(String args[])
{
   // USER CAN INPT THE SIZE OF BOARD HERE AND

PASS IT AS ARGUMENT TO THE CONSTRUCTOR
   checkerboard ch=new checkerboard(4);
   ch.setTitle("CheckerBoard");
   ch.setSize(180,200);
   ch.setDefaultCloseOperation(EXIT_ON_CLOSE);
   ch.setVisible(true);


}


}

}

}

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