No you dont need an interface. Keep your present class somewhat as is with all the math functions in it. Remove the parts where you are getting the inputs from the user. Make sure all your math stuff is in public methods.
Create a second class that has the main method. In the main method get the user inputs and store in variables. Initialize an object of the first class and call the required math methods of the first class with the user inputs as parameters to give you the results. Your second class would be something like this
class MainClass {
public static void main(String args[]){
get user inputs
store them in variables (example sidex,sidey,sidez)
mathClass oldclass = new mathClass();
result = oldclass.getAreaOfTriangle(sidex,sidey,sidez);
System.out.println("Area = " + result);
}
}
Your old class will look like this:
class mathClass {
public double getAreaOfTriangle(int x,inty,intz){
calculate area;
result = area calculated;
return result;
}
}
|