Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling different classes with if else statements
    text
    copied!<p>I'm writing a java program that is like a physics lesson:</p> <pre><code>import javax.swing.JOptionPane; public class PhysicsClass { public static void main(String[] args) { int g = -1; while (g&lt;0){ String input = JOptionPane.showInputDialog("Welcome! What's your name? "); if(input.length() &gt; 0){ g++; System.out.println("Great! Lets begin."); } else{ System.out.println(" ok then."); System.exit(0); } } String[] firstChoice = {"Kinematics", "Dynamics", "Impulse/Momentum", "Energy/Power"}; JOptionPane.showInputDialog(null, "Which one of these Topic would you like to start with?", "Please pick a topic to start with", JOptionPane.INFORMATION_MESSAGE, null, firstChoice, firstChoice[0]); int i = 0; while (i&lt;0){ String Choice = ""; if (Choice == firstChoice[0]){ Kinematics.IntroToKinematics(); i++; } else if (Choice == firstChoice[1]){ Dynamics.DynamicsIntro(); i++; } else if (Choice == firstChoice[2]){ ImpulseAndMomentum.ImpulseAndMomentumIntro(); i++; } else if (Choice == firstChoice[3]){ EnergyAndPower.EnergyAndPowerIntro(); i++; } else{ System.out.println("Please pick one."); } } </code></pre> <p>I want whatever choice you pick in the first choice array to then go to the respected class. So if I choose kinematics, it will call on the kinematics class, for which the first few lines are:</p> <pre><code>import javax.swing.JOptionPane; public class Kinematics { public static void IntroToKinematics() { JOptionPane.showInternalMessageDialog(null, "Kinematics is one of the most basic" + " ideas of Newtonian Physics. It encompasses: speed, distance, time" + " displacement, acceleration and many key base concepts that form the the " + " foundation for most physic subjects. It will poke its head in everything" + "we cover.", "intro", JOptionPane.INFORMATION_MESSAGE); } } </code></pre> <p>It doesn't give me any errors but when I choose one of the strings from the array, it doesn't do anything. I think it might have something to do with the if else statements I used. Thanks for any and all help, I'm still relatively new to Java so any tips would be appreciated. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload