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

Following the insturction to make Junit test basic on the code: insturction: Tra

ID: 3797718 • Letter: F

Question

Following the insturction to make Junit test basic on the code:

insturction:

Translate a pixel's row to the associated x-coordinate in the fractal (1 test per fractal) [4 * 5 points = 20 points]

Translate a pixel's column to the associated y-coordinate in the fractal (1 test per fractal) [4 * 5 points = 20 points]

Code:

package edu.ccs;
import javax.swing.*;

public class EscapeTimeAlg extends JFrame {
   //Variables used in Escape Time Algorithm Calculation
private double xCalc, yCalc, Dist;
private int Passes;
//Array that will store all x and y values in the Range
double[][] Frac;
//Array that will store the result of EscapeTime Algorithm
private int[][] Result;
//Constructor class that receives the range of x and y values
public EscapeTimeAlg(double xMin, double xMax, double yMin, double yMax ){
   setSize(513,513);
   setTitle("Fractals");
   setDefaultCloseOperation(1);
//   setVisible(true);
   reset(xMin, xMax, yMin, yMax);
   }
      
public void reset(double xMin, double xMax, double yMin, double yMax ){      
       xCalc = 0;
       yCalc = 0;
       Dist = 0;
       Passes = 0;
      
       double constx = (Math.abs(xMax) + Math.abs(xMin))/ 512;
       double consty = (Math.abs(yMax) + Math.abs(yMin))/ 512;
      
       Frac = new double[2][512];
      
       for(int i = 0; i< 512; i++){
           Frac[0][i] = xMin +(constx * i);
           Frac[1][i] = yMin +(consty * i);
      
           Result = new int[512][512];  
}}  

//Implementation of Mandelbrot sets
public int[][] Mandelbrot(){
   for(int x = 0;x <512;x++){
       xCalc= Frac[0][x];
       double Ox = xCalc;
   for(int y = 0;y <512;y++){
       yCalc= Frac[1][y];
       double Oy = yCalc;
       Dist = Math.sqrt(Math.pow(xCalc, 2) + Math.pow(yCalc, 2));
       Passes =0;
           while(Dist <= 2 && Passes <255)
           {
               double oldx = xCalc;
               xCalc = Math.pow(oldx, 2) - Math.pow(yCalc, 2)+ Ox;
               yCalc = 2 * oldx * yCalc + Oy;
               Passes++;
               Dist = Math.sqrt(Math.pow(xCalc, 2) + Math.pow(yCalc, 2));
           }
              Result[x][y] = Passes;}}
       return Result;
   }

public int[][] Julia(){
       for (int x = 0 ;x<512;x++){
           xCalc = Frac[0][x];
       for (int y=0;x<512;y++){
               yCalc= Frac[1][y];
           Dist = Math.sqrt(Math.pow(xCalc, 2)+Math.pow(yCalc, 2));          
           Passes =0;
           while(Dist <=2 && Passes<255)
           {
               double oldx = xCalc;
               xCalc= Math.pow(xCalc,2) - Math.pow(yCalc,2) + (-0.72689);
               yCalc= 2 * oldx * yCalc + 0.188887;
               Passes++;
           }
               Result[x][y]=Passes;}}
   return Result;
}

public int[][] BurningShip(){
   for(int x=0; x< 512; x++){
       xCalc = Frac[0][x];
       double Ox = xCalc;
   for(int y =0; y<512;y++){
       yCalc = Frac[1][y];
       double Oy = yCalc;
       Dist = Math.sqrt(Math.pow(xCalc, 2)+ Math.pow(yCalc, 2));
       Passes =0;
       while(Dist <= 2 && Passes < 255 )
       {
           double _oldx = xCalc;
           xCalc = Math.pow(xCalc,2) - Math.pow(yCalc,2) + Ox;
           yCalc = Math.abs(2* _oldx* yCalc) + Oy;
           Passes++;
           Dist = Math.sqrt(Math.pow(xCalc, 2) + Math.pow(yCalc, 2));
       }
          Result[x][y] = Passes;}}
   return Result;
}

public int[][] Multibrot(){
   for(int x = 0;x <512;x++)   {
       xCalc= Frac[0][x];
       double Ox = xCalc;
   for(int y = 0;y <512;y++)       {
       yCalc= Frac[1][y];
       double Oy = yCalc;
       Dist = Math.sqrt(Math.pow(xCalc, 2) + Math.pow(yCalc, 2));
       Passes = 0;
           while(Dist <= 2 && Passes <255)
              {
               double oldx = xCalc;
               xCalc = Math.pow(xCalc, 3) - (3* xCalc * Math.pow(yCalc, 2)) + Ox;
               yCalc = (3* Math.pow(oldx, 2)* yCalc) - Math.pow(yCalc, 3) + Oy;
               Passes++;
                   Dist = Math.sqrt(Math.pow(xCalc, 2) + Math.pow(yCalc, 2));
               }
               Result[x][y] = Passes;
                                  }}
           return Result;
   }
}

