Page 2 of 2 FirstFirst 12
Results 21 to 37 of 37
Like Tree2Likes

Thread: Final Project - physics calculator

  1. #21
    javaStooge is offline Senior Member
    Join Date
    Jan 2014
    Posts
    104
    Rep Power
    0

    Default Re: 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.

  2. #22
    jashburn is offline Senior Member
    Join Date
    Feb 2014
    Posts
    219
    Rep Power
    1

    Default Re: 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.

  3. #23
    javaStooge is offline Senior Member
    Join Date
    Jan 2014
    Posts
    104
    Rep Power
    0

    Default Re: 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.
    Last edited by javaStooge; 05-04-2014 at 11:17 PM.

  4. #24
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,446
    Rep Power
    25

    Default Re: 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.
    If you don't understand my response, don't ignore it, ask a question.

  5. #25
    javaStooge is offline Senior Member
    Join Date
    Jan 2014
    Posts
    104
    Rep Power
    0

    Default Re: 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

    Results
    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:

    Results
    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:
    Java Code:
    for(int i = 0 ; i < JTFarray.length < i++){
        if(JTFarray.empty()){
            int variable = i;  (empty JTF)
            int[] variableArray = new int[];
            variableArray.add(variable);
    }
    4. Use the variable array to determine which switch statement to execute? I recognize the problem with this though. By doing this, each variable will be limited to a single switch equation. (Do I need to make all the equations accessible regardless of the variable and if it can return a result, execute the calculation, if not move on to the next equation until it can.)
    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.
    Last edited by javaStooge; 05-05-2014 at 12:35 AM.

  6. #26
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,446
    Rep Power
    25

    Default Re: 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?
    If you don't understand my response, don't ignore it, ask a question.

  7. #27
    javaStooge is offline Senior Member
    Join Date
    Jan 2014
    Posts
    104
    Rep Power
    0

    Default Re: 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.

  8. #28
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,446
    Rep Power
    25

    Default Re: 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.
    If you don't understand my response, don't ignore it, ask a question.

  9. #29
    javaStooge is offline Senior Member
    Join Date
    Jan 2014
    Posts
    104
    Rep Power
    0

    Default Re: Final Project - physics calculator

    For that equation, what variables can be undefined by the user and still solved by the program?
    Yes, so I need to test whether enough data has been entered to produce a result, if not...send message to user "Not Enough Data".

    Are there different combinations of variables that can be undefined.
    Yes, I chose those equations because they best suited my needs to solve for the unknown variable. The equation used is dependent on the data provided. Does this suggest I build each equation to solve for any potential variable? Which leads me to ask, how
    can I determine which equation to use?

    Are there any variables that must be defined?
    I suppose you could prevent this by checking the number of inputs and testing if it can produce a results, if not, send the message to user.

  10. #30
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,446
    Rep Power
    25

    Default Re: 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?
    If you don't understand my response, don't ignore it, ask a question.

  11. #31
    jashburn is offline Senior Member
    Join Date
    Feb 2014
    Posts
    219
    Rep Power
    1

    Default Re: 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?

  12. #32
    javaStooge is offline Senior Member
    Join Date
    Jan 2014
    Posts
    104
    Rep Power
    0

    Default Re: Final Project - physics calculator

    What variables must be given values?
    I should have at least one distance, velocity, or time variable, final or initial. If one from each of these are left empty, there is nothing to calculate...not enough data.
    But if only two of them are unknown, I can use one of the other equations to find the unknown.

  13. #33
    javaStooge is offline Senior Member
    Join Date
    Jan 2014
    Posts
    104
    Rep Power
    0

    Default Re: Final Project - physics calculator

    Quote Originally Posted by jashburn View Post
    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.
    Yes, in my mind I didn't think it was going to be so difficult..but I wasn't thinking in terms of coding.


    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.
    Yes, I suppose that's what I had intended to do originally, simply pass the unknown variable and choose the correct equation. However as time went on, I finally realized the possibility of more than one empty field.
    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.

  14. #34
    javaStooge is offline Senior Member
    Join Date
    Jan 2014
    Posts
    104
    Rep Power
    0

    Default Re: 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.
    Last edited by javaStooge; 05-05-2014 at 08:48 AM.

  15. #35
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,030
    Rep Power
    6

    Default Re: 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.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  16. #36
    javaStooge is offline Senior Member
    Join Date
    Jan 2014
    Posts
    104
    Rep Power
    0

    Default Re: 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.

  17. #37
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,030
    Rep Power
    6

    Default Re: Final Project - physics calculator

    Quote Originally Posted by javaStooge View Post
    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.
    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!
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Final Java Project
    By ExX in forum New To Java
    Replies: 1
    Last Post: 05-06-2012, 09:57 AM
  2. Final Year Project
    By srrehman in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 09-14-2011, 01:00 PM
  3. Help me? Class final project.
    By Blue Energy in forum Advanced Java
    Replies: 2
    Last Post: 05-14-2011, 06:39 AM
  4. GUI Final Project help
    By Unknown in forum New To Java
    Replies: 21
    Last Post: 12-30-2008, 07:58 PM
  5. help to complete final part of project
    By dirtycash in forum New To Java
    Replies: 6
    Last Post: 12-31-2007, 06:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •