# Most of my code works when executed except for the Min and Max calculations

• December 5th, 2012, 02:50 PM
Baboop
Most of my code works when executed except for the Min and Max calculations
Everything works exactly like its suppose to but when its suppose to show the max and min values out of the 3 numbers, it just returns 0.

Code Java:

```//23.4 import java.awt.Graphics; import javax.swing.JApplet; import javax.swing.JOptionPane;   public class Comparisons extends JApplet { public double sum; public double average; public double product; public double smallest; public double largest; public double minimumValue; public double maximumValue;   public void init() { String firstNumber = JOptionPane.showInputDialog( "Enter the first floating-point value" );   String secondNumber = JOptionPane.showInputDialog( "Enter the second floating-point value" );   String thirdNumber = JOptionPane.showInputDialog( "Enter the third floating-point value" );   double number1 = Double.parseDouble( firstNumber ); double number2 = Double.parseDouble( secondNumber ); double number3 = Double.parseDouble( thirdNumber );   sum = number1 + number2 + number3;   average = (number1 + number2 + number3) / 3;   product = number1 * number2 * number3;   } public static double minimum( double number1, double number2, double number3 ) { double minimumValue = number1;   if( number2 < minimumValue ) minimumValue = number2;   if( number3 < minimumValue ) minimumValue = number3; return minimumValue; } public static double maximum(double number1, double number2, double number3) { double maximumValue = number1;   if( number2 > maximumValue ) maximumValue = number2; if( number3 > maximumValue ) maximumValue = number3; return maximumValue; } public void paint(Graphics g) { super.paint(g);   g.drawRect(15, 10, 270, 20);   g.drawString("The sum is " + sum, 25, 25);   g.drawRect(15, 30, 270, 20);   g.drawString("The average is: " + average, 25, 45);   g.drawRect(15, 50, 270, 20);   g.drawString("The product is " + product, 25, 63);   g.drawRect(15, 70, 270, 20);   g.drawString("The smallest value is " + minimumValue, 25, 83);   g.drawRect(15, 90, 270, 20);   g.drawString("The largest value is " + maximumValue, 25, 103);   }   }```
• December 5th, 2012, 03:01 PM
Norm
Re: Most of my code works when executed except for the Min and Max calculations
Where does the code set the value of the variables to the max or min values?
Is the code where that happens executed?
Add a call to the println method to print a message when the methods are executed to see if they are in fact executed. If nothing prints, that would say the method is NOT executed. If the method is not executed the values of the variables won't be changed.
• December 5th, 2012, 03:10 PM
Baboop
Re: Most of my code works when executed except for the Min and Max calculations
yes it executes but it just says the min value is 0 and the max value is 0
• December 5th, 2012, 03:27 PM
Norm
Re: Most of my code works when executed except for the Min and Max calculations
Did you add the println call in the methods where the min and max variables are given values?
Was anything printed?
If nothing prints, that would say the method is NOT executed. If the method is not executed the values of the variables won't be changed and will still be 0.
• December 5th, 2012, 03:40 PM
Baboop
Re: Most of my code works when executed except for the Min and Max calculations
even with the println call it still says the max and min are both 0.
• December 5th, 2012, 03:53 PM
Norm
Re: Most of my code works when executed except for the Min and Max calculations
The println statements won't change the values of min and max. They are to tell you if the methods are executed.
Was anything printed?
If nothing prints, that would say the method is NOT executed. If the method is not executed the values of the variables won't be changed and will still be 0.

--- Update ---

The println statements won't change the values of min and max. They are to tell you if the methods are executed.
Was anything printed?
If nothing prints, that would say the method is NOT executed. If the method is not executed the values of the variables won't be changed and will still be 0.

--- Update ---

The println statements won't change the values of min and max. They are to tell you if the methods are executed.
Was anything printed?
If nothing prints, that would say the method is NOT executed. If the method is not executed the values of the variables won't be changed and will still be 0.

--- Update ---

The println statements won't change the values of min and max. They are to tell you if the methods are executed.
Was anything printed?
If nothing prints, that would say the method is NOT executed. If the method is not executed the values of the variables won't be changed and will still be 0.
• December 5th, 2012, 03:56 PM
Baboop
Re: Most of my code works when executed except for the Min and Max calculations
it printed "The smallest value is 0" for the min and "The largest value is 0" for the max.
• December 5th, 2012, 03:59 PM
Norm
Re: Most of my code works when executed except for the Min and Max calculations
Did you add some new printlns to all the methods as I requested earlier in post#2?

Did any of them print out a message?

Add this to all the methods in the code:
Code :

`System.out.println("in <name of method here> ");`
• December 5th, 2012, 04:00 PM
Baboop
Re: Most of my code works when executed except for the Min and Max calculations
i only added the println to the min and max because those are the only two that aren't working properly.
• December 5th, 2012, 04:03 PM
Norm
Re: Most of my code works when executed except for the Min and Max calculations
Did you add some new printlns to all the methods as I requested earlier in post#2?

Did any of them print out a message?

Add this to all the methods in the code:
Code :

`System.out.println("in <name of method here> ");`

--- Update ---

Please post the code that shows where you added the new println statements.