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

[In Java] What am I doing wrong with my code on line 15? What I plan to do: crea

ID: 3884266 • Letter: #

Question

[In Java]

What am I doing wrong with my code on line 15?

What I plan to do:
create a hash table with the String keys "+", "-", "/", "*" . And the values would be the object(of the classes). I have already made
Addition.java, Subtraction.java, Multiplication.java, Division.java.

They all have nothing filled in them.

Evaluatorul.java Operator.Java |! | 0 java 2 Operand.java 1.aye'E 8gIls. Addition·java Subtraction.java. Source History |,. | | import java.util.HashMap: /*Hashmap K-keys V type of mapped values 6 public abstract class Operator // The Operator class should contain an instance of a HashMap // This map will use keys as the tokens we're interested in, // and values will be instances of the Operators. 10 12 13 14 // Example: // Where does this declaration go? What should its access level be? // Class or instance variable? Is this the right declaration? static Ha3hMap opera tor = new Ha3hMap(){ operator.put(, new Addition) 16 17 18 19 20 21 //map.put"-, new Subtraction) public abstract int priority): public abstract Operand execut rand op1, Operand op2) 23 24 25 26 public static boolean check( String token return false;

Explanation / Answer

Hi Friend, there is error is HashMap creation.

Please find correct way.

import java.util.HashMap;

public class Test {

  

   static HashMap operator = new HashMap();

  

   // static block

   static{

       operator.put("+", new Addition());

   }

// instance function

   void fun1() {

       operator.put("+", new Addition());

   }

// static function

   static void fun2() {

       operator.put("+", new Addition());

   }

// main function

   public static void main(String[] args) {

      

       operator.put("+", new Addition());

   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote