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

Exception in thread \"main\" java.lang.Error: Unresolved compilation problem: at

ID: 3797072 • Letter: E

Question

Exception in thread "main" java.lang.Error: Unresolved compilation problem:

at ArithmeticOperators.main(ArithmeticOperators.java:19)"

I'm not sure what is causing this at all, below is my code.

import java.util.*;

public class ArithmeticOperators{


public LinkedList head;

private static Scanner userChoice;

public String toString() {
        String result = "";
        LinkedList current = head;
        while(current.getFirst() != null){
            current = (LinkedList) current.getFirst();
        }
        return "List: " + result;
  }

public static void main(String[]args){


//mC stands for Math Choice
Scanner mC = new Scanner(System.in);
System.out.println("Enter your choice");
System.out.println("You can add or subtract");
String choice = mC.nextLine();

if(choice.equals("add")){
  Addition(result);
}else if(choice.equals("minus")){
  Subtraction(result2);}
System.out.println("Please choose FIVE numbers to add or subtract,");
}
public static int result;
public static int result2;

public static int Addition(int list){
  
  
  userChoice = new Scanner(System.in);
  LinkedList<Integer> aL = new LinkedList<Integer>();
  
  int a = userChoice.nextInt();
  int b = userChoice.nextInt();
  int c = userChoice.nextInt();
  int d = userChoice.nextInt();
  int e = userChoice.nextInt();
  
  aL.add(a);
  aL.add(b);
  aL.add(c);
  aL.add(d);
  aL.add(e);
  result = a + b + c + d + e;
  System.out.println("The elements of your list are:" + aL.toString());
  System.out.println("The result of your numbers are: " + result);
  return result;
  
  }

public static int Subtraction(int list){
  
  
  userChoice = new Scanner(System.in);
  LinkedList<Integer> aL = new LinkedList<Integer>();
  
  int a = userChoice.nextInt();
  int b = userChoice.nextInt();
  int c = userChoice.nextInt();
  int d = userChoice.nextInt();
  int e = userChoice.nextInt();
  
  aL.add(a);
  aL.add(b);
  aL.add(c);
  aL.add(d);
  aL.add(e);
  result = a - b - c - d - e;
  System.out.println("The elements of your list are:" + aL.toString());
  System.out.println("The result of your numbers are: " + result);
  return result2;

  


}

e eclipse ava Arithmeticop java Pse erators/src/Arithmeticoperators File Edit Source Refactor Navigate Search Project Run Window Help la Package Exp Ari hrnelicope Two java project eticOperators java int e userChoice next 71 Int AminoAcids 72 73 add a b Arithrreticoperators L. add(b); 74 L. add(c 75 (Jelaulu package 76 aL add d etioope 77 al. add(e); result a b c d e; Linked Stack 78 System out rintln ("The elements of your list are: aL toString 79 a JRF System Library system. out println ("The result of your numbers are: result 80 ArithmetiroperatorsTv 81 return result 82 th detault package 83 ArithmeticOpel 85 Link java RE System Library 87 88 89 91. di Problems Javadoc Declaration Console 3s ArithmeticOperators Clava A ication] CAP m Fil esJavaMirc1.8.0 121 binjavaw.exe (Feb 22, 2017, 9:1 12 PM) Exception in thread "main" java lang. Error: Unresolved compilation problem at Arithmeticoperators main (Arithmetic erators ava: 19 Ask me anything Quick Access 9:21 P 2/22/2017

Explanation / Answer

Hi buddy, I've identified one mistake in your code. You haven't given closing braces at the end of the java class. Here is the corrected code and the output.

import java.util.*;

public class ArithmeticOperators{


public LinkedList head;

private static Scanner userChoice;

public String toString() {
        String result = "";
        LinkedList current = head;
        while(current.getFirst() != null){
            current = (LinkedList) current.getFirst();
        }
        return "List: " + result;
}

public static void main(String[]args){


//mC stands for Math Choice
Scanner mC = new Scanner(System.in);
System.out.println("Enter your choice");
System.out.println("You can add or subtract");
String choice = mC.nextLine();

if(choice.equals("add")){
Addition(result);
}else if(choice.equals("minus")){
Subtraction(result2);}
System.out.println("Please choose FIVE numbers to add or subtract,");
}
public static int result;
public static int result2;

public static int Addition(int list){


userChoice = new Scanner(System.in);
LinkedList<Integer> aL = new LinkedList<Integer>();

int a = userChoice.nextInt();
int b = userChoice.nextInt();
int c = userChoice.nextInt();
int d = userChoice.nextInt();
int e = userChoice.nextInt();

aL.add(a);
aL.add(b);
aL.add(c);
aL.add(d);
aL.add(e);
result = a + b + c + d + e;
System.out.println("The elements of your list are:" + aL.toString());
System.out.println("The result of your numbers are: " + result);
return result;

}

public static int Subtraction(int list){


userChoice = new Scanner(System.in);
LinkedList<Integer> aL = new LinkedList<Integer>();

int a = userChoice.nextInt();
int b = userChoice.nextInt();
int c = userChoice.nextInt();
int d = userChoice.nextInt();
int e = userChoice.nextInt();

aL.add(a);
aL.add(b);
aL.add(c);
aL.add(d);
aL.add(e);
result = a - b - c - d - e;
System.out.println("The elements of your list are:" + aL.toString());
System.out.println("The result of your numbers are: " + result);
return result2;
}

}

OUTPUT:

D:>java ArithmeticOperators
Enter your choice
You can add or subtract
add
3
5
6
8
6
The elements of your list are:[3, 5, 6, 8, 6]
The result of your numbers are: 28
Please choose FIVE numbers to add or subtract,

D:>java ArithmeticOperators
Enter your choice
You can add or subtract
minus
5
1
2
4
3
The elements of your list are:[5, 1, 2, 4, 3]
The result of your numbers are: -5
Please choose FIVE numbers to add or subtract,