Read multiple data types from txt file into arrayList - Java -


for program i'm supposed read txt file containing information on automobile's make, model, mpg, , trunk space in order. example is: hyundai genesis 24.6 100 , repeated several different cars. had construct "automobile" superclass instance variables of make , model. "gasengineauto" subclass instance variable mpg extends "automobile". subclass called "sedan" extends "gasengine auto" , has instance variable trunk space. assignment had these classes signed off on make sure made correctly.

write method read information file gas_sedans.txt , store in list created in previous step. list should parameter method. within method, open file, read information each sedan appropriately-typed variables, call parameterized constructor (the 1 takes arguments attributes) create object, add object list. call method main.

below code far. wanted try make sure read arraylist before used method it.

import java.io.file;  import java.io.filenotfoundexception;  import java.util.arraylist;  import java.util.scanner;    /**   *   * @author    */  public class lab10_prelab {        /**       * @param args command line arguments       */      public static void main(string[] args) throws filenotfoundexception {                    arraylist<sedan> sedanlist = new arraylist<sedan>();            file myfile = new file(system.getproperty("user.dir")+"/src/gas_sedans (1).txt");          if (!myfile.exists()){              system.out.println("the file not found");              system.exit(0);          }            scanner inputfile = new scanner(myfile);                    while (inputfile.hasnext())          {              sedan = new sedan();              a.setmake(inputfile.nextline());              a.setmodel(inputfile.nextline());              inputfile.nextline();              a.setmpg(inputfile.nextdouble());              inputfile.nextline();              a.settrunkcapacity(inputfile.nextdouble());              sedanlist.add(a);          }          inputfile.close();          }          }

it says inputmismatchexception notice when try run program.

you have typo error: automobilearray , autombilearray different.

in code missing o after m in variable

autombilearray     ^ 

edited: 06:49am 18/07/20115

it says inputmismatchexception notice when try run program.

a.setmodel(inputfile.nextline()); inputfile.nextline();//remove line a.setmpg(inputfile.nextdouble()); inputfile.nextline(); a.settrunkcapacity(inputfile.nextdouble()); inputfile.nextline();//add here 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -