So im trying to make a simple calc but having some problems Error message :Multiple markers at this line - No enclosing instance of type Application is accessible. Must qualify the allocation with an enclosing instance of type Application (e.g. x.new A() where x is an instance of Application). - Line breakpoint:Application [line: 64] - main(String[])
What am i doing wrong? Could anyone see something wrong and fix it plz?
public class Application {
interface MathOp {
public double doMath(double a, double b);
}
class Add implements MathOp{
public double doMath(double a, double b) {
return (a + b);
}
}
class Sub implements MathOp{
public double doMath(double a, double b) {
return (a - b);
}
}
class Div implements MathOp{
public double doMath(double a, double b){
return (a / b);
}
}
class Mul implements MathOp{
public double doMath(double a, double b){
return (a * b);
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double a,b,c;
int choice = 0;
a=b=c=0.0;
while(true) {
System.out.println("Enter two numbers");
a = Double.parseDouble(sc.nextLine());
b = Double.parseDouble(sc.nextLine());
System.out.println("Enter your choice");
System.out.println("1. Add");
System.out.println("2. Sub");
System.out.println("3. Mul");
System.out.println("4. Div");
choice = Integer.parseInt(sc.nextLine());
switch(choice) {
case 1 :
c = new Add().doMath(a,b);
break;
case 2 :
c = new Sub().doMath(a,b);
break;
case 3 :
c = new Div().doMath(a,b);
break;
case 4 :
c = new Mul().doMath(a,b);
break;
default:
break;
}
System.out.println(c + "this is the answere");
System.out.println("would you like to continue? (Y/N)");
if("N".equalsIgnoreCase(sc.nextLine())) { // careful with the paranthesis
break;
}
}
}