Results 1 to 3 of 3

Thread: Calculator

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

    Default Calculator

    'm just messing around and rewriting a program I'd been working on several months ago -- slightly more sophisticated physics calculator. I was hoping you guys could provide me with a little insight. Right now I have just the main, gui, and kinematics classes, eventually, I will add the other areas of physics. The program will open with a main menu where the user can select there topic and they can enter there data into JTFs. No, when I wrote this program the first time I used a lot of accessor methods(for each variable in the class(topic) ) that it just looked messy, so I want to get rid of those and use something else.

    Do you have any ideas how I might accomplish this? I had considered using a list, when the user chooses a field to enter (ex: kinematics) it will initiate a list of type Kinematic. Is this a better approach?

    Also, last time I had an issue with determining which calculations to perform based on the information entered. For instance, if the user left more than 2 JTF's blank (2 variables), but only enough data was given to solve for 1.....how can one account for this in there code? Aside from trying to perform each calculation in the class and breaking from any calculation that has more than one variable...I'm not sure what to do.

    this is just a rough example to the kinematics class to give you a better picture of what I'm trying to do.

    Java Code:
    	///////////////////////////////////|
    	/////////ACCESSOR METHODS//////////|
    	///////////////////////////////////|
    	public void initialVelocity(double iVelocity) {
    		this.iVelocity = iVelocity;
    	}
    	
    	public void finalVelocity(double fVelocity) {
    		this.fVelocity = fVelocity;
    	}
    	
    	public double initialDistance() {	
    		return iDistance;
    	}
    	
    	public double finalDistance() {	
    		return fDistance;
    	}
    	
    	///////////////////////////////////|
    	///////CALCULATE KINEMATICS////////|
    	///////////////////////////////////|
    	public double calculate(int i) {
    		switch(i) {
    		// Initial Velocity //
    		case 0: result = fVelocity - (acceleration * time);
    		// Final Velocity //
    		case 1: result = iVelocity + (acceleration * time); 
    		// Initial Distance //
    		case 2: result = ((iVelocity * iVelocity) - (fVelocity * fVelocity)  + (2 * acceleration)) / 2 ;
    		// Final Distance //
    		case 3: result = iDistance + (iVelocity*time) + (acceleration*(time*time))/2;
    		// Acceleration //
    		case 4: fVelocity = (iVelocity * iVelocity) + 2*acceleration*(fDistance - iDistance);
    				result = (fVelocity * fVelocity);
    		// Result //
    		case 5: result = (fVelocity - iVelocity)/acceleration;		
    		}
    		return result;
    	}
    	
    	public void empty() {
    		for(int i = 0; i <= data.length; i++) {
    			if(data[i] == null){
    				calculate(i);
    				break;
    			}
    		}
    	}
    }

  2. #2
    Matrice is offline Member
    Join Date
    Jul 2014
    Location
    Mililani
    Posts
    37
    Rep Power
    0

    Default Re: Calculator

    From all that, it seems that you like science.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,680
    Blog Entries
    7
    Rep Power
    21

    Default Re: Calculator

    Quote Originally Posted by javaStooge View Post
    Also, last time I had an issue with determining which calculations to perform based on the information entered. For instance, if the user left more than 2 JTF's blank (2 variables), but only enough data was given to solve for 1.....how can one account for this in there code? Aside from trying to perform each calculation in the class and breaking from any calculation that has more than one variable...I'm not sure what to do.
    That would be impossible to determine; e.g. a certain system may need three variable values v1, v2 and v3 where any of the values may be empty. Suppose there are four possible calculations, that need the following values:

    A: v1, v2
    B: v1, v3
    C: v1, v2, v3
    D: v1, v2

    Now, suppose the user leaves v3 blank; what calculation do you want to perform given v1 and v2?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Help with my calculator?
    By CountBale in forum New To Java
    Replies: 7
    Last Post: 01-08-2014, 10:19 AM
  2. need some help with my calculator
    By Tooks1 in forum New To Java
    Replies: 0
    Last Post: 02-13-2013, 07:38 PM
  3. calculator help
    By sirstroud in forum New To Java
    Replies: 0
    Last Post: 04-01-2012, 06:58 AM
  4. calculator
    By rithish in forum AWT / Swing
    Replies: 10
    Last Post: 04-26-2011, 12:24 AM
  5. help with calculator
    By kalibballer in forum New To Java
    Replies: 8
    Last Post: 04-01-2009, 01:57 PM

Posting Permissions

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