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

I need to put a class called math into the if statement. So that when the user i

ID: 3589080 • Letter: I

Question

I need to put a class called math into the if statement. So that when the user inputs 'y', the program is run from the other class and the calculator runs. If you can offer other suggestions, please provide them as well, thank you. Here is the main class:

package calculatorApp;

import java.util.Scanner;

/**
*
*
*/
public class main {

//private static char reply;

private static char reply;

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello world");
System.out.println("Welcome to the calculator");
System.out.println("Do you want to begin? Enter 'y' or 'n' ");
Scanner response = new Scanner(System.in);
String str = response.nextLine();
if (str.equals("y") ) {
System.out.println("Welcome to the calculator!");

// HERE IS WHERE I NEED HELP CALLING THE "MATH" CLASS

}
}

else if (str.equals("n")){
System.out.println("Goodbye");

}

else {

System.out.println("Error!");

}

}

private static char reader() {

return 0;
}

}

Explanation / Answer

import java.util.Scanner;
/**
*
*
*/
public class Main {
//private static char reply;
private static char reply;
/**
* @param args
*/
  
public class math{
// this is inner class
//add method
public int add(int a,int b){
return a+b;
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello world");
System.out.println("Welcome to the calculator");
System.out.println("Do you want to begin? Enter 'y' or 'n' ");
Scanner response = new Scanner(System.in);
String str = response.nextLine();
if (str.equals("y") ) {
System.out.println("Welcome to the calculator!");
//instianciate outer class Main
Main m = new Main();
//instianciate new inner math
Main.math mat = m.new math();
//calling add method of math method.
System.out.println(mat.add(4,5));
}
else if (str.equals("n")){
System.out.println("Goodbye");
}
else {
System.out.println("Error!");
}
}
private static char reader() {
return 0;
}
}
/*
sample output

Hello world
Welcome to the calculator
Do you want to begin? Enter 'y' or 'n'
y
Welcome to the calculator!
9

*/