java - public static methods return issues -


i have created text.file user adds values to. part users data gets read , validated. struggle when user add values when prompted to, not return data. shows zeroes. must not returning values somewhere.

here directions section.

"ask user if there more amounts add not in text file.  ifso:  use static methods read , validate amount type , amount  use instance method add amount 1 of totals"

and here have far. direction , help.

public static char readvalidateamounttype() {      system.out.println("enter amount type(t, d, e) enter: ");     scanner keyboard = new scanner(system.in);         char amounttype = keyboard.next().charat(0);         amounttype = character.touppercase(amounttype);                         {                 if(amounttype !='t' && amounttype !='d' && amounttype !='e')                  {                      system.out.println("invalid amount type!");                      system.out.println("enter amount type(t, d, e) enter: ");                     amounttype = keyboard.next().charat(0);                     amounttype = character.touppercase(amounttype);                 }                 else                 {                     return amounttype;                 }                 }             while(amounttype !='t' && amounttype !='d' && amounttype !='e');             return amounttype;     }  public static double readvalidateamount() {     scanner keyboard = new scanner(system.in);     system.out.println("please enter dollar amount: ");     amount = keyboard.nextdouble();     if(amount <=0)     {                 {                    system.out.println("invalid amount!");             system.out.println("please enter dollar amount: ");             amount = keyboard.nextdouble();         }         while(amount <=0);         return amount;     }     else     {         return amount;     } 

the main:

  public static void main (string[] args) throws ioexception {     henwoodeventclass event = new henwoodeventclass();     system.out.println("this program tell financial details of"             + " event. \nand allow change or add input.\n\n");      string userfile = "event.txt";     try      {         file inputfile = new file (userfile);          scanner checkfile = new scanner (inputfile);          if(checkfile.hasnextline())         {             while (checkfile.hasnextline())             {                 try                 {                     system.out.println(checkfile.nextline());                     }                 catch (illegalargumentexception exception)                 {                        system.out.println("does not exist!");                 }                }             checkfile.close();                 event.gettotalticketsales();              event.gettotalmoneydonated();              event.gettotalexpenses();         }             system.out.println("are ther anymore amounts add not in textfile?: ");             scanner keyboard = new scanner(system.in);             char choice = keyboard.next().charat(0);             choice = character.touppercase(choice);                                  {                     if(choice == 'y')                     {                         readvalidateamounttype();                         readvalidateamount();                          system.out.println("are ther anymore amounts add not in textfile?: ");                         choice = keyboard.next().charat(0);                         choice = character.touppercase(choice);                     }                     event.displayfinalresults();                 }                 while(choice =='y');             }     catch (filenotfoundexception exception)      {            system.out.println("file "+ userfile +" not exist!\n\n");       } } 

}

try double.parsedouble(keyboard.nextline()); instead of nextdouble() , replace next() nextline().

see: by default, scanner uses white space separate tokens.


Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -