- #1
CAF123
Gold Member
- 2,948
- 88
Homework Statement
I have to write a JAVA program that will compute and display (via the ptplot package) the solutions for the damped harmonic oscillator (x against t) in some given range for t. The solutions vary depending on how gamma and omega are related. The instructions given were:
1) Read in values of omega, gamma and the number of points to plot from the terminal
2) Calculate and plot the amplitude vs time using the ptplot package
3) Reprompt for new values of omega, gamma and no. of points
4) Add the results of this new calculation to the existing graph as a new series
The Attempt at a Solution
Writing up how to draw the graph is fine, I am just getting a bit confused about how to go about coding the loop (i.e the bit about reprompting for new values)
I remember someone saying they had to enclose the code in a 'while' loop, but I am not sure what the boolean condition would be here.
What I have written so far is something like:
while (some boolean statement) {
// In my program, I have the code that should be under this while statement correctly, here I will just write what I am doing - Ask user for values of omega,gamma and no.of points and parse into double form
if (gamma>2omega) {
//Here I write in the code to draw this graph etc..
After this I get stuck- How to reprompt user for more values?
What is the boolean statement?
How to plot graphs on existing graphs?
Any help here would be greatly appreciated and if anything is unclear, I will explain again.
Many thanks