This site requires JavaScript, please enable it in your browser!
Greenfoot back
divinity
divinity wrote ...

2017/10/17

class or method

1
2
3
danpost danpost

2017/11/2

#
divinity wrote...
how can i fix that, is there a way to fix it.
You could use (2, 2, 3) instead of (1, 2, 3), for example.
divinity divinity

2017/11/2

#
 public double doublearea(double side2, double side2, double side3){
         
            double s;
            double area;
            
            s = (2 + 2 +3)/2;
            area = Math.sqrt(s *(s - 1) * (s - 2) * (s - 3));
            
            return area;
        }
divinity divinity

2017/11/2

#
I am getting an error saying: variable here is the error
variable side2 is already defined in method doublearea(double,double,double)
on line 1
danpost danpost

2017/11/2

#
Do not change the name of your variables -- you only want to change the value(s). Change line 1 back to what you had. You need to change the (1, 2, 3) in the 'actionPerformed' method and then convert the literals '1', '2' and '3' in the 'doubleArea' method (old line 6) to the appropriate parameter variable names.
divinity divinity

2017/11/2

#
hi danpost I tried testing out the calculation on a area calculator on a webpage: the number used is: 3, 4, 3, the answer i got was: 4.47213595499958 Square Units but when i tested it on my calculator, the answer i got was this: 2.5617376914898995 I tried another set of numbers and ah got is: testing numbers is 5,6,7, answer ah got is;14.696938456699069 Square Units but when I used the same number of my calculator is ah got this; 2.5617376914898995, which is the exact same answer from the first test. then something is again off
danpost danpost

2017/11/2

#
Ah... improvement -- you are now getting non-zero output. That is a plus. Show you revised 'doublearea' method for review.
divinity divinity

2017/11/2

#
here it is. tell me where else that need fixing
@Override
    public void actionPerformed(ActionEvent ae) {

        double A = Double.parseDouble(side1.getText());
        double B = Double.parseDouble(side2.getText());
        double C = Double.parseDouble(side3.getText());
        
        double area=  doublearea(2, 2, 3);        
        displayArea.setText( area +"");

    }
        
        public double doublearea(double side1, double side2, double side3){
         
            double s;
            double area;
            
            s = (side1 + side2 + side3)/2;
            area = Math.sqrt(s *(s - 1) * (s - 2) * (s - 3));
            
            return area;
        }
       
     /*  public static  boolean isvalid(double side1, double side2, double side3) {
        
        return (side1 + side2 > side3 && side1 + side3 > side2 && side2 + side3 > side1); 
        
   }*/
    
    public static  void main(String[] args) {

        HeronFormulaCalculator hfc = new HeronFormulaCalculator();
        hfc.setBounds(300, 300, 350, 250);
        hfc.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
danpost danpost

2017/11/2

#
You are still using '1', '2' and '3' in lines 19.
divinity divinity

2017/11/2

#
hi danpost I change it to
  double s;
            double area;
            
            s = (side1 + side2 + side3)/2;
            area = Math.sqrt(s *(s - side1) * (s -side2) * (s - side3));
            
            return area;
and when ah test it again the answer ah got is 1.984313483298443 when the real is is supposed to be 4.4721
danpost danpost

2017/11/2

#
With that result, I would say that you are using (2, 2, 3) in your calculations. Make sure your 'actionPerformed' method is not overriding the values you give for the sides.
divinity divinity

2017/11/2

#
so wat do u think ah shud do and how to fix it
danpost danpost

2017/11/2

#
divinity wrote...
so wat do u think ah shud do and how to fix it
Call 'doublearea' with the correct values (using the right variables) in the 'actionPerformed' method.
divinity divinity

2017/11/3

#
hi danpost I tried putting side1, side2, side3 in the doublearea actionperformed method but was getting an error saying: incompatible types: JTextField cannot be converted to double
Super_Hippo Super_Hippo

2017/11/3

#
In the class, side1, side2 and side3 are JTextField objects while the ones with the same name in the doublearea method are doubles. Maybe you want to get the value in the text field and not the text field itself. In the actionPerformed method, you get A, B and C. Try to use them as parameters.
divinity divinity

2017/11/3

#
IHi danpost and super_hippo I got it. I change the doublearea(1, 2, 3) to doublearea(A, B,C) the value that is being collected thank you guys for all of the help
You need to login to post a reply.
1
2
3