java - Program done in netbeans and works fine but when cut and pasted to notepad and then complied will not work properly -


i created program in netbeans , options in program works when take code , pasted in notepad , compile @ cmd options work , dont why that.

import java.io.filenotfoundexception; import java.util.scanner;  /* should create @ least 2 java classes – titanic , testtitanic  */ public class testtitanic{      public static void main(string[] args) throws filenotfoundexception {         //use command line arguments send in name of titanic file         string filename = args[0];         titanic titanic = new titanic(filename);         //the application should keep track of elapsed time (in seconds)          long starttime = system.currenttimemillis();          //a user-friendly , well-organized menu s         string choices[] =         {"total number of passengers on titanic",             "total number of passengers perished on titanic",             "total number of passengers survived sinking of titanic",             "number of passengers survived sinking of titanic function of passenger class (e.g. 1,2,3)",             "number of passengers survived sinking of titanic function of passenger gender (e.g., male, female)",             "a list of names of passengers paid greater $200 tickets",             "a list of names of passengers less 10 years old survived",             "a list of names of passengers less 10 years old perished ",             "the count of number of passengers function of first letter of last name. (e.g., a: 13, b:33 …)", "exit"};         int choice = menuchoice(choices);         while (choice != 10) {             switch (choice) {                 case 1:                     system.out.println("total number of passengers on titanic: " + titanic.gettotalpassengers());                     break;                 case 2:                     system.out.println("total number of passengers perished on titanic: " + titanic.gettotalnumberofperishedpassengers());                     break;                 case 3:                     system.out.println("total number of passengers survived : " + titanic.gettotalnumberofsurvivedpassengers());                     break;                 case 4:                     system.out.print("enter class (e.g. 1,2,3): ");                     int cls = getintinrange(1, 3);                     system.out.println(cls + " class number of passengers survived: " + titanic.gettotalnumberofsurvivedpassengersbyclass(cls));                     break;                 case 5:                     system.out.print("enter gender (e.g., male, female): ");                     string gender = getstring();                     system.out.println("number of " + gender + " passengers survived: " + titanic.gettotalnumberofsurvivedpassengersbygender(gender));                     break;                 case 6:                     system.out.print("names of passengers paid greater $200 tickets: ");                     system.out.println(titanic.getnamespaidfare(200));                     break;                 case 7:                     system.out.print("names of passengers less 10 years old survived: ");                     system.out.println(titanic.getsurvivednameslessgivenage(10));                     break;                 case 8:                     system.out.print("names of passengers less 10 years old perished: ");                     system.out.println(titanic.getperishednameslessgivenage(10));                     break;                 case 9:                     system.out.print("enter letter: ");                     char ch = getstring().charat(0);                     system.out.println("count: " + titanic.getcountbyfirstletteroffirstname(ch));                     break;             }             choice = menuchoice(choices);         }          //the application should keep track of elapsed time (in seconds)          long endtime = system.currenttimemillis();         long elapsedtime = (endtime - starttime) / 1000;         /**          * after program exited, application should provide prompt          * thanking user trying titanic program , providing          * total time elapsed.          */         system.out.println("thank trying titanic program");         system.out.println("elapsed time: " + elapsedtime);     }      /**      * helper method string user      *      * @return      */     public static string getstring() {         scanner input = new scanner(system.in);         return input.nextline();     }      /**      * helper method user input in range      *      * @param low      * @param high      * @return      */     public static int getintinrange(int low, int high) {         int num = 0;         {             num = getint();             if (num < low || num > high) {                 system.out.println("enter number between " + low + " , " + high);             }         } while (num < low || num > high);         return num;     }      /**      *      * method display organized menu user      *      * @param choices      * @return      */     public static int menuchoice(string choices[]) {         int choice = 0;         system.out.println("");         (int = 0; < choices.length; i++) {             system.out.println((i + 1) + ". " + choices[i]);         }         system.out.print("enter choice (1-" + choices.length + "): ");         choice = getintinrange(1, choices.length);         return choice;     }      /**      * helper method int user      *      * @return      */     public static int getint() {         scanner input = new scanner(system.in);         int num = -1;         boolean good;         {             = true;             try{                 num = input.nextint();             }              catch(exception e) {                 = false;                 input = new scanner(system.in);                 system.out.println("enter numeric value: ");             }         } while (!good);         return num;     } } 

here other code:

import java.io.file; import java.io.filenotfoundexception; import java.util.scanner; // java class titanic public class titanic{      int maxpassengers = 10000;     int actualpassengers = 0;     //b. use 2d array store titanic data.      string[][] data = new string[maxpassengers][6];      /**      * constructor read file , set 2d array store titanic data      */     titanic(string filename) throws filenotfoundexception {         scanner filereader = new scanner(new file(filename));          while (filereader.hasnextline()) {             //line has tab delimeted data             data[actualpassengers++] = filereader.nextline().split("\t");          }         filereader.close();     }      /**      *      * @return total number of passengers on titanic      */     public int gettotalpassengers() {         return actualpassengers;     }      /**      *      * @return total number of passengers perished on titanic      */     public int gettotalnumberofperishedpassengers() {         int count = 0;         (int = 0; < gettotalpassengers(); i++) {              int status = integer.parseint(data[i][1]);             //survived (1=yes, 0=no)             if (status == 0) {                 count++;             }         }         return count;     }      /**      *      * @return total number of passengers survived sinking of      * titanic      */     public int gettotalnumberofsurvivedpassengers() {         return gettotalpassengers() - gettotalnumberofperishedpassengers();     }      /**      * number of passengers survived sinking of titanic      * function of passenger class (e.g. 1,2,3)      *      * @param cls      * @return      */     public int gettotalnumberofsurvivedpassengersbyclass(int cls) {         int count = 0;         (int = 0; < gettotalpassengers(); i++) {             int status = integer.parseint(data[i][1]);             int clazz = integer.parseint(data[i][0]);             //survived (1=yes, 0=no)             if (status == 1 && clazz == cls) {                 count++;             }         }         return count;     }      /**      * number of passengers survived sinking of titanic      * function of passenger gender (e.g., male, female)      *      * @param gender      * @return      */     public int gettotalnumberofsurvivedpassengersbygender(string gender) {         int count = 0;         (int = 0; < gettotalpassengers(); i++) {             int status = integer.parseint(data[i][1]);             //survived (1=yes, 0=no)             if (status == 1 && gender.equalsignorecase(data[i][3])) {                 count++;             }         }         return count;     }      /**      *      * @param fair      * @return list of names of passengers paid greater given      * fair tickets      */     public string getnamespaidfare(double fair) {         string name = "";         (int = 0; < gettotalpassengers(); i++) {             if (data[i].length >= 6) {                 double pfair = double.parsedouble(data[i][5]);                 if (pfair > fair) {                     name += "\n" + data[i][2];                 }             }         }         return name;     }      /**      * g. list of names of passengers less 10 years old      * survived sinking of titanic      *      * @param age      * @return      */     public string getsurvivednameslessgivenage(int age) {         string name = "";         (int = 0; < gettotalpassengers(); i++) {             if (data[i].length >= 6 && data[i][4].length() > 0) {                 int status = integer.parseint(data[i][1]);                 double page = double.parsedouble(data[i][4]);                 //survived (1=yes, 0=no)                 if (status == 1 && page < age) {                     name += "\n" + data[i][2];                 }             }         }         return name;     }      /**      * h. list of names of passengers less 10 years old      * perished on titanic      *      * @param age      * @return      */     public string getperishednameslessgivenage(int age) {         string name = "";         (int = 0; < gettotalpassengers(); i++) {             if (data[i].length >= 6 && data[i][4].length() > 0) {                 int status = integer.parseint(data[i][1]);                 double page = double.parsedouble(data[i][4]);                 //survived (1=yes, 0=no)                 if (status == 0 && page < age) {                     name += "\n" + data[i][2];                 }             }         }         return name;     }      /**      * count of number of passengers function of first letter      * of last name. (e.g., a: 13, b:33 …)      *      * @param ch      * @return      */     public int getcountbyfirstletteroffirstname(char ch) {         int count = 0;         (int = 0; < gettotalpassengers(); i++) {             char pchar = data[i][2].charat(0);              if (character.touppercase(ch) == character.touppercase(pchar)) {                 count++;             }         }         return count;     } } 

here stacktrace:

exception in thread "main" java.lang.arrayindexoutofboundsexception:1 @ titanic.gettotalnumbersofperishedpassengers(titanic.java:43) @ testtitanic.main(testtitanic.java:34) 


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -