please help me with the following
1) make a sierpenski triangle using java and recursion. Make it similar to the code below. And please comment the code
2) Please make the follow code out put on the console. It a t square fractal
import java.awt.image.*;
import java.awt.Color;
import java.io.*;
import javax.imageio.*;
public class Main
{
static final int DIMENSION = 1000;
static BufferedImage image = new BufferedImage(DIMENSION, DIMENSION, BufferedImage.TYPE_INT_RGB);
static final int WHITE = Color.WHITE.getRGB();
static final int BLACK = Color.BLACK.getRGB();
private static void drawSquare(int x, int y, int side)
{
if (side <= 0)
return;
else
{
int left = x - side/2;
int top = y - side/2;
int right = x + side/2;
int bottom = y + side/2;
for (int i = left; i < right; i++)
for (int j = top; j < bottom; j++)
{
image.setRGB(i, j, BLACK);
}
drawSquare(left, top, side/2);
drawSquare(left, bottom, side/2);
drawSquare(right, top, side/2);
drawSquare(right, bottom, side/2);
}
}
public static void main (String[] args) throws IOException
{
for (int i = 0; i < DIMENSION; i++)
for (int j = 0; j < DIMENSION; j++)
{
image.setRGB(i, j, WHITE);
}
drawSquare(DIMENSION/2, DIMENSION/2, DIMENSION/2);
File imagefile = new File("tfractal.jpg");
ImageIO.write(image, "jpg", imagefile);
}
}
Step by stepSolved in 3 steps with 2 images
- Change Java code below so that it outputs a 9x9 board and not a 3x3 board. import java.util.*; public class Tic_Tac_Toe{ static String[] board;static String turn;static String checkWinner(){for (int a = 0; a < 8; a++) {String line = null; switch (a) {case 0:line = board[0] + board[1] + board[2];break;case 1:line = board[3] + board[4] + board[5];break;case 2:line = board[6] + board[7] + board[8];break;case 3:line = board[0] + board[3] + board[6];break;case 4:line = board[1] + board[4] + board[7];break;case 5:line = board[2] + board[5] + board[8];break;case 6:line = board[0] + board[4] + board[8];break;case 7:line = board[2] + board[4] + board[6];break;}//For X winnerif (line.equals("XXX")) {return "X";} // For O winnerelse if (line.equals("OOO")) {return "O";}} for (int a = 0; a < 9; a++) {if (Arrays.asList(board).contains(String.valueOf(a + 1))) {break;}else if (a == 8) {return "draw";}} // To enter the X Or O at the exact place on board.System.out.println(turn + "'s turn; enter…arrow_forwardQUESTION 18 Java uses a hybrid typing system: One system for primitives but everything else is an object. True Falsearrow_forwardUsing the code in the image provided: Implement a method called summation which adds two integers and returns their sum. INPUT: The first line of input contains an integer a. The Second Line of input containes and integer b. OUTPUT: Print the result which is the sum of a and b.arrow_forward
- write a code in java (using recursion)arrow_forwardimport java.util.Scanner; public class LabProgram { // Recursive method to draw the triangle public static void drawTriangle(int baseLength, int currentLength) { if (currentLength <= 0) { return; // Base case: stop when currentLength is 0 or negative } // Calculate the number of spaces needed for formatting int spaces = (baseLength - currentLength) / 2; if (currentLength == baseLength) { // If it's the first line, don't output spaces before the first '*' System.out.println("*".repeat(currentLength) + " "); } else { // Output spaces and asterisks System.out.println(" ".repeat(spaces) + "*".repeat(currentLength) + " "); } // Recursively call drawTriangle with the reduced currentLength drawTriangle(baseLength, currentLength - 2); } public static void drawTriangle(int baseLength) { drawTriangle(baseLength, baseLength); } public static…arrow_forwardFix the code below so that there is a function that calculate the height of the triangle. package recursion; import javax.swing.*;import java.awt.*; /** * Draw a Sierpinski Triangle of a given order on a JPanel. * * */public class SierpinskiPanel extends JPanel { private static final int WIDTH = 810; private static final int HEIGHT = 830; private int order; /** * Construct a new SierpinskiPanel. */ public SierpinskiPanel(int order) { this.order = order; this.setMinimumSize(new Dimension(WIDTH, HEIGHT)); this.setMaximumSize(new Dimension(WIDTH, HEIGHT)); this.setPreferredSize(new Dimension(WIDTH, HEIGHT)); } public static double height(double size) { double h = (size * Math.sqrt(3)) / 2.0; return h; } /** * Draw an inverted triangle at the specified location on this JPanel. * * @param x the x coordinate of the upper left corner of the triangle * @param y the y…arrow_forward
- c) Draw a UML Diagram for the following source code. (CLO1, CLO2) public class MyCircle { double MyRadius= 0.0; MyCircle() { } MyÇircle(double newRadius) { MyRadius = newRadius; } double getArea() { return MyRadius * MyRadius * 3.14159;} public static void main(String[] args) { MyCircle C1 = new MyCircle(); C1 MyRadius = 2.0; MyCircle C2 = new MyCircle(); C2.MyRadius = 4.0; System.out.println(C1.getArea()); System.out println(C2,getArea(); } }arrow_forwardwrite a code in java (using recursion)arrow_forwardwrite a code in java (using recursion)arrow_forward
- Write the implementation of the Java classes based on the following UML diagram. (a) Define the method IncreTotSpecies) to increment the data field totalSpecles (b) Define the method printColor) to print the data field color (c) Override the method printColor) in the class Falcon to print the data fields featherColor, beakColor Birds +color: String +foodHabit: String +totalSpecies: int -skeleton: String +Birds () +Birds(color: String, foodHabit: String, skeleton: String) +increTotSpecies (): void +printColor (): void Falcon -featherColor: String -beakColor: String +Falcon (featherColor: String, beakColor: String) +printColor (): voidarrow_forwardMath 130 Java Programming Does my code pass the requirements? May I have more explanation? Does my code compile correctly? Is my code readable? Is my code well commented? How may I better organize my code? Are there whitespaces to appropriate help separate distinct parts? My code: import java.util.Scanner; public class TicketSale { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); //Prompt user to input the number of Adult tickets to purchase System.out.print("Please enter number of adults:"); //Prompt user to input the number of Adult tickets to purchase int adults = keyboard.nextInt(); //Prompt user to input the number of Children tickets to purchase System.out.print("Please enter number of children:"); //Prompt user to input the number of Children tickets to purchase int children = keyboard.nextInt(); //Calculate and display the total cost for adults and children System.out.print("Your total cost for " + adults +…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education