Java JoptionPane trying to get it to work for sepreate method with double x4 -


i trying program show grade , letter grade know mess need print netbean says joptionpane requires double, double, double, double

package garrett_sprunger_a5;  import java.text.decimalformat; import java.util.scanner; import javax.swing.joptionpane;  /**  *  * @author garrett */ public class garrett_sprunger_a5 {      /**      * @param args command line arguments      */     public static void main(string[] args) {         string inputstring;       // reader's input         double     testscore1,      //define testscore 1         testscore2,     //define testscore 2         testscore3,    //define testscore 3         averagescore; //define averagescore         scanner keyboard = new scanner(system.in); //to hold users grade                                                    // (somehow able use                                                    // keyboard can't                                                    // varible match correctly)         decimalformat formatter =                      new decimalformat("#,##0.0"); //format scores         scanner keyboard = new scanner(system.in);         inputstring=         joptionpane.showinputdialog("\t\nplease enter test score 1");         testscore1 = double.parsedouble(inputstring);         // input testscore2         inputstring=             joptionpane.showinputdialog("\t\nplease enter test score 2");         // convert input double         testscore2 = double.parsedouble(inputstring);         //input testscore3         inputstring=             joptionpane.showinputdialog("\t\nplease enter test score 3");         // convert input double         testscore3 = double.parsedouble(inputstring);         //calculate average score tests         averagescore = calcaverage(testscore1, testscore2, testscore3);         //averagescore = (averagescore +0.5);// applying midpoint roudning                                               // rule not needed formated                                              // rounding          //display average test score         {             if(testscore1 <0 && testscore1 >100)                 joptionpane.showmessagedialog(null, "please enter correct" +                                                 " data range between 0 , 100");         }         joptionpane.showmessagedialog(null, "\t\nyour test score 1  : "                                              + formatter.format(testscore1)                                               +"\t grade: "                                              + getlettergrade(testscore1)                                             + "\t\nyour test score 2  : "                                             + formatter.format(testscore2)                                               + "\t grade: "                                             + getlettergrade(testscore2)                                             + "\t\nyour test score 3  : "                                              + formatter.format(testscore3)                                              + "\t grade: "                                             + getlettergrade(testscore3)                                             + "\t\nyour average score : "                                             + formatter.format(averagescore)                                             + "\t grade: "                                             + getlettergrade(averagescore));     }//end main method      public static double calcaverage(double testscore1,                                 double testscore2, double testscore3  ) {         double averagescore = ((testscore1 + testscore2 + testscore3)/3);         return averagescore;     }      // determine letter grade      public static char getlettergrade(double testscore1,                 double testscore2,double testscore3, double averagescore) {         if (averagescore >=90) {             return 'a';         } else if (averagescore >= 70 && averagescore < 90) {             if (testscore3 > 90)                 return 'a';         } else             return 'b';          if(averagescore >=50 && averagescore <70) {             if(((testscore2 + testscore3)/2.0) > 70)                 return 'c';         } else              return 'd';         if (averagescore < 50)             return 'f';            else                 return '0';     }      public static void displaygrade( double averagescore,                             double testscore1, double testscore2,                             double testscore3, char getlettergrade) {         decimalformat formatter = new decimalformat("#,##0.0");         joptionpane.showmessagedialog(null, "\t\nyour test score 1  : " +                                              formatter.format(testscore1)  +                                             "\t grade: " + getlettergrade(                                             testscore1) +                                             "\t\nyour test score 2  : " +                                              formatter.format(testscore2)  +                                             "\t grade: " + getlettergrade(                                             testscore2) +                                             "\t\nyour test score 3  : " +                                             formatter.format(testscore3)  +                                             "\t grade: " + getlettergrade(                                             testscore3) +                                             "\t\nyour average score : " + formatter.format(averagescore)+                                             "\t grade: " + getlettergrade(                                             averagescore));     } } 

i suggest change getlettergrade() method resembles this:

public static char getlettergrade(double testscore) {     if (testscore >= 90) {         return 'a';     }     else if (testscore >= 80) {         return 'b';     }     //continue using if statements determine letter grade } 

note method above has 1 parameter, double testscore, should more helpful inputing 4 doubles @ once.

would point out if statement in code never run. should easy figure out why:

if(testscore1 <0 && testscore1 >100)             joptionpane.showmessagedialog(null, "please enter correct data range between 0 , 100"); 

Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -