My apologies, I know you guys are very busy on these forums and I will make sure to take that into account next time by stating that explicitly.

Printable View

- 05-04-2014, 10:38 PMjavaStoogeRe: Final Project - physics calculator
My apologies, I know you guys are very busy on these forums and I will make sure to take that into account next time by stating that explicitly.

- 05-04-2014, 10:47 PMjashburnRe: Final Project - physics calculator
There are different people in each forum, and there are also the same people. E.g., both Norm and I are on both forums.

The Kinematics panel has the following fields:

- Initial Distance
- Final Distance
- Initial Velocity
- Final Velocity
- Average Velocity
- Acceleration
- Time

It will be helpful if you can provide**a few theoretical cases**to illustrate how you expect this to work. E.g., if you place

- Initial Velocity: 25
- Final Velocity: 35
- Time: 5
- all other fields: blank

when you click Calculate do you expect to see**Acceleration: 2**? (*Acceleration = (Final velocity - Initial velocity) / Time*.)

Do you also expect to see**Distance: 150**? (*Distance = (Initial velocity + Final velocity) / 2 * Time*.)

If so, a few more like the above will help. - 05-04-2014, 11:10 PMjavaStoogeRe: Final Project - physics calculator
Yes, I know most of the moderators and senior members stay busy on here, Norm is pretty sick with it. Honestly don't know how he does it. Is he real? haha

Yes, that's__exactly__what I would like to happen! At least that's what I originally had in mind. It would be nice to produce any and all results it can based on the data. With that comes reformatting all the equations for each variable, which I can do. But given all that, I don't see how the checkJTF method and switch statements will accomplish this......leaving me in the dark. - 05-04-2014, 11:15 PMNormRe: Final Project - physics calculator
Can you do the manual exercise and create some example cases that jashburn suggested.

It seems that you are trying to write code without any design. When there is a design, then work on how to code it.

Worrying about methods and switch statements before a design can be a waste of time. - 05-04-2014, 11:56 PMjavaStoogeRe: Final Project - physics calculator
GOAL: After the calculation, return all the data to the results panel where I can display user input and unknowns, since all the variables will have been solved.

__Case 1:__

**Known**:

Initial Distance: 10

Final Distance: 20

Initial Velocity: 2

Final Velocity:

Average Velocity:

Acceleration:

Time: 4

**Result**s

Initial Distance: 10

Final Distance: 20

Initial Velocity: 2

Final Velocity: 0

Average Velocity: 1

Acceleration: -1/2

Time: 4

Final velocity = sqrt(lnitial Velocity^2 + 2*acceleration *(distanceFinal - distanceInitial))

Avg. Veclocity = (distanceF - distnceI) / time

Acceleration = 2 * ((distanceFinal - distanceInitial) - velocityInitial * time) / (time*time)

__Case 2:__

**Known**:

Initial Distance: 5

Final Distance:

Initial Velocity: 2

Final Velocity: 6

Average Velocity:

Acceleration: 2

Time:

**Result**s

Initial Distance: 5

Final Distance: 13

Initial Velocity: 2

Final Velocity: 6

Average Velocity: 4

Acceleration: 2

Time: 2

distanceFinal = (velocityFinal ^2 - velocityInitial ^2)/ (2*acceleration) + distanceInitial

velocityAvg = (distanceFinal - distanceInitial) / time

time = (velocityFinal - velocityInitial) / acceleration

OK. I think the problem exists with the checkJTF method.

A JTF[] exists to hold input values:

1. Input data into field

2. Test which JTF's in the array are left empty

* using a for statement followed by if statement

3. Within the if statement, if empty, assign each variable to an unknown variable array

ex:Code:`for(int i = 0 ; i < JTFarray.length < i++){`

if(JTFarray.empty()){

int variable = i; (empty JTF)

int[] variableArray = new int[];

variableArray.add(variable);

}

5. Implement a loop to find all unknown variables until they have all been found.

6. Display results

I don't know if I've just locked in on switch/case and the checkJTF method, but that's the only way I see doing it. - 05-05-2014, 12:13 AMNormRe: Final Project - physics calculator
Can you show an equation with variables

Make several cases for different variables without values

Give some variables in the equation values

Show the equation to compute the value of the missing variable.

Can an equation be made for each of the variables?

Forget about writing code until the above examples have produced a design.

Given the example you posted, how do you get the missing values? - 05-05-2014, 12:39 AMjavaStoogeRe: Final Project - physics calculator
I edited my previous post to keep things condensed. Hopefully the examples are clear and make sense.

