Issue
Yeah, the title isn't very descriptive but that is because I don't know how call this problem.
The problem is the next: I use inheritance with a list of a steps, for example a sum:
- Message of "give me the first number"
- "Insert first number"
- Message of "give me the second number"
- "Insert second number"
- Show the result
But the output make this:
- "Insert first number" 2 "Insert second number"
- Message of "give me the first number"
- Message of "give me the second number"
- Show the result (but ignoring the existance of the first number)
Now this is the code Code of JavaClassPrueba1A:
package package1;
import java.util.Scanner;
public class JavaClass1A {
protected int value1, value2, result;
Scanner dataEntry = new Scanner(System.in);
//Este método pide los valores al usuario
public void RequestData(){
System.out.print("Give me the first value: ");
value1 = dataEntry.nextInt();
System.out.print("Give me the second value: ");
value2 = dataEntry.nextInt();
}
//Este método muestra el resultado
public void ShowResult(){
System.out.println(result);
}
}
Code of JavaClassPrueba2A:
package package1;
public class JavaClass2A extends JavaClass1A{
public void Sum(){
result = value1 + value2;
}
}
Code of JavaClassPrueba3A:
package package1;
public class JavaClass3A extends JavaClass1A{
public void Subtraction(){
result = value1 - value2;
}
}
Code of MainClass1A (this is the class that run all):
package MetodoMain;
import package1.JavaClass2A;
import package1.JavaClass3A;
public class MainClass1A {
public static void main(String[] args){
JavaClass2A messageSum = new JavaClass2A();
messageSum.RequestData();
messageSum.Sum();
System.out.print("The resultado of the sum is: ");
messageSum.ShowResult();
JavaClass3A messageSubtraction = new JavaClass3A();
messageSubtraction.RequestData();
messageSubtraction.Subtraction();
System.out.print("The resultado of the Subtraction is: ");
messageSubtraction.ShowResult();
}
}
And this is a copy of all run. The problem here is a problem of in the order in which things are displayed/run (for this reason don't exist error message [yes i am very redundant])
cd C:\Users\Usuario\Documents\NetBeansProjects\JavaClassPrueba2; "JAVA_HOME=C:\Program Files\Java\jdk1.8.0_151" cmd /c ""C:\Program Files\NetBeans-12.1\netbeans\java\maven\bin\mvn.cmd" -Dexec.args="-classpath %classpath MetodoMain.MainClass1A" -Dexec.executable="C:\Program Files\Java\jdk1.8.0_151\bin\java.exe" -Dexec.classpathScope=runtime -Dmaven.ext.class.path="C:\Program Files\NetBeans-12.1\netbeans\java\maven-nblib\netbeans-eventspy.jar" -Dfile.encoding=UTF-8 org.codehaus.mojo:exec-maven-plugin:1.5.0:exec" Running NetBeans Compile On Save execution. Phase execution is skipped and output directories of dependency projects (with Compile on Save turned on) will be used instead of their jar artifacts.
Scanning for projects...
------------------------< DOS:JavaClassPrueba2 >------------------------
Building JavaClassPrueba2 1.0.0-SNAPSHOT
--------------------------------[ jar ]---------------------------------
--- exec-maven-plugin:1.5.0:exec (default-cli) @ JavaClassPrueba2 ---
5 this is a number that I inputed like the other 3
10
Give me the first value: Give me the second value: The resultado of the sum is: 15
90
100
Give me the first value: Give me the second value: The resultado of the Subtraction is: -10
BUILD SUCCESS
Total time: 01:05 min Finished at: 2021-01-20T16:00:24-03:00
And this is a screenshot of the same message of the run
Solution
It is a bug of maven on NetBeans. Try to change
System.out.print()
to
System.out.println()
in method RequestData()
Answered By - yuri777