Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 2 12 LastLast
Results 1 to 25 of 49

Thread: Testing double null

  1. #1
    Member
    Join Date
    Jan 2014
    Location
    Washington DC
    Posts
    81
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Testing double null

    I need a little advice on how to execute a particular class. I've created a Kinematics class that will execute and calculate all the functions pertaining to kinematic equations. In the main class, I will have the user provide the data in JTextField. Now I need to test which JTextfields (variables) were left empty. I plan to use a number of if/else statements :
    if(distanceI != null && distanceF != null)
    The problem with this is that these variables are double and therefore cannot be tested as null. I read a few things about Double but I really don't see how I'm supposed convert each double variable to Double, is that even possible?

    I know this code is going to take quite a bit of time to write and will be cumbersome since I need to manipulate each equation to solve for the missing variable, but figuring this out would be a big step in completing this program.

    public class Kinematics {
    	double distanceI, distanceF, velocityI, velocityF,
    	velocityAverage, acceleration;	
    	public Kinematics(){
     
    		//v2 = v1 + a*dt	
    		if(distanceI != null && distanceF != null){
     
    				}
    				else{
     
    				}	
     
     
    	}
    		public void setDistanceI(double distanceI){
    			this.distanceI = distanceI;
    		}
    		public void setDistanceF(double distanceF){
    			this.distanceF = distanceF;
    		}
    		public void setVelocityI(double velocityI){
    				this.velocityI = velocityI;
    		}
    		public void setVelocityF(double velocityF){
    			this.velocityF = velocityF;
    		}
    		public void setVelocityAverage(double velocityAverage){
    			this.velocityAverage = velocityAverage; 
    		}
    		public void setAcceleration(double acceleration){
    			this.acceleration = acceleration;
    		}
    		public double getDistanceI(){
    			return distanceI;
    		}
    		public double getDistanceF(){
    			return distanceF;
    		}
    		public double getVelocityI(){
    			return velocityI;
    		}
    		public double getVelocityF(){
    			return velocityF;
    		}
    		public double getVelocityAverage(){
    			return velocityAverage;
    		}
    		public double getAcceleration(){
    			return acceleration;
    		}
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Testing double null

    What do you want to test for? A primitive will never have a null value.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Jan 2014
    Location
    Washington DC
    Posts
    81
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Testing double null

    When I set the restrictions for the if/else statements, the program needs to know which variable to solve for. So for instance, F = ma:
    if(m != null && a!= null)
    F = m*a;
    else if(F!=null && m!= null)
    a = F / m;
    else().....

    Do you think that is the best way to do this?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Testing double null

    Perhaps the caller of the method could sort out what computation to do and call an appropriate method to solve it.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Jan 2014
    Location
    Washington DC
    Posts
    81
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Testing double null

    The method would still need to test whether or not a double is null...no? I had considered making a method for each equation, but since there are slight variations in each of them I thought I could contain them within the same method...

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Testing double null

    test whether or not a double is null
    A primitive like double will never have a null value.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Member
    Join Date
    Jan 2014
    Location
    Washington DC
    Posts
    81
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Testing double null

    Quote Originally Posted by Norm View Post
    A primitive like double will never have a null value.
    Yes, I know that, as I mentioned in my first post. I'm not sure what you are suggesting I can do with the method to "sort out what computation to do".

    Would this be attached to the calculate JButton some how?
    Last edited by javaStooge; May 2nd, 2014 at 11:53 AM.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Testing double null

    test which JTextfields (variables) were left empty.
    Test the String that is returned by the getText method.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Member
    Join Date
    Jan 2014
    Location
    Washington DC
    Posts
    81
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Testing double null

    Thank you, I took your advice and found some good stuff online. I'm just trying to get my thoughts down in code (what you see below), but after that, I started thinking about the method you were talking about. Should I create a single "checkJTF" method that will perform the actions of the "for" loop below, for each textfield array (e.g. kinematics, dynamics, circuits..etc.) and include the try/catch. . Then I can just call the method inside the actionListener and from there pass the values to the class to be calculated?

    My concern with doing it this way is that if I used a single method to check the JTF that it will include all the empty JTF's from each JPanel. So in other words, there would be the empty textfield for voltage, current, and resistors, when the user is actually just trying to to find acceleration.


    Also, when I tried to assign the empty JTF to unknown -- what type do I make it?

    calculate.addActionListener(new ActionListener(){
    			public void actionPerformed(ActionEvent ae){
     
                                for(int i = 0; i < kinematicsJT.length ; i++){
                                    if(kinematicsJT[i].getText().isEmpty()){
                                        String unknown = kinematicsJT[i];
                                    }
                                }
                                try{
    					/*double distanceI = Double.parseDouble(dI.getText());
    					double distanceF = Double.parseDouble(d0.getText());
    					double v0 = Double.parseDouble(velocityI.getText());
    					double v1 = Double.parseDouble(velocityF.getText());
    					double vA = Double.parseDouble(velocityAverage.getText());
    					double aA = Double.parseDouble(accelerationAverage.getText()); 
                                            */
    				} catch(NumberFormatException ex){
    					JOptionPane.showConfirmDialog(null, "Numbers Only");
    				}
    			}
    		});

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Testing double null

    user is actually just trying to to find acceleration.
    Would the actionlistener know what the user wants to find and be able to see if the required data has been entered in some textfields? If any required data is missing, issue an error message and go back to the user for correction.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Member
    Join Date
    Jan 2014
    Location
    Washington DC
    Posts
    81
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Testing double null

    My thinking was that, as you know, one equation with one unknown, so when the program executes the empty JTF would be assigned the unknown variable. The kinematic class contains the get/set methods, and those values that have been checked and parsed (check method) would be passed to a "calculation" method that contains if/else statements each containing the equations to solve for particular unknown.

    Screen Shot 2014-05-02 at 3.05.20 PM.jpg

    The logic makes sense, but the code is another story.

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Testing double null

    Where can a missing entry be detected? How can that information be passed to a method for processing?
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Member
    Join Date
    Jan 2014
    Location
    Washington DC
    Posts
    81
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Testing double null

    That's why I had if(kinematicsJT[i].getText().isEmpty()) so that it would then assign the empty JTF a variable "unknown". I would then use set method from kinematic class to assign the unknown in the kinematic class.

    Is any of what I'm talking about even possible, or am I heading down a dark path? I mean there must be a way for this to work.

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Testing double null

    If you passed wrapper class objects: Double vs double, the value could be null.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Member
    Join Date
    Jan 2014
    Location
    Washington DC
    Posts
    81
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Testing double null

    I have never used wrapper classes....but I was thinking, what if I assigned an integer number to an "unknown" variable depending on which JTF in the array was left blank. This would tell the switch/case statement in the kinematic class which equation to use for the calculation. May not be elegant but it should work..right?

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Testing double null

    What info do you need to pass to the method? What are the ways to pass it?
    If you use an object to pass a value to a method, then a value of null would show the data is missing.
    Another way would be to use a variable to flag which of the other variables have no value. For example a boolean array with true/false values for which variables are defined and which are not defined.
    callTheMethod(var1, var2, var3, boolArray);
    boolArray would have 3 elements corresponding to var1, var2 and var3
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Member
    Join Date
    Jan 2014
    Location
    Washington DC
    Posts
    81
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Testing double null

    Norm, I hope I am on the right path here...

    Method I created to check JTF and assign unknown. It's the only thing I could really understand and work with, so hopefully it's right. The calculate AL is just a rough draft to see if this approach will work and verify I can get a result. Problem, when I try to invoke the method using the kinematics object, this error shows up:
    HTML Code:
    cannot find symbol
      symbol:   method checkJTF(JTextField[])
      location: variable kinematics of type Kinematics
     public void checkJTF(JTextField[] a){
            for (int i = 0 ; i < a.length ; i++){
                if(a[i].getText().isEmpty()){
                    int unknown = i;
                    kinematics.setUnknown(unknown);
                }  
            }
        }

    Calculate ActionListener:

    calculate.addActionListener(new ActionListener(){
    			public void actionPerformed(ActionEvent ae){
    			    kinematics.checkJTF(kinematicsJT);                                     
                                try{
    				float distanceI = Float.parseFloat(dI.getText());
                                    kinematics.setDistanceI(distanceI);
    				double distanceF = Double.parseDouble(d0.getText());
    				double v0 = Double.parseDouble(velocityI.getText());
    				double v1 = Double.parseDouble(velocityF.getText());
    				double vA = Double.parseDouble(velocityAverage.getText());
    				double aA = Double.parseDouble(accelerationAverage.getText()); 
     
    				} catch(NumberFormatException ex){
    					JOptionPane.showConfirmDialog(null, "Numbers Only");
    				}
    			}
    		});

    Not sure why the float distance and float time would not work when I tried to use them in the equations.
    This is the switch/case I will use in the kinematic class:

    public Kinematics() {
            System.out.println(unknown);
            //float distance = distanceF - distanceI;
            //float time = timeF - timeI;
     
            if (unknown >= 0 && unknown <= 6) {
                switch (unknown) {
                    case 1:
                        velocityF = velocityI + acceleration * (timeF - timeI);
                    case 2:
                        distanceF = distanceI + ((velocityI + velocityF) / 2) * (timeF - timeI);
                    case 3:
                        velocityF = (float) Math.sqrt(velocityI * velocityI) + 2 * acceleration * (distanceF - distanceI);
                    case 4:
                        distanceF = (float) (velocityF * (timeF - timeI) + 0.5 * (acceleration * ((timeF - timeI) * (timeF - timeI))));
                    case 5:
                        velocityAverage = (distanceF - distanceI) / (timeF - timeI);
                }
            }
        }

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Testing double null

    cannot find symbol
    symbol: method checkJTF(JTextField[])
    The compiler can not find a definition for the method named in the error message. Where is that method define?
    Is it in scope where the code tries to use it?

    The code snippets don't show enough.
    If you don't understand my answer, don't ignore it, ask a question.

  19. #19
    Member
    Join Date
    Jan 2014
    Location
    Washington DC
    Posts
    81
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Testing double null

    This is both classes in their entirety. Hopefully this will work. Thanks a lot for help.

    package physicspractice;
     
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyEvent;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import javax.imageio.ImageIO;
    import javax.swing.*;
     
    public class Frame extends JFrame{
     
        //Objects 
        final Kinematics kinematics = new Kinematics();
     
        public Frame() throws IOException {
    		super("PhysAssist");
     
    		// Buttons
    		JButton kinematic = new JButton("Kinematic");
    		kinematic.setMnemonic(KeyEvent.VK_K);
    		JButton dynamics = new JButton("Dynamics");
    		dynamics.setMnemonic(KeyEvent.VK_D);
    		JButton power = new JButton("Power and Energy");
    		power.setMnemonic(KeyEvent.VK_E);
    		JButton wave = new JButton("Wave");
    		wave.setMnemonic(KeyEvent.VK_W);
    		JButton sound = new JButton("Sound");
    		sound.setMnemonic(KeyEvent.VK_S);
    		JButton circuit = new JButton("Circuit");
    		circuit.setMnemonic(KeyEvent.VK_C);
     
    		// Execute Buttons
    		JButton calculate = new JButton("Calculate");
    		calculate.setMnemonic(KeyEvent.VK_ENTER);
    		calculate.setFont(new java.awt.Font("Georgia", Font.BOLD, 16));
    		calculate.setForeground(Color.BLUE);
    		JButton back = new JButton("Back");
    		back.setMnemonic(KeyEvent.VK_ESCAPE);
    		back.setFont(new java.awt.Font("Georgia", Font.ITALIC, 16));
    		back.setForeground(Color.RED);
     
    		// Button Array Characteristics
    		final JButton[] buttonArray = { kinematic, dynamics, power, wave,
    				sound, circuit };
    		for (int i = 0; i < buttonArray.length; i++) {
    			buttonArray[i].setFont(new java.awt.Font("Georgia", Font.BOLD, 16));
    			buttonArray[i].setForeground(Color.darkGray);
    			buttonArray[i].setBackground(Color.GRAY);
    		}
     
    		// Panels
    		final JPanel mainPanel = new JPanel();
    		mainPanel.setLayout(new BorderLayout());
     
    		final JPanel executePanel = new JPanel();
    		executePanel.setLayout(new FlowLayout());
    		executePanel.add(back);
    		executePanel.add(calculate);
     
    		final JPanel sidePanel = new JPanel();
    		sidePanel.setLayout(new BorderLayout());
     
    		final JPanel buttonPanel = new JPanel();
    		buttonPanel.setLayout(new GridLayout(6, 1));
    		buttonPanel.setBackground(Color.DARK_GRAY);
     
    		// Kinematic Pane and Contents
    		final JPanel kinematicPane = new JPanel(new GridLayout(6, 2));
    		kinematicPane.add(new JLabel("Initial Distance"));
    		final JTextField dI = new JTextField();
    		kinematicPane.add(dI);
    		kinematicPane.add(new JLabel("Final Distance"));
    		final JTextField d0 = new JTextField();
    		kinematicPane.add(d0);
    		kinematicPane.add(new JLabel("Initial Velocity"));
    		final JTextField velocityI = new JTextField();
    		kinematicPane.add(velocityI);
    		kinematicPane.add(new JLabel("Final Velocity"));
    		final JTextField velocityF = new JTextField();
    		kinematicPane.add(velocityF);
    		kinematicPane.add(new JLabel("Average Velocity"));
    		final JTextField velocityAverage = new JTextField();
    		kinematicPane.add(velocityAverage);
    		kinematicPane.add(new JLabel("Acceleration"));
    		final JTextField accelerationAverage = new JTextField();
    		kinematicPane.add(accelerationAverage);
                    final JTextField [] kinematicsJT = {dI, d0, velocityI, velocityF,
                    velocityAverage, accelerationAverage};
     
     
     
    		// Dynamics Pane
    		final JPanel dynamicsPane = new JPanel(new GridLayout(6, 2));
    		dynamicsPane.add(new JLabel("Force"));
    		final JTextField force = new JTextField();
    		dynamicsPane.add(force);
    		dynamicsPane.add(new JLabel("Mass One"));
    		final JTextField massOne = new JTextField();
    		dynamicsPane.add(massOne);
    		dynamicsPane.add(new JLabel("Mass One"));
    		final JTextField massTwo = new JTextField();
    		dynamicsPane.add(massTwo);
    		dynamicsPane.add(new JLabel("Radius One"));
    		final JTextField radiusOne = new JTextField();
    		dynamicsPane.add(radiusOne);
    		dynamicsPane.add(new JLabel("Radius Two"));
    		final JTextField radiusTwo = new JTextField();
    		dynamicsPane.add(radiusTwo);
    		dynamicsPane.add(new JLabel("Normal Friction"));
    		final JTextField frictionNormal = new JTextField();
    		dynamicsPane.add(frictionNormal);
     
    		// Power, Work, Energy Pane
    		final JPanel powerPane = new JPanel(new GridLayout(7, 2));
    		powerPane.add(new JLabel("Work"));
    		final JTextField work = new JTextField();
    		powerPane.add(work);
    		powerPane.add(new JLabel("Energy"));
    		final JTextField energy = new JTextField();
    		powerPane.add(energy);
    		powerPane.add(new JLabel("Power"));
    		final JTextField powerP = new JTextField();
    		powerPane.add(power);
    		powerPane.add(new JLabel("Mass"));
    		final JTextField mass = new JTextField();
    		powerPane.add(mass);
    		powerPane.add(new JLabel("Initial Time"));
    		final JTextField timeOne = new JTextField();
    		powerPane.add(timeOne);
    		powerPane.add(new JLabel("Final Time"));
    		final JTextField timeTwo = new JTextField();
    		powerPane.add(timeTwo);
    		powerPane.add(new JLabel("Velocity"));
    		final JTextField velocity = new JTextField();
    		powerPane.add(velocity);
    		powerPane.add(new JLabel("Force"));
    		final JTextField powerForce = new JTextField();
    		powerPane.add(powerForce);
     
    		final JPanel wavePane = new JPanel();
     
    		final JPanel soundPane = new JPanel();
     
    		final JPanel circuitPane = new JPanel(new GridLayout(3, 2));
    		circuitPane.add(new JLabel("Voltage"));
    		final JTextField voltage = new JTextField();
    		circuitPane.add(voltage);
    		circuitPane.add(new JLabel("Current"));
    		final JTextField current = new JTextField();
    		circuitPane.add(current);
    		circuitPane.add(new JLabel("Resistance"));
    		final JTextField resistance = new JTextField();
    		circuitPane.add(resistance);
     
    		// Add Header to JFrame
    		/*final JPanel imagePanel = new JPanel();
    		imagePanel.setBackground(Color.DARK_GRAY);
    		BufferedImage bfimage = ImageIO.read(getClass().getResource(
    				"physicsImg.jpg"));
    		ImageLabel image = new ImageLabel(bfimage);
    		JLabel headerLabel = new JLabel(new ImageIcon(bfimage));
    		headerLabel.add(image);
    		imagePanel.add(headerLabel);
                    */
     
    		// Add button components and header
     
    		buttonPanel.add(kinematic);
    		buttonPanel.add(dynamics);
    		buttonPanel.add(power);
    		buttonPanel.add(wave);
    		buttonPanel.add(sound);
    		buttonPanel.add(circuit);
     
    		add(mainPanel);
    		//mainPanel.add(imagePanel, BorderLayout.CENTER);
    		mainPanel.add(buttonPanel, BorderLayout.SOUTH);
     
    		validate();
     
    		back.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent ae) {
    				for (int i = 0; i < buttonArray.length; i++) {
    					mainPanel.remove(buttonArray[i]);
    				}
    				mainPanel.remove(sidePanel);
    				mainPanel.add(buttonPanel, BorderLayout.SOUTH);
    				//mainPanel.add(imagePanel, BorderLayout.CENTER);
    				mainPanel.revalidate();
    				mainPanel.repaint();
    			}
    		});
     
    		calculate.addActionListener(new ActionListener(){
    			public void actionPerformed(ActionEvent ae){
    			    kinematics.checkJTF(kinematicsJT);                                     
                                try{
    				float distanceI = Float.parseFloat(dI.getText());
                                    kinematics.setDistanceI(distanceI);
    				float distanceF = Float.parseFloat(d0.getText());
    				float v0 = Float.parseFloat(velocityI.getText());
    				float v1 = Float.parseFloat(velocityF.getText());
    				float vA = Float.parseFloat(velocityAverage.getText());
    				float aA = Float.parseFloat(accelerationAverage.getText()); 
     
    				} catch(NumberFormatException ex){
    					JOptionPane.showConfirmDialog(null, "Numbers Only");
    				}
    			}
    		});
     
    		kinematic.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent ae) {
    				sidePanel.add(kinematicPane, BorderLayout.CENTER);
    				sidePanel.add(executePanel, BorderLayout.SOUTH);
    				mainPanel.add(buttonPanel, BorderLayout.WEST);
    				mainPanel.add(sidePanel, BorderLayout.CENTER);
    				//mainPanel.remove(imagePanel);
    				mainPanel.revalidate();
    				mainPanel.repaint();		
    			}
    		});
     
    		dynamics.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent ae) {
    				sidePanel.add(dynamicsPane, BorderLayout.CENTER);
    				sidePanel.add(executePanel, BorderLayout.SOUTH);
    				mainPanel.add(sidePanel, BorderLayout.CENTER);
    				mainPanel.add(buttonPanel, BorderLayout.WEST);
    				//mainPanel.remove(imagePanel);
    				mainPanel.revalidate();
    				mainPanel.repaint();
     
    				float f = Float.parseFloat(force.getText());
    				float m1 = Float.parseFloat(massOne.getText());
    				float m2 = Float.parseFloat(massTwo.getText());
    				float r1 = Float.parseFloat(radiusOne.getText());
    				float r2 = Float.parseFloat(radiusTwo.getText());
    				float fN = Float.parseFloat(frictionNormal.getText());
    			}
    		});
     
    		power.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent ae) {
    				sidePanel.add(powerPane, BorderLayout.CENTER);
    				sidePanel.add(executePanel, BorderLayout.SOUTH);
    				mainPanel.add(sidePanel, BorderLayout.CENTER);
    				mainPanel.add(buttonPanel, BorderLayout.WEST);
    				//mainPanel.remove(imagePanel);
    				mainPanel.revalidate();
    				mainPanel.repaint();
     
    				float w = Float.parseFloat(work.getText());
    				float e = Float.parseFloat(energy.getText());
    				float p = Float.parseFloat(powerP.getText());
    				float m = Float.parseFloat(mass.getText());
    				float t1 = Float.parseFloat(timeOne.getText());
    				float t2 = Float.parseFloat(timeTwo.getText());
    				float v = Float.parseFloat(velocity.getText());
    				float pF = Float.parseFloat(powerForce.getText());
    			}
    		});
     
    		wave.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent ae) {
    				sidePanel.add(wavePane, BorderLayout.CENTER);
    				sidePanel.add(executePanel, BorderLayout.SOUTH);
    				mainPanel.add(sidePanel, BorderLayout.CENTER);
    				mainPanel.add(buttonPanel, BorderLayout.WEST);
    				//mainPanel.remove(imagePanel);
    				mainPanel.revalidate();
    				mainPanel.repaint();
    			}
    		});
     
    		sound.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent ae) {
    				sidePanel.add(soundPane, BorderLayout.CENTER);
    				sidePanel.add(executePanel, BorderLayout.SOUTH);
    				mainPanel.add(sidePanel, BorderLayout.CENTER);
    				mainPanel.add(buttonPanel, BorderLayout.WEST);
    				//mainPanel.remove(imagePanel);
    				mainPanel.revalidate();
    				mainPanel.repaint();
    			}
    		});
     
    		circuit.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent ae) {
    				sidePanel.add(circuitPane, BorderLayout.CENTER);
    				sidePanel.add(executePanel, BorderLayout.SOUTH);
    				mainPanel.add(sidePanel, BorderLayout.CENTER);
    				mainPanel.add(buttonPanel, BorderLayout.WEST);
    				//mainPanel.remove(imagePanel);
    				mainPanel.revalidate();
    				mainPanel.repaint();
     
    				float volt = Float.parseFloat(voltage.getText());
    				float cI = Float.parseFloat(current.getText());
    				float rR = Float.parseFloat(resistance.getText());
    			}
    		});
     
        }
        public void checkJTF(JTextField[] a){
            for (int i = 0 ; i < a.length ; i++){
                if(a[i].getText().isEmpty()){
                    int unknown = i;
                    kinematics.setUnknown(unknown);
                }  
            }
        }
    }

    package physicspractice;
     
    public class Kinematics {
     
        float distanceI, distanceF, velocityI, velocityF,
                velocityAverage, acceleration, timeF, timeI;
        int unknown;
     
        public Kinematics() {
            System.out.println(unknown);
            //float distance = distanceF - distanceI;
            //float time = timeF - timeI;
     
            if (unknown >= 0 && unknown <= 6) {
                switch (unknown) {
                    case 1:
                        velocityF = velocityI + acceleration * (timeF - timeI);
                    case 2:
                        distanceF = distanceI + ((velocityI + velocityF) / 2) * (timeF - timeI);
                    case 3:
                        velocityF = (float) Math.sqrt(velocityI * velocityI) + 2 * acceleration * (distanceF - distanceI);
                    case 4:
                        distanceF = (float) (velocityF * (timeF - timeI) + 0.5 * (acceleration * ((timeF - timeI) * (timeF - timeI))));
                    case 5:
                        velocityAverage = (distanceF - distanceI) / (timeF - timeI);
                }
            }
        }
     
        public void setDistanceI(float distanceI) {
            this.distanceI = distanceI;
        }
     
        public void setDistanceF(float distanceF) {
            this.distanceF = distanceF;
        }
     
        public void setVelocityI(float velocityI) {
            this.velocityI = velocityI;
        }
     
        public void setVelocityF(float velocityF) {
            this.velocityF = velocityF;
        }
     
        public void setVelocityAverage(float velocityAverage) {
            this.velocityAverage = velocityAverage;
        }
     
        public void setAcceleration(float acceleration) {
            this.acceleration = acceleration;
        }
     
        public void setUnknown(int unknown) {
            this.unknown = unknown;
        }
     
        public int getUnknown() {
            return unknown;
        }
     
        public double getDistanceI() {
            return distanceI;
        }
     
        public double getDistanceF() {
            return distanceF;
        }
     
        public double getVelocityI() {
            return velocityI;
        }
     
        public double getVelocityF() {
            return velocityF;
        }
     
        public double getVelocityAverage() {
            return velocityAverage;
        }
     
        public double getAcceleration() {
            return acceleration;
        }
    }
    Last edited by javaStooge; May 2nd, 2014 at 04:36 PM. Reason: Change code

  20. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Testing double null

    I can not compile the post code without many compiler errors.
    Most are due to missing import statements.

    Can you make a small, complete program that shows the error. Not 30+ errors
    If you don't understand my answer, don't ignore it, ask a question.

  21. #21
    Member
    Join Date
    Jan 2014
    Location
    Washington DC
    Posts
    81
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Testing double null

    Quote Originally Posted by Norm View Post
    I can not compile the post code without many compiler errors.
    Most are due to missing import statements.

    Can you make a small, complete program that shows the error. Not 30+ errors
    I replaced the code with both classes as I have them. And it shows only the one error. hopefully the same for you.

  22. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Testing double null

    See post#18

    NOTE: Frame is the name of a Java SE class. It's better not to use names that conflict with Java SE class names.
    If you don't understand my answer, don't ignore it, ask a question.

  23. #23
    Member
    Join Date
    Jan 2014
    Location
    Washington DC
    Posts
    81
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Testing double null

    Alright I managed to fix the simple issue with the method by adding the static. I'm using a Sys.out to test the check method and it works when I print the value from within the method, but it will not pass the value to the kinematics class....

    Cruising down Java Highway hitting every pothole!

  24. #24
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Testing double null

    fix the simple issue with the method by adding the static
    That doesn't make sense with the code in post#19

    it will not pass the value to the kinematics class.
    Can you explain where the code is trying to pass a value to that class?
    If you don't understand my answer, don't ignore it, ask a question.

  25. #25
    Member
    Join Date
    Jan 2014
    Location
    Washington DC
    Posts
    81
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Testing double null

    I created the kinematics object from the Kinematics class --- within the checkJTF method (located at very bottom of Frame class)... kinematics.setUnknown

    By making the checkJTF method static in the Frame class, am I not able to call it within the class.

Page 1 of 2 12 LastLast

Similar Threads

  1. testing
    By neeraj bhatt in forum Java Theory & Questions
    Replies: 1
    Last Post: November 4th, 2012, 03:48 PM
  2. Java automated testing tools for Unit testing
    By rameezraja in forum Member Introductions
    Replies: 2
    Last Post: April 14th, 2012, 08:51 AM
  3. string==null or string.equals(null) problem
    By csharp100 in forum What's Wrong With My Code?
    Replies: 31
    Last Post: November 4th, 2011, 08:17 AM
  4. If Testing, testing for another if?
    By Rusticus in forum Loops & Control Statements
    Replies: 10
    Last Post: October 1st, 2011, 10:18 AM
  5. [SOLVED] Read double from console without having to read a string and converting it to double.
    By Lord Voldemort in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: June 26th, 2011, 08:08 AM