Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I keep on getting a Error: Could not find or load main class Swamp.java and i can't figure it out import java.io.*; import java.util.*; //

I keep on getting a Error: Could not find or load main class Swamp.java and i can't figure it out

import java.io.*; import java.util.*;

// DO NOT!! IMPORT JAVA.LANG

public class Swamp { static int[][] swamp; // NOW YOU DON'T HAVE PASS THE REF IN/OUT METHODS

public static void main(String[] args) throws Exception { int[] dropInPt = new int[2]; // row and col will be on the 2nd line of input file; swamp = loadSwamp( args[0], dropInPt ); int row=dropInPt[0], col = dropInPt[1]; String path = ""; // with each step grows to => "[2,3][3,4][3,5][4,6]" etc dfs( row, col, path ); } // END MAIN

// JUST FOR YOUR DEBUGGING - DELETE THIS METHOD AND ITS CALL BEFORE HANDIN // ---------------------------------------------------------------- private static void printSwamp(String label, int[][] swamp ) { System.out.println( label ); System.out.print(" "); for(int c = 0; c < swamp.length; c++) System.out.print( c + " " ) ; System.out.print( " "); for(int c = 0; c < swamp.length; c++) System.out.print("- "); System.out.print( " ");

for(int r = 0; r < swamp.length; r++) { System.out.print( r + "| "); for(int c = 0; c < swamp[r].length; c++) System.out.print( swamp[r][c] + " "); System.out.println("|"); } System.out.print( " "); for(int c = 0; c < swamp.length; c++) System.out.print("- "); System.out.print( " "); } // --YOU-- WRITE THIS METHOD (LOOK AT PRINTSWAMP FOR CLUES) // ---------------------------------------------------------------- private static int[][] loadSwamp( String infileName, int[] dropInPt ) throws Exception { File swampFile= new File(infileName); Scanner inputFile = new Scanner( swampFile );

int dimension = inputFile.nextInt(); dropInPt[0] = inputFile.nextInt(); dropInPt[1] = inputFile.nextInt(); int[][] swamp = new int[dimension][dimension]; for( int r = 0; r

static void dfs( int r, int c, String path ) // dfs = DEPTH FIRST SEARCH { path += "[" + Integer.toString(r) + "," + Integer.toString(c) + "]"; //finish writing

if (onEdge(r,c)) { System.out.println(path); return; } if(swamp[r-1][c] == 1) // north { swamp[r][c]= -1; dfs(r-1, c, path); swamp[r][c] = 1; } if(swamp[r-1][c+1] == 1) // northeast { swamp[r][c]= -1; dfs(r-1, c+1, path); swamp[r][c] = 1; } if(swamp[r][c+1] == 1) // east { swamp[r][c]= -1; dfs(r, c+1, path); swamp[r][c] = 1; } if(swamp[r+1][c+1] == 1) // southeast { swamp[r][c]= -1; dfs(r+1, c+1, path); swamp[r][c] = 1; } if(swamp[r+1][c] == 1) // south { swamp[r][c]= -1; dfs(r+1, c, path); swamp[r][c] = 1; } if(swamp[r+1][c-1] == 1) // southwest { swamp[r][c]= -1; dfs(r+1, c-1, path); swamp[r][c] = 1; } if(swamp[r][c-1] == 1) // west { swamp[r][c]= -1; dfs(r, c-1, path); swamp[r][c] = 1; } if(swamp[r-1][c-1] == 1) // northwest { swamp[r][c]= -1; dfs(r-1, c-1, path); swamp[r][c] = 1; }

} static boolean onEdge(int r, int c) { return ( r==0 || r == swamp.length - 1 || c==0 || c == swamp[r].length - 1 ); } }

The text file swamp2.txt:

9 4 4 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 1 1 1 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1 0 0 1 0 0 0 0 1 0 1 0 1 0 0 0 1 0 0 0 0 0 0 0 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administration The Complete Guide To Dba Practices And Procedures

Authors: Craig S. Mullins

2nd Edition

0321822943, 978-0321822949

More Books

Students also viewed these Databases questions