Question

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{
   Scanner sc = new Scanner(new File(file));
  
   for(int row = 0; row < 30; row++)
   {
   for(int col = 0; col < 30; col++)
   {
   maze[row][col] = sc.next();
   }
   sc.nextLine();
   }
   printArray();
   }
   catch(FileNotFoundException fe)
   {
   System.out.println("Error: file mazefile.txt not found!");
   }
   return maze;
   }
   public static void printArray()
   {
   System.out.println();
   for(int row=0;row<30;row++)
   {
   for(int col=0;col<30;col++)
   {
   System.out.print(maze[row][col]+" ");
   }
   System.out.println();
   }


   }

   public void location()
   {

   System.out.println("Please enter from the Matrix location S.");
   Scanner StartingPoint = new Scanner(System.in);
   String index = StartingPoint.nextLine();
   String[] indices = index.split(" ");
   }
   public String getByte( String arrayValue, int index)
   throws IllegalArgumentException, ArrayIndexOutOfBoundsException
   {
  
   //return arrayValue;
   //placing this statement at the end because they are not reachable because of this

   String x = arrayValue;
   switch (x.charAt(0)) {
   case '0':
   //push();//dfine this method to use
   //S = StartingPoint; // they both are not declared any where
   System.out.println("S");
   break;
   case '1':
   //Move();//define this method to use
   System.out.println("Help, I am trapped");
   break;
   case 'E':
   //Exit();
   System.out.println("I am free");
   break;

   default:
   //doSomethingElse();
   }
   return arrayValue;
   }
   }
public interface Stack
   {
   public void push(Object X);
   public void pop();
   public void top();
   Object move();
   boolean isEmpty();

  
   }

public interface Stack public void push(Object X); public void pop(); public void top); Object move(); boolean isEmpty();*mazeGame.javaStacklmplementation.java 3 1 package mazeGame; 2 public classl StackImp lementation implements Stack 3 public v

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The code seems to be incomplete. I can't understand what you are trying to achieve. I'll point out the errors that I found.

You need to understand the basic concepts of Java.

1. Make sure Stack interface is created within a separate file. You should not append it with another class in the same file. The error in Stack interface can be corrected by this.

2. In StackImplementation class, you need to implement all the methods from Stack interface. You have not implemented move() and isEmpty() methods in StackImplementation.

3. There is no such Exception in java called UnderflowException. You must define the custom exception UnderflowException in a separate class if you need so. Or just use Exception itself instead of UnderflowException.

4. fillArray() is defined in class mazeGame as static. You should call this static method as mazeGame.fillArray().

(i.e: className.methodName())

5. You need to pass a String object to the method fillArray() since you have declared it with public static String[][] fillArray(String file) in mazeGame.

6. Variable maze in class mazeGame is static. So you should call the variable as mazeGame.maze.

7. Variables topofStack and theArray are not declared in class StackImplementation.

8. top() is defined wih return type void, but you are returning a variable from it. Make sure you have given the proper return type in method top().

9. In method push(Object X) consider using String instead of Object. You seem to be using String to read value in mazeGame. String is a subtype of Object and not vice versa. You might get compile time error saying incompatible type. You can only pass same type or subtype of the parameter in the method.

Add a comment
Know the answer?
Add Answer to:
Need Help ASAP!! Below is my code and i am getting error in (public interface stack)...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I have a java project that I need help trying to finish. I have most of it completed but the issue I am running into is adding numbers with different lengths. Project requirements: . Use a Stack ADT w...

    I have a java project that I need help trying to finish. I have most of it completed but the issue I am running into is adding numbers with different lengths. Project requirements: . Use a Stack ADT with the implementation of your choice (Array or Link), it should not make a difference 2.Read two “integer” numbers from the user. Hint: You don’t need to use an int type when you read, it may be easier to parse the input...

  • Currently, I'm getting this as my output: "Exception in thread "main" java.lang.NullPointerException    at InfixExpression.execute(InfixExpression.java:98)   ...

    Currently, I'm getting this as my output: "Exception in thread "main" java.lang.NullPointerException    at InfixExpression.execute(InfixExpression.java:98)    at InfixExpression.Evaluate(InfixExpression.java:65)    at InfixExpression.setWholeExpr(InfixExpression.java:24)    at InfixExpression.<init>(InfixExpression.java:17)    at Main.testHW1(Main.java:17)    at Main.main(Main.java:6)" I need to get this as my output: "Testing InfixExpression: When passing null, the String and double = Infix String: , result: 0.0 When passing a valid String, the String and double = Infix String: ( 234.5 * ( 5.6 + 7.0 ) ) / 100.2, result: 29.488023952095805 ..." I...

  • I need to implement a stack array but the top of the stack has to be...

    I need to implement a stack array but the top of the stack has to be Initialize as the index of the last location in the array.    //Array implementation of stacks.    import java.util.Arrays;       public class ArrayStack implements Stack {        //Declare a class constant called DEFAULT_STACK_SIZE with the value 10.           private static final int DEFAULT_STACK_SIZE = 10;           /* Declare two instance variables:            1. An integer called...

  • *JAVA* Can somebody take a look at my current challenge? I need to throw a different...

    *JAVA* Can somebody take a look at my current challenge? I need to throw a different exception when a)(b is entered. It should throw "Correct number of parenthesis but incorrect syntax" The code is as follows. Stack class: public class ArrayStack<E> {    private int top, size;    private E arrS[];    private static final int MAX_STACK_SIZE = 10;    public ArrayStack() {        this.arrS = (E[]) new Object[MAX_STACK_SIZE];        this.top = size;        this.size = 0;...

  • Stack help. I need help with my lab assignment. Complete a method for a class named...

    Stack help. I need help with my lab assignment. Complete a method for a class named Palindrome that evaluates a string phrase to determine if the phrase is a palindrome or not. A palindrome is a sequence of characters that reads the same both forward and backward. When comparing the phrase to the same phrase with the characters in reverse order, an uppercase character is considered equivalent to the same character in lowercase, and spaces and punctuation are ignored. The...

  • Im writing a method to evaluate a postfix expression. Using my own stack class. Here is my code but I keep getting a classcastexception where it says java.lang.Character cannot be cast to java.lang,In...

    Im writing a method to evaluate a postfix expression. Using my own stack class. Here is my code but I keep getting a classcastexception where it says java.lang.Character cannot be cast to java.lang,Integer. Im not sure how to fix this. public class Evaluator { public static void evaluatePost(String postFix)    {        LinkedStack stack2 = new LinkedStack();        int val1;        int val2;        int result;        for(int i = 0; i < postFix.length(); i++)        {            char m = postFix.charAt(i);            if(Character.isDigit(m))            {                stack2.push(m);            }            else            {               ...

  • I have added a little Code but I need help with the rest. /** A class...

    I have added a little Code but I need help with the rest. /** A class of stacks whose entries are stored in a chain of nodes. Implement all methods in MyStack class Main Reference : text book or class notes Do not change or add data fields */ package PJ2; public class MyStack<T> implements StackInterface<T> {    // Data fields    private Node<T> topNode; // references the first node in the chain    private int numberOfEntries;       public...

  • how do I change my code to generic form *********************************************************************** public class UnboundedStackQueue { //question#3 }...

    how do I change my code to generic form *********************************************************************** public class UnboundedStackQueue { //question#3 } class Stack { Node head; int size; Stack() //default constructor { this.head=null; this.size=0; } //Input = data //Output = void (just adds value to list) // method pushes elements on stack // time: O(1) // space: O(1) public void push(int data) { Node node=new Node(data); node.next=head; head=node; size++; } //Input = none //Output = top of stack // method pops value from top of...

  • Java - data structures Suppose that in the array-based stack, the array doubles in size after...

    Java - data structures Suppose that in the array-based stack, the array doubles in size after multiple push operations. But later on, fewer than half of the array’s locations might actually be used by the stack due to pop operations. Revise the implementation so that its array also can shrink in size as objects are removed from the stack. Accomplishing this task will require two new private methods, as follows: The first new method checks whether we should reduce the...

  • Dynamic Implementation of Stack - The purpose is to use our dynamic implementation of stack. The...

    Dynamic Implementation of Stack - The purpose is to use our dynamic implementation of stack. The application will be to add large numbers. Review adding large numbers Remember that we can use stacks to safely add integer values that overflow the int data type g. in Java, the maximum possible int value Integer.MAX_VALUE is: 2147483647 so any int addition larger than this will overflow and fail Using stacks to add large numbers safely Will actually represent the large integers to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT