First, lets imagine you saved both classes in the package (folder) named "myPackage". First thing you should add in every class is this line of code:
package myPackage;
After you did that you have to create a new instance of SalesAnalyzer
inside the SalesManager
class, the same way you created a new Scanner
.
Scanner scan = new Scanner(System.in); //Here you created a new Scanner
Create a new SalesAnalyzer
:
SalesAnalyzer newSA = new SalesAnalyzer();
Now, if you want to access any method, you have to write the name of yours SalesAnalyzer
object, dot after that and then name of the method you wish to call.
/*
* Here you created a new String named fileName and added it value that
* yours "next" method returned. "next" is a method inside Scanner object
* and you called for it by writing "scan.next()".
*/
String fileName = scan.next();
This is what next method looks like inside Scanner object:
public String next() {
ensureOpen();
clearCaches();
while (true) {
String token = getCompleteTokenInBuffer(null);
if (token != null) {
matchValid = true;
skipped = false;
return token;
}
if (needInput)
readInput();
else
throwFor();
}
}
Now, lets say you want to call for totalSales
method inside your SalesAnalyzer
. It's a method that returns double type value. In case you want to save that value to some variable in your SalesManager
class you have to create variable of double type and call for the totalSales
method after. It should look like this:
double totalS = newSA.totalSales();
This way you accessed to method totalSales
inside your SalesAnalyzer
from your SalesManager
class and saved the value it returned to double variable named totalS
. Hopefully I clarified anything to you and helped you even a little. If you have any further question feel free to ask.