how to call maze1 and maze2 object to be use in print method
maze2.maze[i][j]
maze2 is object
maze[i][j] is variable from different class
i just need help in calling object to be used in the print method and main will call print method to display.
import java.io.*;
public class MazeSolver {
//===========================================
// object reader
//==========================================
public static void read()throws
FileNotFoundException,IOException{
reader maze1 = new reader(new
FileReader("maze1.txt"));
reader maze2 = new reader(new
FileReader("maze2.txt"));
}
//===================================
// Print
//===================================
//maze1
public static void print(){
System.out.println("Maze 1:
\n");
for (int i=0; i<7; i++) {
for (int j=0;
j<7; j++) {
System.out.print(maze1.maze[i][j]);
System.out.print(' ');
}
System.out.println();
}
System.out.println("\nMaze 2:
\n");
//maze2
for (int i=0; i<7; i++) {
for (int j=0;
j<7; j++) {
System.out.print(maze2.maze[i][j]);
System.out.print(' ');
}
System.out.println();
}
}
//===========================================
// Main
//==========================================
public static void main(String[] args){
print();
}//end main
}//endclass
You can declare maze1 and maze2 as class level static variable. and add throws in main method like below:
import java.io.*;
public class MazeSolver {
private static reader maze1, maze2;
//===========================================
// object reader
//==========================================
public static void read()throws
FileNotFoundException,IOException{
maze1 = new reader(new FileReader("maze1.txt"));
maze2 = new reader(new FileReader("maze2.txt"));
}
//===================================
// Print
//===================================
//maze1
public static void print(){
System.out.println("Maze 1: \n");
for (int i=0; i<7; i++) {
for (int j=0; j<7; j++) {
System.out.print(maze1.maze[i][j]);
System.out.print(' ');
}
System.out.println();
}
System.out.println("\nMaze 2: \n");
//maze2
for (int i=0; i<7; i++) {
for (int j=0; j<7; j++) {
System.out.print(maze2.maze[i][j]);
System.out.print(' ');
}
System.out.println();
}
}
//===========================================
// Main
//==========================================
public static void main(String[] args)throws
FileNotFoundException,IOException{
read();
print();
}//end main
}//endclass
how to call maze1 and maze2 object to be use in print method maze2.maze[i][j] maze2 is...
This program is giving me an error in the main method at "outputFile.flush();" and "outputFile.close();" saying that it is unreachable code. Why is that, and how can I fix this?? import java.util.Scanner; import java.io.*; public class Topic7Hw { static Scanner sc = new Scanner (System.in); public static void main(String[] args) throws IOException { PrintWriter outputFile = new PrintWriter ("output.txt"); outputFile.println("hello"); final int MAX_NUM = 10;...
Need Help ASAP!! Below is my code and i am getting error in
(public interface stack) and in StackImplementation class. Please
help me fix it. Please provide a solution so i can fix the
error.
thank you....
package mazeGame;
import java.io.*;
import java.util.*;
public class mazeGame {
static String[][]maze;
public static void main(String[] args)
{
maze=new String[30][30];
maze=fillArray("mazefile.txt");
}
public static String[][]fillArray(String file)
{
maze = new String[30][30];
try{...
How do I separate the method into different class? I try
separate the testing and method class into 2 different class. And
when I test it, it said that the method is undefined. And it ask me
to create the method in the main class. I don't know what is the
problem.
This is the access to the code
https://repl.it/@Teptaikorn/test
Thank you very much
MazeSolver.java MazeTerster.... TwoDim AutoA... testfile.txt Main.java x > 0 N Binary TreeN... X LinkedBinary... Maze.java 1...
The DictionaryClient program featured in the class lecture also used the try-catch when creating a socket. Socket are auto-closeable and thus can use a try-with-resources instead. Edit the dictionary program to use try-with-resources instead. package MySockets; import java.net.*; import java.io.*; public class DictionaryClient { private static final String SERVER = "dict.org"; private static final int PORT = 2628; private static final int TIMEOUT = 15000; public static void main(String[] args) { Socket ...
I must implement a class to calculate n-th row of Pascal's Triangle (in Java). I need to create a static method that takes an argument "n" and returns the n'th line of pascal's triangle. the main method, which will call the class, is already done and the class is set up. Please build this without modifying the main method and without modifying exactly what the static method returns. public class Main { public static void main(String[] args) { int n...
I need to make this code access the main method I suppose, but I don't know how to make that happen... Help please! QUESTION: Write a method called switchEmUp that accepts two integer arrays as parameters and switches the contents of the arrays. Make sure that you have code which considers if the two arrays are different sizes. Instructor comment: This will work since you never go back to the main method, but if you did, it wouldn't print out...
Add appropriate descriptive comments to EACH line of the code in the project explaining why the code is in the application. import java.io.*; public class ExceptionTesterApp { public static void main(String[] args) { System.err.println("In main: calling method1."); method1(); System.err.println("In main: returned from method1."); } public static void method1() { System.err.println("\tIn method1: calling method2."); try { method2(); } catch (FileNotFoundException e) { System.err.println(e.toString()); } System.err.println("\tIn method1: returned from method2."); } public static void method2() throws FileNotFoundException { System.err.println("\t\tIn method2: calling method3.");...
(How do I remove the STATIC ArrayList from the public class Accounts, and move it to the MAIN?) import java.util.ArrayList; import java.util.Scanner; public class Accounts { static ArrayList<String> accounts = new ArrayList<>(); static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int option = 0; do { System.out.println("0->quit\n1->add\n2->overwirte\n3->remove\n4->display"); System.out.println("Enter your option"); option = scanner.nextInt(); if (option == 0) { break; } else if (option == 1) { add(); } else...
Help check why the exception exist do some change but be sure to use the printwriter and scanner and make the code more readability Input.txt format like this: Joe sam, thd, 9, 4, 20 import java.io.File; import java.io.PrintWriter; import java.io.IOException; import java.io.FileNotFoundException; import java.io.FileWriter; import java.util.Scanner; public class Main1 { private static final Scanner scan = new Scanner(System.in); private static String[] player = new String[622]; private static String DATA = " "; private static int COUNTS = 0; public static...
please evaluate the following code. this is JAVA a. class Car { public int i = 3; public Car(int i) { this.i = i; } } ... Car x = new Car(7), y = new Car(5); x = y; y.i = 9; System.out.println(x.i); b. class Driver { public static void main(String[] args) { int[] x = {5, 2, 3, 6, 5}; int n = x.length; for (int j = n-2; j > 0; j--) x[j] = x[j-1]; for (int j...