Write a Java program to summarize the data from an input file and output a report -


i need writing java program summarize data input file sprocketorders.txt , output report similar 1 below:

                                spacely sprockets                          taking sprockets future                                sales summary report             sprocket number                          total quantity sold                  1                                           90                  2                                           155                  3                                           50                  4                                           300                  5                                           100   

the data in chart comes .txt file named above. info contained in txt file such:

 3   50  2   20  2   100  5   15  1   90  5   85  4   300  2   35  3   100 

the report needs appear in output window.

i want use switch structure. switch structure fragment have use reference:

 switch (snum)     {         case 1: part1total = part1total + quantity;             break;         case 2: part2total = part2total + quantity;             break;         case 3: part3total = part3total + quantity;             break;         case 4: part4total = part4total + quantity;             break;         case 5: part5total = part5total + quantity;             break;         default: system.out.println("bad sprocket number");      }  

this code have far establish inputting file:

 package spacely.sprockets;   public class spacelysprockets  {   public static void main(string[] args)  {     inputfile orderinfo;     orderinfo = new inputfile("sprocketorders.txt");   }  } 

how can use switch structure summarize data txt file , output report? it's not making sense me how can input data txt file , have displayed example below. need solid direction. thanks.

please try following code:

please not forget change file path

import java.io.bufferedreader; import java.io.filenotfoundexception; import java.io.filereader; import java.io.ioexception; import java.util.map; import java.util.treemap;  public class fileparsingdemo{      public static void main(string args[]) {          try {             treemap<string, string> map = new treemap<string, string>();              bufferedreader br = new bufferedreader(new filereader(                     "d:/vijay/temp.txt"));             string line;             while ((line = br.readline()) != null) {                 // process line.                 // system.out.println(line);                  line = line.trim();                 string number = line.substring(0, line.indexof(" "));                 string qlty = line.substring(line.lastindexof(" "));                   int found=0;                 (int = 0; < map.size(); i++) {                      if (map.containskey(number.trim())) {                          string oldqlt=map.get(number.trim());                            int totalqlt=integer.parseint(oldqlt) + integer.parseint(qlty.trim());                           map.remove(number.trim());                         map.put(number, ""+totalqlt);                         found=1;                         break;                      }                  }                 if(found==0)                 {                     map.put(number.trim(), qlty.trim());                  }               }             br.close();              (map.entry<string, string> e : map.entryset()) {                 //to key               system.out.println(e.getkey() +" ---- " + e.getvalue());                 //and value              }           } catch (filenotfoundexception ex) {             ex.printstacktrace();         } catch (ioexception ex) {             ex.printstacktrace();         } catch (exception ex) {             ex.printstacktrace();         }     } } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -