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 2 of 2 FirstFirst 12
Results 26 to 49 of 49

Thread: Testing double null

  1. #26
    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

    You'll have to post the code. I don't understand what you have done with the checkJTF method.
    It looked like it was ok where it was located, in the same class where the code was trying to call it. Just call the method as a local class, not as a method in another class.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Testing double null

    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.IOException;
    import javax.imageio.ImageIO;
    import javax.swing.*;
     
    public class Frame extends JFrame {
    		final static 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) {
    				Frame.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.showMessageDialog(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());
    			}
    		});
    		//System.out.println(kinematics.getDistanceI());
    	}
     
    	public static void checkJTF(JTextField[] a) {
    		for (int i = 0; i < a.length; i++) {
    			if (a[i].getText().isEmpty()) {
    				int unknown = i;
    				System.out.println(unknown);
    				kinematics.setUnknown(unknown);
    			}
    		}
    	}
    }

    I have tried several different ways to print out the correct value in the following class..but I keep getting the same result.

    public class Kinematics {
    	float distanceI, distanceF, velocityI, velocityF,
        velocityAverage, acceleration, timeF, timeI;
    	private static int unknown;
    	public Kinematics(){
     
    		System.out.println(unknown);
    		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 dI){
    			distanceI = dI;
    		}
    		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 float getDistanceI(){
    			return distanceI;
    		}
    		public float getDistanceF(){
    			return distanceF;
    		}
    		public float getVelocityI(){
    			return velocityI;
    		}
    		public float getVelocityF(){
    			return velocityF;
    		}
    		public float getVelocityAverage(){
    			return velocityAverage;
    		}
    		public float getAcceleration(){
    			return acceleration;
    		}
    }
    Last edited by javaStooge; May 2nd, 2014 at 11:15 PM.

  3. #28
    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 happens without the static attribute? Treat the method as a normal local method.


    NOTE: Frame is the name of a java SE class.

    I keep getting the same result.
    Please explain and show some examples.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Testing double null

    If I remove the static from checkJTF then I get an error: Cannot make a static reference to the non-static method checkJTF(JTextField[]) from the type Frame

    For this code in the kinematic class:
    	public  void setUnknown(int unknown) {
    	        this.unknown = unknown;
    	    }

    I get the following error: The static field Kinematics.unknown should be accessed in a static way

    Then if I do the auto fix provided by eclipse it changes to :
    	public  void setUnknown(int unknown) {
    	        Kinematics.unknown = unknown;
    	    }

  5. #30
    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

    That method: setUnknown should be a normal method in the Kinematics class

    Look at post#19. Why did you change that?
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Testing double null

    It is in the Kinematics class...? I put all my get/set methods in the kinematics class.

    I used them in the Frame class in order to pass the unknown variable into the Kinematics class

  7. #32
    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

    ??? The setUnknown method is in the Kinematics class.

    NOTE: Frame is the name of a java SE class.
    If you don't understand my answer, don't ignore it, ask a question.

  8. #33
    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
    ??? The setUnknown method is in the Kinematics class.
    You can see from my code that the setUnknown method is in my Kinematics class where it should be.

  9. #34
    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 don't know what the last posts were about. From the snippets of code that were posted I could not tell where the method was being defined.
    Why is there a static variable?

    Does it compile now?
    Post the errors if not.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Testing double null

    Yes the code does compile without any errors, but the value is not being passed to the Kinematic class when I invoke the setUnknown method. It prints out the default value of 0 from the Syst.out at the top of the Kinematics class. But when I print out the value from within the method it returns location of the empty field from the array. For instance, if I leave kinematicsJT[2] empty, it will print 1 from within the method.

    The only thing I can conclude is that setUknown is not passing value.

    (Code posted in post #27)

    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.IOException;
    import javax.imageio.ImageIO;
    import javax.swing.*;
     
    public class PhysicsFrame extends JFrame {
    		final static Kinematics kinematics = new Kinematics();
     
    	public PhysicsFrame() 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) {
    				PhysicsFrame.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.showMessageDialog(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());
    			}
    		});
    		//System.out.println(kinematics.getDistanceI());
    	}
     
    	static void checkJTF(JTextField[] a) {
    		for (int i = 0; i < a.length; i++) {
    			if (a[i].getText().isEmpty()) {
    				int unknown = i;
    				System.out.println(unknown);
    				kinematics.setUnknown(unknown);
    			}
    		}
    	}
    }

    public class Kinematics {
    	float distanceI, distanceF, velocityI, velocityF,
        velocityAverage, acceleration, timeF, timeI;
    	int unknown;
    	public Kinematics(){
    		System.out.println(unknown);
     
    		if (unknown >= 0 && unknown <= 5) {
                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 dI){
    			distanceI = dI;
    		}
    		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 float getDistanceI(){
    			return distanceI;
    		}
    		public float getDistanceF(){
    			return distanceF;
    		}
    		public float getVelocityI(){
    			return velocityI;
    		}
    		public float getVelocityF(){
    			return velocityF;
    		}
    		public float getVelocityAverage(){
    			return velocityAverage;
    		}
    		public float getAcceleration(){
    			return acceleration;
    		}
    }
    Last edited by javaStooge; May 3rd, 2014 at 09:26 AM.

  11. #36
    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

    setUknown is not passing value.
    Try doing some debugging by adding println statements just before where setUnknown is called to print out the value that is being passed. Then print out the value in the getUnknown method when it is returned.

    Note when printing the values of variables for debugging it is important to add a unique ID String before the variable so you can tell which println printed the value. For example:
    System.out.println("a unique ID "+ theVariableHere);
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Testing double null

    Norm, the getUnknown method doesn't matter if it's not setting the correct value to begin with.

    This code isn't going to work is it? I think I just need to start over and find a new way to make the calculation. The switch/case isn't going to work.

  13. #38
    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

    There are several println() statements in the code. What do they print out?
    Make sure to add an id String so you can tell where it was printed.

    Also add a println after the switch statement executes that prints out the values of all the variables that are calculated in the switch statement.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Testing double null

    Screen Shot 2014-05-03 at 11.41.26 AM.jpg
    checkJTF is the println in the checkJTF method.
    Kinematics is the println in the kinematics class.

    These are the values that result from leaving the last field in the kinematics JT blank.

    I think I see what you were hinting at with printing the results. There isn't a way, that I'm aware of, to specify which result (calculation) was printed.

  15. #40
    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

    The values of all the variables should be printed:
    distanceI, distanceF, velocityI, velocityF, velocityAverage, acceleration, timeF, timeI

    The console shows that the code was executed in the constructor BEFORE the call to setUnknown().
    The switch statement should be in code that is called AFTER the setUnknown() method is called because that is when the value of unknown is set.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Testing double null

    I see what you mean that the code for the kinematic class executes before the setUnknown, but I don't see why that is the case. I've placed the checkJTF method before the try/catch block.
    Why is the kinetmatic class doing anything before the PhysicsFrame? I have not called the kinematics class to do anything except in the checkJTF method.

    Does it have something to do with the catch statement? If I input values for all the fields, then it will print out the values after they've been parsed. BUT there is no empty field for which to assign the unknown variable in this case. And if I leave a field blank, try never executes and the catch error comes up because it does not accept the empty JTF.

    Yet, what I really don't understand is that it should still pass the unknown regardless of the try/catch block..

  17. #42
    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

    Why is the kinetmatic class doing anything before the PhysicsFrame
    This calls the constructor:
    final Kinematics kinematics = new Kinematics();
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Testing double null

    I took a detour from the direction I was heading in the program and decided to add the contents of the kinematics class to PhysicsFrame. I removed the object I was trying to use which I'm still not entirely sure why it calls the contents of Kinematics. Anyways, the calculations are processing, so I think I'm just going to write all of the code for the calculations within the PhysicsFrame class. The reason I wanted to separate each topic into classes was to keep things organized. Once I figure out how to process the correct calculation and print the result to a JPanel...it will mostly be repetition for the other topics. Please tell me if you see issues before I get too far gone. I don't have a lot of time to work on this program.

    --- Update ---

    Its going to be a very long code, but do you notice any problems that might occur with this? I think its going be be necessary for me to remove the veclocityAverage because I will also have a velocityI and velocityF and it will result in too many empty JTF's.

    NOTE: I copied all the code from Eclipse to NetBeans while the class was still called Frame, so I would have a place to test/practice the code--that is what you see. The original code does not have the Frame class anymore.

    calculate.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent ae) {
    				Frame.checkJTF(kinematicsJT);
    				if(unknownVar >= 0 && unknownVar <= 6){
                                    try {
    					float distanceI = Float.parseFloat(dI.getText());
    					Frame.setDistanceI(distanceI);
    					float distanceF = Float.parseFloat(d0.getText());
    					Frame.setDistanceF(distanceF);
    					float v0 = Float.parseFloat(velocityI.getText());
    					Frame.setVelocityI(v0);
    					float v1 = Float.parseFloat(velocityF.getText());
    					Frame.setVelocityF(v1);
    					float vA = Float.parseFloat(velocityAverage.getText());
    					Frame.setVelocityAverage(vA);
    					float aA = Float.parseFloat(accelerationAverage.getText());
    					Frame.setAcceleration(aA);
                                            calcKinematic(getUnknown());
     
    				} catch (NumberFormatException e) {
    					JOptionPane.showMessageDialog(null, "Numbers Only");
    				}
                                }
                                    Frame.checkJTF(dynamicsJT);
                                    if(unknownVar >=7 && unknownVar <= 13){
                                        try{
                                            float f = Float.parseFloat(force.getText());
    				float m1 = Float.parseFloat(massOne.getText());
                                    Frame.setMassOne(m1);
    				float m2 = Float.parseFloat(massTwo.getText());
                                    Frame.setMassTwo(m2);
    				float r1 = Float.parseFloat(radiusOne.getText());
                                    Frame.setRadiusOne(r1);
    				float r2 = Float.parseFloat(radiusTwo.getText());
                                    Frame.setRadiusTwo(r2);
    				float fN = Float.parseFloat(frictionNormal.getText());
                                    Frame.setFrictionNormal(fN);
                                        }catch(NumberFormatException e){
                                            JOptionPane.showMessageDialog(null, "Numbers Only");
                                        }
     
                                    }
                                    Frame.checkJTF(powerJT);
                                    if(unknownVar >=14 && unknownVar <= 22){
     
                                    }
                           }
    		});
     
    		kinematic.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent ae) {
    				sidePanel.add(kinematicPane, BorderLayout.CENTER);
    				sidePanel.add(executePanel, BorderLayout.SOUTH);
    				combinationPanel.add(buttonPanel);
    				combinationPanel.add(resultPanel);
    				mainPanel.add(combinationPanel, 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();
    			}
    		});
     
    		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());
    			}
    		});
    		// System.out.println(kinematics.getDistanceI());
    	}
     
    	static void checkJTF(JTextField[] a) {
    		for (int i = 0; i < a.length; i++) {
    			if (a[i].getText().isEmpty()) {
                                    int unknownVar = i;
    				Frame.setUnknown(unknownVar);
    				System.out.println("checkJTF: " + unknownVar);
                                    a[i].setText("0");
    			}
    		}
    	}
    	//Set/Get Stuff
    	public static void setDistanceI(float dI){
    		distanceI = dI;
    	}
    	public static void setDistanceF(float dF){
    		distanceF = dF;
    	}
    	public static void setVelocityI(float vI){
    		velocityI = vI;
    	}
    	public static void setVelocityF(float F){
    		velocityF = F;
    	}
    	public static void setVelocityAverage(float vAverage){
    		velocityAverage = vAverage; 
    	}
    	public static void setAcceleration(float accel){
    		acceleration = accel;
    	}
            public static void setMassOne(float m1){
                massOne = m1;
            }
            public static void setMassTwo(float m2){
                massTwo = m2;
            }
            public static void setRadiusOne(float r1){
                radiusOne = r1;
            }
             public static void setRadiusTwo(float r2){
                radiusTwo = r2;
            }
              public static void setFrictionNormal(float fn){
                frictionNormal = fn;
            }
    	public static void setUnknown(int unknown) {
                    unknownVar = unknown;
        }
     
     
        public int getUnknown() {
            return unknownVar;
        }
     
            public static void calcKinematic(int unknown){
     
                if (unknown >= 0 && unknown <= 7) {
                switch (unknown) {
                    case 0://velocifyF
                        result = velocityI + acceleration * (timeF - timeI);
                        System.out.println("Case 0");
                        System.out.println("VerifyAcceleraion : " + acceleration);
                        System.out.println("VerifyVelocity : " + velocityI);
     
                        break;
                    case 4: //distanceF
                        result = distanceI + ((velocityI + velocityF) / 2);
                        System.out.println("VerifyVelocity : " + velocityI);
                        System.out.println("Case 4");
                        //System.out.println("Calculation: " +(distanceI + ((velocityI + velocityF) / 2)));
                        System.out.println("Result: " + result);
                        break;
                    case 3://velocityF
                        result = (float) Math.sqrt(velocityI * velocityI) + 2 * acceleration * (distanceF - distanceI);
                                System.out.println("VerifyRestult" + result);
                                System.out.println("VerifyVelocity : " + velocityI);
                                System.out.println("Case 3");
                        break;
                    case 2: //distanceF
                        result = (float) (velocityF * (timeF - timeI) + 0.5 * (acceleration * ((timeF - timeI) * (timeF - timeI))));
                        System.out.println("Case 2");
                        System.out.println("Restult" + result);
                        break;
                    case 5: //velocityAverage
                        result = (distanceF - distanceI) / (timeF - timeI);
                        System.out.println("Case 5");
                        break;
                    }
     
                }
            }
     
            public static void calcDynamics(int unknown){
                if(unknown >= 7 && unknown <= 13){
                    switch(unknown){
                        case 6: //
                        case 7:
                        case 8:
                        case 9:
                        case 10:
                        case 11:
                        case 12:
                    }
                }
            }
            public static void calcPower(int unknown){
                if(unknown >= 14 && unknown <= 22){
                    switch(unknown){
                        case 14: //
                        case 15:
                        case 16:
                        case 17:
                        case 18:
                        case 19:
                        case 20:
                        case 21:
                        case 22: 
     
                    }
                }
            }
    Last edited by javaStooge; May 4th, 2014 at 09:49 AM.

  19. #44
    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

    Its going to be a very long code
    Before typing in tons of code, I suggest making small prototypes with a couple of text fields to see how your design will work out.
    If you don't understand my answer, don't ignore it, ask a question.

  20. #45
    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
    Before typing in tons of code, I suggest making small prototypes with a couple of text fields to see how your design will work out.
    Yes, thank you. I've spent what feels like days on this code and researching different methods to complete the task...
    I see issues in the code, but I could use some direction on how to fix them.
    In this code, I know that I have equations set up to solve the same variable, but the equations have different data to solve for the same unknown, velocityF in this case.
    I mean, as you know, you can manipulate these equations a million different ways to get the desired variable, depending on what data you have. I really don't know how to do get around this.

    case 0://velocifyI
                        result = velocityF - acceleration * (timeF - timeI);
                        System.out.println("Case 0");
                        System.out.println("VerifyAcceleraion : " + acceleration);
                        System.out.println("VerifyVelocityI : " + velocityI);
     
                        break;
                    case 1: //distanceF
                        result = distanceI + ((velocityI + velocityF) / 2);
                        System.out.println("VerifyVelocity : " + velocityI);
                        System.out.println("Case 4");
                        //System.out.println("Calculation: " +(distanceI + ((velocityI + velocityF) / 2)));
                        System.out.println("Result: " + result);
                        break;
                    case 3://velocityF
                        result = (float) Math.sqrt(velocityI * velocityI) + 2 * acceleration * (distanceF - distanceI);
                                System.out.println("VerifyRestult" + result);
                                System.out.println("VerifyVelocity : " + velocityI);
                                System.out.println("Case 3");
                        break;
                    case 2: //distanceF
                        result = (float) (velocityF * (timeF - timeI) + 0.5 * (acceleration * ((timeF - timeI) * (timeF - timeI))));
                        System.out.println("Case 2");
                        System.out.println("Restult" + result);
                        break;
                    case 5: //velocityAverage
                        result = (distanceF - distanceI) / (timeF - timeI);
                        System.out.println("Case 5");
                        break;
                    }

  21. #46
    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

    Reduce the code to a few case statements with a couple of statements. In other words make a small, simple prototype for developing the design.
    If you don't understand my answer, don't ignore it, ask a question.

  22. #47
    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
    Reduce the code to a few case statements with a couple of statements. In other words make a small, simple prototype for developing the design.
    Okay, I got it. I won't proceed any further until I've figured out the calculation issue with kinematics. That still doesn't help me figure out the issue with the variables.

  23. #48
    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

    Make a small, complete example that compiles, execute and shows the problem.

    issue with the variables.
    Be sure to show what the problem is there.

    Same project? http://www.java-forums.org/new-java/...alculator.html
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Testing double null

    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; May 5th, 2014 at 12:56 AM.

Page 2 of 2 FirstFirst 12

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