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

JAVA and this is my code /////////////// import java.io.InputStream; import java

ID: 3776272 • Letter: J

Question

JAVA

and this is my code

///////////////


import java.io.InputStream;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;

public class MazeGUIPane extends Application{

@Override
public void start(Stage primaryStage){
  
WebView mapView = new WebView();
WebEngine webEngine = mapView.getEngine();
String url = "http://street360.net/spain/navarre/pamplona_navarre.php";
url += "&output=embed";
webEngine.load(url);

VBox vBox = new VBox(5);
vBox.getChildren().add(mapView);

InputStream instream = MazeGUIPane.class.getResourceAsStream("traffic.png");
Image trafficImage = new Image(instream);

instream = MazeGUIPane.class.getResourceAsStream("roads.jpg");
Image roadsImage = new Image(instream);
////////////////va
Marker RedMarker = new Marker(trafficImage, "Red");
RedMarker.setLayoutX(320);
RedMarker.setLayoutY(440);
////////////////va
Marker pamplonaMarker = new Marker(roadsImage, "pamplona");
pamplonaMarker.setLayoutX(450);
pamplonaMarker.setLayoutY(400);
///////////////// va
Group root = new Group();
root.getChildren().add(vBox);
root.getChildren().add(RedMarker);
root.getChildren().add(pamplonaMarker);
Scene scene = new Scene(root);

primaryStage.setTitle("Hello street of Pamplona!");
primaryStage.setScene(scene);
primaryStage.show();
}

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

class Marker extends Group{
  
public Marker(Image image, String text){
  
ImageView imageView = new ImageView(image);
Label label = new Label(text);
VBox vbox = new VBox(5);
vbox.getChildren().add(imageView);
vbox.getChildren().add(label);
getChildren().add(vbox);
}
}

}

/////////

if i wanna save this photo here

to roads.jpg or traffic.png ? for this code

and jus save it with the program file?

and what should i get for other jgp or png here...

and plz check if my code is right or not

Map of Pamplona Run

Explanation / Answer

Answer:

import java.io.*;

public class DetectedShortestPathInMaze
{
  
   static int number_of_rows=10;       static    int number_of_columns=10;
   static int begin_of_row=5;       static int begin_of_coloumn=3;
static int end_of_row=1;       static int end_of_coloumn=6;
  
   static    int taken_maze[][]={{1,1,1,1,1,1,1,1,1,1},
                           {1,0,0,1,0,0,0,1,0,1},
                           {1,0,1,1,1,0,1,1,0,1},
                           {1,0,0,0,0,0,0,0,0,1},
                           {1,0,1,0,1,1,0,1,1,1},
                           {1,0,0,0,0,1,0,0,0,1},
                           {1,0,1,1,1,0,0,1,1,1},
                           {1,0,1,1,1,1,0,1,0,1},
                           {1,0,0,0,0,0,0,0,0,1},
                           {1,1,1,1,1,1,1,1,1,1}};

  
   static    int shortestpath[]=new int[number_of_rows*number_of_columns];
   static    int length_short;

  
  
boolean visitedalready(int row, int col, int detectedpathsofar[], int detectedlengthsofar){
      
         
       int x;
       int goal = row*number_of_columns+col;

       for (x=0;x<detectedlengthsofar;x++)
           if (detectedpathsofar[x]==goal) return true;

       return false;
   }

  
  
   public void displayupdatedpath(int takenpath[], int takenlength){
      

       int r,c;

       for (r=0;r<number_of_rows;r++){
           for(c=0;c<number_of_columns;c++){
               if (taken_maze[r][c]==1)
                   System.out.print("|");             
               else if (r==begin_of_row && c==begin_of_coloumn)
                   System.out.print("S");             
               else if (r==end_of_row && c==end_of_coloumn)
                   System.out.print("X");             
               else if (visitedalready(r,c,takenpath,takenlength))
                   System.out.print("o");             
               else
                   System.out.print(" ");             
           }
           System.out.println("");
       }
   }
  
   public void searchnewpath(int row, int col, int detectedpathsofar[], int detectedlengthsofar){
      

      
       if (row<0 || col<0 || row>=number_of_rows || col>=number_of_columns)
           return;
       if (taken_maze[row][col]==1) return ;
       if (visitedalready(row, col, detectedpathsofar, detectedlengthsofar)) return;

       int takenpath[]=new int[detectedlengthsofar+1];

       System.arraycopy(detectedpathsofar, 0, takenpath, 0, detectedlengthsofar);
          
                          
      
       takenpath[detectedlengthsofar++]=row*number_of_columns+col;

       if (row==end_of_row && col==end_of_coloumn){      
          

           System.out.println("Detected path of length "+detectedlengthsofar+":");
           displayupdatedpath(takenpath, detectedlengthsofar);

           if (detectedlengthsofar<=length_short){
               length_short=detectedlengthsofar;
               System.arraycopy(takenpath, 0, shortestpath, 0, detectedlengthsofar);
               System.out.println(" The new shortest path is of length " + detectedlengthsofar);
           }
           System.out.println("");
           return;
       }

      
       searchnewpath(row-1, col, takenpath, detectedlengthsofar);
       searchnewpath(row, col-1, takenpath, detectedlengthsofar);
       searchnewpath(row, col+1, takenpath, detectedlengthsofar);
       searchnewpath(row+1, col, takenpath, detectedlengthsofar);
   }
          
  
   public static void main(String[] args)
   {
      

       int r,c,x;              
       int detectedpathsofar[];      
       int detectedlengthsofar;      

       DetectedShortestPathInMaze obj=new DetectedShortestPathInMaze();  

       detectedpathsofar=new int[obj.number_of_rows*obj.number_of_columns];
      
       for (x=0;x<obj.number_of_rows*obj.number_of_columns;x++){
           obj.shortestpath[x]=-1;
           detectedpathsofar[x]=-1;
       }

      
       obj.length_short=obj.number_of_rows*obj.number_of_columns+1;
       detectedlengthsofar=0;

       System.out.println("The Maze Is Shown As Below:");
       for (r=0;r<obj.number_of_rows;r++){
           for (c=0;c<obj.number_of_columns;c++){
               if (r==begin_of_row && c==begin_of_coloumn)      
                   System.out.print("S");      
               else if (r==end_of_row && c==end_of_coloumn)
                   System.out.print("x");
               else if (obj.taken_maze[r][c]==0)
                   System.out.print(" ");
               else System.out.print("|");
           }
           System.out.println("");
       }

       System.out.println("");
       System.out.println("Searching For Paths!!!!!");

       obj.searchnewpath(begin_of_row, begin_of_coloumn, detectedpathsofar, detectedlengthsofar);

       System.out.println("");
       System.out.println("The shortest path was found with the following of length "+ obj.length_short);
       obj.displayupdatedpath(obj.shortestpath, obj.length_short);

   }
}