I was using a set/get method to retrieve the unknown variable, but I'm not sure I will be able to do that if I use an array. - 05-05-2014, 12:46 AMNormRe: Final Project - physics calculator
For that equation, what variables can be undefined by the user and still solved by the program?

Are there different combinations of variables that can be undefined.

Are there any variables that must be defined?

The example appears to have 3 equations. - 05-05-2014, 12:58 AMjavaStoogeRe: Final Project - physics calculatorQuote:

For that equation, what variables can be undefined by the user and still solved by the program?

Quote:

Are there different combinations of variables that can be undefined.

can I determine which equation to use?

Quote:

Are there any variables that must be defined?

- 05-05-2014, 01:10 AMNormRe: Final Project - physics calculator
Those answers are not specific enough.

What variables must be given values?

List the different combinations of variables that can be undefined. Will there need to be a different equation for each combination of undefined variables? What are they?

Can this be organized by using a spreadsheet? - 05-05-2014, 01:45 AMjashburnRe: Final Project - physics calculator
javaStooge, I've got a proposal for you. Imo at this stage your project is too ambitious. Just for Kinematics alone you have 7 variables. The results of the calculation depend on the values from a combination of the variables, and so you have quite a few equations to use. The issue you have at the moment is in checking the existence of values for the variables, and then depending which ones are available, to determine the equation(s) to use. On top of that you still have 5 other areas to work on.

I'd suggest for now you keep things simple and more narrowly scoped. For Kinematics you could, e.g., just focus on the equation for acceleration (acceleration = (velocity (final) - velocity (initial)) / time), and so introduce only 4 fields/variables. If 3 of the variables are filled in, the equation will allow the calculation of the 4th. This way you'll effectively have only 4 cases to consider (1 case for each variable.) Once done, you can move on to the next area (Dynamics), and return to Kinematics to add more equations if you have the time after having done the other areas.

What do you reckon? - 05-05-2014, 01:57 AMjavaStoogeRe: Final Project - physics calculatorQuote:

What variables must be given values?

But if only two of them are unknown, I can use one of the other equations to find the unknown. - 05-05-2014, 02:09 AMjavaStoogeRe: Final Project - physics calculator
Yes, in my mind I didn't think it was going to be so difficult..but I wasn't thinking in terms of coding.

Quote:

I'd suggest for now you keep things simple and more narrowly scoped. For Kinematics you could, e.g., just focus on the equation for acceleration (acceleration = (velocity (final) - velocity (initial)) / time), and so introduce only 4 fields/variables. If 3 of the variables are filled in, the equation will allow the calculation of the 4th. This way you'll effectively have only 4 cases to consider (1 case for each variable.) Once done, you can move on to the next area (Dynamics), and return to Kinematics to add more equations if you have the time after having done the other areas.

For the time being, I will limit the program to one physics equation per topic and do it that way. I don't like the idea. Maybe along the way the solution to my anguish will present itself and not all will be lost. This is really, REALLY going to bother me.

Thanks. I'm sure I will have several more posts before the sun comes up. - 05-05-2014, 04:44 AMjavaStoogeRe: Final Project - physics calculator
Do you have any idea how I can properly update the result panel to display the unknown variable? I tried to revalidate the panel after add a JLabel.

----EDIT-----

I figured it out. - 05-05-2014, 08:48 AMgimbal2Re: Final Project - physics calculator
You might have to add a repaint() after that revalidate(), sometimes (and I don't know exactly why) that is necessary.

- 05-06-2014, 03:04 AMjavaStoogeRe: Final Project - physics calculator
Taking jashburns advice, I finished the code last night by resorting to a single equation for each topic. I'm happy with the result and that it began working properly however there are a lot of redundancies I would rather not have in the code. I kept with the checkJTF method, but instead of using a single method as I had hoped, I went ahead and created one for each topic JTF (e.g. kinematicCheck, dynamicsCheck, powerCheck) array. Also, I went ahead and created a calculate action listener for each of the topics as well. As a result, the code became rather redundant. How could I have avoided doing it this way? There must be some way of producing the same result with less code. Any ideas on how I could have reduced or improved the code? Any thoughts on how you guys would have written this program?

I'm going to continue working on the code because it has been a great learning experience for me and allowed me to implement a broad range of Java material. - 05-06-2014, 08:50 AMgimbal2Re: Final Project - physics calculator
It takes experience, you write less code by designing your code to be more reusable from the beginning; doing that afterwards tends to be a hairy deal where you lose track of the trees in the forest so to say. The next application you build will be a little more efficient, and then the next, etc. etc. Don't worry too much about it (but do keep thinking about it), congratulations on your successful milestone!