I am new to Java and still trying to understand the basics. I can write code within a class and method but really struggling with working across classes. To help I am trying to write a very simple programme that can add or subtract two numbers. This program will have three classes:
Class 1
package christmas;
public class addintegers
{
public static int add2numbers(int a, int b)
{
return (a+b);
} }
and the second class
package christmas;
public class subtractintegers {
public static int sub2numbers(int a, int b)
{
return (a-b);
}
}
what I now want to do is to write a third class that contains a main method that can read two numbers and an operator (+ or -) from the keyboard and then depending on the operand call the addintegers or subtractintegers classes.
This seems basic and it is not homework, I am simply trying to understand through a basic example how to build more complex code to work across mumtiple classes.
I know how to read from the keyboard, the help I need is how to call the different classes from a main method that is in a class of its own.
Thank you in advance - I am sure this is easy for many but hard for me to understand.