this question will seem very dumb to many, but I seem to lack some basic understanding of Java. I just never used several classes in one project. For a bigger project I want to split the code on a few classes, which have to operate each with one another. Here is a very basic example for better understanding.
I have the three classes TestMain, TestA and TestB. TestMain reads in two Strings input1 and input2. TestA parses input1 to the int inputA, TestB parses input2 to the int inputB. TestA then uses inputA and inputB to produce result1, and than TestB uses result1 to create result2. After that TestMain prints out both results.
I am not sure if this is even possible, since the classes have to interact with each other simultaneously. Since this is necessary for my other project, that's my first question - is this even possible?
My code until now is this, but there are several problems with it:
public class TestMain {
public static void main(String[] args) throws IOException {
String input1, input2;
TestA testA = new TestA(); TestB testB = new TestB();
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
input1 = br.readLine();
input2 = br.readLine();
System.out.println("A: " + testA.result1 + ", B: " + testB.result2);
}
}
public class TestA {
public static void main(String args[]){
String inputA;
int a; int result;
TestMain testMain = new TestMain(); TestB testB = new TestB();
inputA = testMain.input1;
a = Integer.parseInt(inputA);
result1 = a*testB.b;
}
}
public class TestB {
public void main(String args[]){
String inputB;
int b;
int result2;
TestMain testMain = new testMain(); TestA testA = new testA();
inputB = testMain.input1;
b = Integer.parseInt(inputB);
result2 = testA.result1*2;
}
}
That I can't solve this very easy example shows my lack of basics, so I hope that you can help me. Cheers, Joshflux