Explanation / Answer

public void reset(double xMin, double xMax, double yMin, double yMax ){      
       xCalc = 0;
       yCalc = 0;
       Dist = 0;
       Passes = 0;
      
       double constx = (Math.abs(xMax) + Math.abs(xMin))/ 512;
       double consty = (Math.abs(yMax) + Math.abs(yMin))/ 512;
      
       Frac = new double[2][512];
      
       for(int i = 0; i< 512; i++){
           Frac[0][i] = xMin +(constx * i);
           Frac[1][i] = yMin +(consty * i);
      
           Result = new int[512][512];  
}}  

//Implementation of Mandelbrot sets
public int[][] Mandelbrot(){
   for(int x = 0;x <512;x++){
       xCalc= Frac[0][x];
       double Ox = xCalc;
   for(int y = 0;y <512;y++){
       yCalc= Frac[1][y];
       double Oy = yCalc;
       Dist = Math.sqrt(Math.pow(xCalc, 2) + Math.pow(yCalc, 2));
       Passes =0;
           while(Dist <= 2 && Passes <255)
           {
               double oldx = xCalc;
               xCalc = Math.pow(oldx, 2) - Math.pow(yCalc, 2)+ Ox;
               yCalc = 2 * oldx * yCalc + Oy;
               Passes++;
               Dist = Math.sqrt(Math.pow(xCalc, 2) + Math.pow(yCalc, 2));
           }
              Result[x][y] = Passes;}}
       return Result;
   }

public int[][] Julia(){
       for (int x = 0 ;x<512;x++){
           xCalc = Frac[0][x];
       for (int y=0;x<512;y++){
               yCalc= Frac[1][y];
           Dist = Math.sqrt(Math.pow(xCalc, 2)+Math.pow(yCalc, 2));          
           Passes =0;
           while(Dist <=2 && Passes<255)
           {
               double oldx = xCalc;
               xCalc= Math.pow(xCalc,2) - Math.pow(yCalc,2) + (-0.72689);
               yCalc= 2 * oldx * yCalc + 0.188887;
               Passes++;
           }
               Result[x][y]=Passes;}}
   return Result;
}

public int[][] BurningShip(){
   for(int x=0; x< 512; x++){
       xCalc = Frac[0][x];
       double Ox = xCalc;
   for(int y =0; y<512;y++){
       yCalc = Frac[1][y];
       double Oy = yCalc;
       Dist = Math.sqrt(Math.pow(xCalc, 2)+ Math.pow(yCalc, 2));
       Passes =0;
       while(Dist <= 2 && Passes < 255 )
       {
           double _oldx = xCalc;
           xCalc = Math.pow(xCalc,2) - Math.pow(yCalc,2) + Ox;
           yCalc = Math.abs(2* _oldx* yCalc) + Oy;
           Passes++;
           Dist = Math.sqrt(Math.pow(xCalc, 2) + Math.pow(yCalc, 2));
       }
          Result[x][y] = Passes;}}
   return Result;
}

public int[][] Multibrot(){
   for(int x = 0;x <512;x++)   {
       xCalc= Frac[0][x];
       double Ox = xCalc;
   for(int y = 0;y <512;y++)       {
       yCalc= Frac[1][y];
       double Oy = yCalc;
       Dist = Math.sqrt(Math.pow(xCalc, 2) + Math.pow(yCalc, 2));
       Passes = 0;
           while(Dist <= 2 && Passes <255)
              {
               double oldx = xCalc;
               xCalc = Math.pow(xCalc, 3) - (3* xCalc * Math.pow(yCalc, 2)) + Ox;
               yCalc = (3* Math.pow(oldx, 2)* yCalc) - Math.pow(yCalc, 3) + Oy;
               Passes++;
                   Dist = Math.sqrt(Math.pow(xCalc, 2) + Math.pow(yCalc, 2));
               }
               Result[x][y] = Passes;
                                  }}
           return Result;
   }
}