0
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         
       
    double grades;
    grades= Double.parseDouble(comprogGrds .getText())+Double.parseDouble (dsGrds .getText())+ Double.parseDouble (cwGrds.getText())+ Double.parseDouble(multGrds.getText())/4;
        
    if(grades>=90){
        average.setText(Double.toString(grades));
    }else if(grades>=78 && grades<=79){
      average.setText(Double.toString(grades));
    }else if(grades>=74 && grades <=75){
       average.setText(Double.toString(grades));
    }
                
}
maloomeister
  • 2,461
  • 1
  • 12
  • 21
Rose
  • 11
  • 1
  • Please, describe what exactly you have problems with, what result you get and how this differs from your expected result. For more information, read [ask]. So please [edit] your question to add more text describing your problem. – maloomeister Jul 06 '22 at 12:24
  • 1
    Looks like you might have a [PEMDAS](https://en.wikipedia.org/wiki/Order_of_operations) problem. – Paul Samsotha Jul 06 '22 at 12:29
  • This question would be better if phrased "Why are my numbers not dividing as I expected?" and it can be answered by learning about Java operators and order of operations. Nonetheless I have supplied an answer. – Blue Dev Jul 06 '22 at 14:56
  • 1
    More [here](https://stackoverflow.com/q/2137690/230513). – trashgod Jul 06 '22 at 15:15

1 Answers1

2

You've just missed a set of parentheses. You're currently only dividing the final number by 4. Try instead the following.

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         
       
    double grades;
    grades= (Double.parseDouble(comprogGrds .getText())+Double.parseDouble (dsGrds .getText())+ Double.parseDouble (cwGrds.getText())+ Double.parseDouble(multGrds.getText()))/4;
        
    if(grades>=90){
        average.setText(Double.toString(grades));
    }else if(grades>=78 && grades<=79){
      average.setText(Double.toString(grades));
    }else if(grades>=74 && grades <=75){
       average.setText(Double.toString(grades));
    }
                
}

As an explanation, if you have double result = 3+6+9+2/4;, you will end up with 3+6+9+(2/4). To fix this, a set of parentheses will suffice. double result = (3+6+9+2)/4;

Blue Dev
  • 142
  • 8
  • 1
    thank you everyone it is already work. thank you so muchhh Godbless to all. – Rose Jul 06 '22 at 16:08
  • @Rose if you're satisfied with an answer, be sure to mark it as accepted (the check mark by the upvote) so this question can be closed. – Blue Dev Jul 06 '22 at 19:57