Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 30.27 KB | None | 0 0
  1. package app.management.prototype;
  2. import java.io.BufferedReader;
  3. import java.io.FileReader;
  4. import java.io.File;
  5. import java.io.FileNotFoundException;
  6. import java.io.FileWriter;
  7. import java.io.IOException;
  8. import java.io.PrintWriter;
  9. import java.util.Scanner;
  10. import java.io.BufferedWriter;
  11. import java.nio.file.Path;
  12. import java.nio.file.Paths;
  13.  
  14.  
  15. public class SysFunc {
  16.    
  17.    
  18.    
  19.     Path currentRelativePath = Paths.get("");
  20.     public String accDir = currentRelativePath.toAbsolutePath().toString()+"\\Accounts\\";
  21.     public String appDir = currentRelativePath.toAbsolutePath().toString()+"\\Apps\\";
  22.     public int activeAccount;
  23.     public int numOfAccounts = new File(accDir).list().length;
  24.     public int numOfApps = new File(appDir).list().length;
  25.     public int pata;
  26.     public int fata;
  27.     public int numPaidApps = 0;
  28.     public int numFreeApps = 0;
  29.     String newline = System.getProperty("line.separator");
  30.     Scanner i = new Scanner(System.in);
  31.    
  32. // MENUS    
  33. public void adminMenu() throws IOException
  34. {  
  35.     Account aA = new Account(activeAccount);
  36.     Scanner in = new Scanner(System.in);    
  37.     System.out.println("Logged in as "+aA.getName());
  38.     System.out.println("-----------------------");
  39.     System.out.println("What do you want to manage?");
  40.         System.out.println("1.Accounts");
  41.         System.out.println("2.Apps");
  42.         System.out.println("3.Total bought Apps");
  43.         System.out.println("4.Total used free Apps");
  44.         System.out.println("5.Log Out");
  45.         System.out.println("Type a number to select an option");
  46.         System.out.println("-----------------------");
  47.         String choice = in.nextLine();
  48.         switch (choice) {
  49.             case "1":
  50.                 accMng();
  51.                 break;
  52.             case "2":
  53.                 appMng();
  54.                 break;
  55.             case "3":
  56.                 System.out.println("-----------------------");
  57.                 System.out.println(pata+" Apps have been bought");
  58.                 adminMenu();
  59.                 break;
  60.             case "4":
  61.                 System.out.println("-----------------------");
  62.                 System.out.println(fata+" free Apps have been used");
  63.                 adminMenu();
  64.                 break;
  65.                 case "5":
  66.                logIn();
  67.                 break;
  68.             default:
  69.             System.out.println("Not a valid option.");
  70.                     System.out.println("-----------------------");
  71.                     adminMenu();
  72.                 break;
  73.         }
  74. }
  75.    
  76. public void custMenu() throws IOException
  77. {
  78.     Account aA = new Account(activeAccount);
  79.     Scanner in = new Scanner(System.in);  
  80.     System.out.println("Logged in as "+aA.getName()+" with £"+aA.getAmountToBePaid()+" to be paid (Student and Academic discounts are applied at checkout)");
  81.     System.out.println("-----------------------");
  82.     System.out.println("Main Menu?");
  83.         System.out.println("1.Edit Account");
  84.         System.out.println("2.View all apps");
  85.         System.out.println("3.View specific app");
  86.         System.out.println("4.Buy all Apps in Basket");
  87.         System.out.println("5.Log Out");
  88.         System.out.println("Type a number to select an option");
  89.         System.out.println("-----------------------");
  90.         String choice = in.nextLine();
  91.         switch (choice) {
  92.             case "1":
  93.                 custEditAcc(activeAccount);
  94.                 break;
  95.             case "2":
  96.                 listApps();
  97.                 break;
  98.             case "3":
  99.                searchApp();
  100.                 break;
  101.             case "4":
  102.                 buyOut();
  103.                 break;
  104.                 case "5":
  105.                logIn();
  106.                 break;
  107.             default:
  108.             System.out.println("Not a valid option.");
  109.                     System.out.println("-----------------------");
  110.                     adminMenu();
  111.                 break;
  112. }
  113. }
  114.  
  115. public void buyOut() throws IOException
  116. {
  117.     Account aA = new Account(activeAccount);
  118.    
  119.                 if(aA.getProfession().equalsIgnoreCase("Student"))
  120.                 {
  121.                     AccountStudents aS = new AccountStudents(activeAccount);
  122.                     aS.buyAll(activeAccount, numPaidApps, numFreeApps);
  123.                      
  124.                 }
  125.                 else if (aA.getProfession().equalsIgnoreCase("Academic"))
  126.                 {
  127.                     AccountAcademics aAc = new AccountAcademics(activeAccount);
  128.                     aAc.buyAll(activeAccount,numPaidApps, numFreeApps);
  129.                 }
  130.                 else
  131.                 {
  132.                     aA.buyAll(activeAccount, numPaidApps, numFreeApps);
  133.                 }
  134.                 String path = appDir+"TotalApps.txt";
  135.                 FileReader fr1 = new FileReader(path);
  136.             BufferedReader br1 = new BufferedReader(fr1);
  137.             int intData = Integer.parseInt(br1.readLine());
  138.             br1.close();
  139.                 totalCounter(numPaidApps + intData);
  140.                 numPaidApps = 0;
  141.                 numFreeApps = 0;
  142.            
  143.                 chkPrm();
  144.    
  145. }
  146. public void devMenu() throws IOException
  147. {
  148.     Account aA = new Account(activeAccount);
  149.     Scanner in = new Scanner(System.in);    
  150.     System.out.println("Logged in as "+aA.getName());
  151.     System.out.println("-----------------------");
  152.     System.out.println("Main Menu?");
  153.         System.out.println("1.Edit Account");
  154.         System.out.println("2.View all apps");
  155.         System.out.println("3.View specific app");
  156.         System.out.println("4.Create new App");
  157.         System.out.println("5.Log Out");
  158.         System.out.println("Type a number to select an option");
  159.         System.out.println("-----------------------");
  160.         String choice = in.nextLine();
  161.         switch (choice) {
  162.             case "1":
  163.                 custEditAcc(activeAccount);
  164.                 break;
  165.             case "2":
  166.                 listApps();
  167.                 break;
  168.             case "3":
  169.                searchApp();
  170.                 break;
  171.             case "4":
  172.                createApp();
  173.                case "5":
  174.                logIn();
  175.                
  176.                 break;
  177.             default:
  178.             System.out.println("Not a valid option.");
  179.                     System.out.println("-----------------------");
  180.                     adminMenu();
  181.                 break;
  182. }
  183. }
  184.  
  185. public void accMng() throws IOException
  186. {
  187.     Scanner in = new Scanner(System.in);  
  188.     System.out.println("-----------------------");
  189.     System.out.println("Account Management Menu");
  190.            System.out.println("1.Create New Account");
  191.            System.out.println("2.Delete account");
  192.            System.out.println("3.Edit Account");
  193.            System.out.println("4.Search for account");
  194.            System.out.println("5.Display total Accounts");
  195.            System.out.println("6.List Accounts");
  196.            System.out.println("7.Return to Main Menu");
  197.            System.out.println("8.Log Out");
  198.            System.out.println("Type a number to select an option");
  199.            System.out.println("-----------------------");
  200.            String choice = in.nextLine();
  201.         switch (choice) {
  202.             case "1":
  203.                 createAcc(false);
  204.                 break;
  205.             case "2":
  206.                 deleteAcc();
  207.                 break;
  208.             case "3":
  209.                 editAcc();
  210.                 break;
  211.             case "4":
  212.                 searchAcc();
  213.                 break;
  214.             case "5":
  215.                 System.out.println("-----------------------");
  216.                 System.out.println("There are currently "+numOfAccounts+" accounts.");
  217.                
  218.                 accMng();
  219.                 break;
  220.                  case "6":
  221.                 listAccounts();
  222.                 break;
  223.             case "7":
  224.                 adminMenu();
  225.                 break;
  226.                  case "8":
  227.                 logIn();
  228.                 break;
  229.            
  230.             default:
  231.                 System.out.println("-----------------------");
  232.                 System.out.println("Not a valid option.");
  233.                 System.out.println("-----------------------");
  234.                 accMng();
  235.                 break;
  236.                
  237.         }
  238.            
  239.     }
  240.    
  241. public void appMng() throws IOException
  242. {
  243.     Scanner in = new Scanner(System.in);  
  244.     System.out.println("-----------------------");
  245.     System.out.println("App Management Menu");
  246.            System.out.println("1.Create New App");
  247.            System.out.println("2.Delete App");
  248.            System.out.println("3.Edit App");
  249.            System.out.println("4.Search for App");
  250.            System.out.println("5.Display total Apps");
  251.            System.out.println("6.List all Apps");
  252.            System.out.println("7.Return to Main Menu");
  253.            System.out.println("8.Log Out");
  254.            System.out.println("Type a number to select an option");
  255.            String choice = in.nextLine();
  256.         switch (choice) {
  257.             case "1":
  258.                 createApp();
  259.                 break;
  260.             case "2":
  261.                 deleteApp();
  262.                 break;
  263.             case "3":
  264.                 editApp();
  265.                 break;
  266.             case "4":
  267.                 searchApp();
  268.                 break;
  269.             case "5":
  270.                 System.out.println("There are currently "+numOfApps+" App(s).");
  271.                 appMng();
  272.                 break;
  273.             case "6":
  274.                 listApps();
  275.                 break;
  276.             case "7":
  277.                 adminMenu();
  278.                 break;
  279.                 case "8":
  280.                 logIn();
  281.                 break;
  282.             default:
  283.                 System.out.println("Not a valid option.");
  284.                 System.out.println("-----------------------");
  285.                 appMng();
  286.                 break;
  287.         }
  288.    }
  289.  
  290. public void logIn() throws IOException
  291. {
  292. //    updPata();
  293.  //   updFata();
  294.     System.out.println("Please type 'new' to create a new account, or ENTER ANY KEY to Log In.");
  295.        try{
  296.         String ch = i.nextLine();
  297.         if (ch.equalsIgnoreCase("new")){ activeAccount = 9999; createAcc(true);}
  298.         else { System.out.println("What is your account number?");
  299.             String gh = i.nextLine();
  300.             activeAccount = Integer.parseInt(gh);
  301.             Account aA = new Account(activeAccount);
  302.             if (aA.getPerms().equalsIgnoreCase("c"))
  303.           {custMenu();}
  304.         else if(aA.getPerms().equalsIgnoreCase("d"))
  305.           {devMenu();}
  306.         else if(aA.getPerms().equalsIgnoreCase("a"))
  307.           {adminMenu();}}
  308.          
  309.         }
  310.         catch(IOException e) { System.out.println("That Account does not exist");
  311.         logIn();   }
  312.        
  313.         finally
  314.     {
  315.         System.out.println("That Account does not exist");
  316.        
  317.        
  318.         logIn();
  319.     }
  320.        
  321. }
  322.        
  323.  
  324. //Creators
  325. /*
  326. public void updPata() throws IOException
  327. {
  328.     String path = appDir+"pata.txt";
  329.     FileReader patafr = new FileReader(appDir+"pata.txt");
  330.     BufferedReader patabr = new BufferedReader(patafr);
  331.     FileWriter fw = new FileWriter(path);
  332.     BufferedWriter bw = new BufferedWriter(fw);
  333.     fata = Integer.parseInt(patabr.readLine());
  334.     int editLine = pata+1;
  335.            
  336.             bw.write(editLine);
  337.             bw.flush();
  338.             bw.close();
  339.            
  340. }
  341.  
  342. public void updFata() throws IOException
  343. {
  344.     String path = appDir+"fata"+".txt";
  345.     FileReader fatafr = new FileReader(appDir+"fata.txt");
  346.     BufferedReader fatabr = new BufferedReader(fatafr);
  347.     FileWriter fw = new FileWriter(path);
  348.     BufferedWriter bw = new BufferedWriter(fw);
  349.     fata = Integer.parseInt(fatabr.readLine());
  350.     int editLine = fata+1;
  351.            
  352.             bw.write(editLine);
  353.             bw.flush();
  354.             bw.close();
  355.            
  356. } */
  357.  
  358. public void createApp() throws IOException
  359. {
  360.     Account aA = new Account(activeAccount);
  361.     int cNum = numOfApps;
  362.     //try{              
  363.     Scanner in = new Scanner(System.in);  
  364.     Scanner inc = new Scanner(System.in);
  365.                     System.out.println("What is the App's name?");
  366.                     String n = inc.nextLine();
  367.                     System.out.println("What is the App's description?");
  368.                     String a = in.nextLine();
  369.                     System.out.println("What is the Developer name?");
  370.                     String p = inc.nextLine();
  371.                     System.out.println("What is the App's cost? (GBP)");
  372.                     String c = in.nextLine();
  373.                     double pt = (int)(Math.random()*10000);
  374.                     String pop = Double.toString(pt);
  375.                     System.out.println("What is the type of the App?");
  376.                     String t = inc.nextLine();
  377.                     System.out.println("Is the App for free or for purchasing? Type 1 for Free and 2 for Purchasing");
  378.                     int ifp = in.nextInt();
  379.                     String iff;
  380.                     if(ifp==1){iff="Free";}
  381.                     else {iff="Purchasing";}
  382.                    
  383.                     File f = new File(appDir+cNum);
  384.                     do { cNum ++;} while(f.exists());
  385.                     writeToFile(cNum, n, "app");
  386.                     writeToFile(cNum, a, "app");
  387.                     writeToFile(cNum, p, "app");
  388.                     writeToFile(cNum, c, "app");
  389.                     writeToFile(cNum, pop, "app");
  390.                     writeToFile(cNum, t, "app");
  391.                     writeToFile(cNum, iff, "app");
  392.                     System.out.println("Your App has been created with the number "+cNum+".");
  393.                     System.out.println("-----------------------");
  394.                     numOfApps++;
  395.                     if (aA.getPerms().equalsIgnoreCase("d"))
  396.                     {devMenu();}
  397.                     else if(aA.getPerms().equalsIgnoreCase("c"))
  398.                     {custMenu();}
  399.                     else
  400.                     {appMng();}    
  401.                     }
  402.  //catch(IOException e)
  403. //{
  404. //    System.out.println("Dun Goofed");
  405. //}
  406. //}
  407. public void createAcc(boolean newacc) throws IOException
  408. {
  409.      
  410.     int cNum = numOfAccounts;
  411.                     Scanner in = new Scanner(System.in);          
  412.                     System.out.println("What is your Full Name?");
  413.                     String n = in.nextLine();
  414.                     System.out.println("What is your address?");
  415.                     String a = in.nextLine();
  416.                     System.out.println("What is your your Occupation?");
  417.                     String p = in.nextLine();
  418.                     System.out.println("Is this a Developer account?(yes / no) ");
  419.                     String cd = in.nextLine();
  420.                     File f = new File(accDir+cNum);
  421.                     do { cNum ++;} while(f.exists());
  422.                     writeToFile(cNum, n, "acc");
  423.                     writeToFile(cNum, a, "acc");
  424.                     writeToFile(cNum, p, "acc");
  425.                     writeToFile(cNum , "0", "acc");
  426.                     writeToFile(cNum, "0", "acc");
  427.                     if (cd.equalsIgnoreCase("yes"))
  428.                     { writeToFile(cNum, "d", "acc"); }
  429.                     else
  430.                     { writeToFile(cNum, "c", "acc"); }
  431.                     System.out.println("Your account has been created with the number "+cNum+".");
  432.                     System.out.println("-----------------------");
  433.                     numOfAccounts++;
  434.  
  435.  
  436.                     if(!newacc)
  437.                     { accMng();}
  438.                     else if(newacc) {System.out.println("Please log in with your new account number.");logIn(); }
  439.                     }
  440.                    
  441. public void chkPrm() throws IOException
  442. {
  443.    Account aA = new Account(activeAccount);
  444.     if(aA.getName().equalsIgnoreCase("admin"))
  445.     {
  446.     adminMenu();
  447.     }
  448. else if(aA.getPerms().equalsIgnoreCase("c"))
  449.     {
  450.         custMenu();
  451.     }
  452. else if(aA.getPerms().equalsIgnoreCase("d"))
  453. {
  454.     devMenu();
  455.     }
  456. }
  457. public void writeToFile(int file, String textLine, String t) throws IOException
  458. {
  459.     String path;
  460.     if(t.equalsIgnoreCase("acc"))
  461.     {path = accDir+file+".txt";}
  462.     else
  463.     { path = appDir+file+".txt";}
  464.    
  465.        boolean append_to_file = true;
  466.   FileWriter write = new FileWriter(path, append_to_file);
  467.   PrintWriter print_line = new PrintWriter(write);
  468.   print_line.printf("%s%n", new Object[] { textLine });
  469.  
  470.   print_line.close();
  471.     }
  472.  
  473. public void totalCounter(int numApps) throws IOException
  474. {
  475.     String path = appDir+"TotalApps.txt";
  476.    
  477.   FileWriter fw = new FileWriter(path);
  478.   BufferedWriter bw = new BufferedWriter(fw);
  479.   PrintWriter print_line = new PrintWriter(bw);
  480.   print_line.printf("%s%n", new Object[] { numApps });
  481.  
  482.   print_line.close();
  483. }
  484. //Deleters
  485. public void deleteAcc() throws IOException
  486. {
  487. Scanner in = new Scanner(System.in);
  488.     System.out.println("Which Account do you want to delete");
  489. int ch = in.nextInt();
  490. File x = new File(accDir+ch+".txt");
  491. boolean delete = x.delete();
  492. if(delete)
  493. System.out.println("Deleted!");
  494. else
  495. System.out.println("Cannot Delete");
  496. accMng();
  497. }
  498.  
  499. public void deleteApp() throws IOException
  500. {
  501.     Scanner in = new Scanner(System.in);
  502. System.out.println("Which App do you want to delete? (App Number)");
  503. int ch = in.nextInt();
  504. File x = new File(appDir+ch+".txt");
  505. boolean delete = x.delete();
  506. if(delete)
  507. System.out.println("Deleted!");
  508. else
  509. System.out.println("Cannot Delete");
  510. appMng();  
  511. }
  512.  
  513. //Editors
  514. public void editAcc() throws FileNotFoundException, IOException
  515. {
  516.     System.out.println("Which Account do you want to edit? (Account Number)");
  517.     Scanner impor = new Scanner(System.in);
  518.     String editLine = "hi";
  519.     int ach = impor.nextInt();
  520.     String path = accDir+ach+".txt";
  521.    
  522.    
  523.            
  524.             FileReader fr1 = new FileReader(path);
  525.             BufferedReader br1 = new BufferedReader(fr1);
  526.            
  527.  
  528.             int numberOfLines = 6;
  529.             String[] textData = new String[numberOfLines];
  530.             for (int b = 0; b < numberOfLines; b++) {        
  531.             textData[b] = br1.readLine(); }
  532.             Scanner in = new Scanner(System.in);
  533.             System.out.println("-----------------------");
  534.             System.out.println(textData[0]);
  535.             System.out.println(textData[1]);
  536.             System.out.println(textData[2]);
  537.             System.out.println("-----------------------");
  538.             br1.close();
  539.            
  540.             System.out.println("What do you want to edit?");
  541.             System.out.println("type 1 for name");
  542.             System.out.println("type 2 for Address");
  543.             System.out.println("type 3 for Occupation");
  544.            
  545.             String inc = in.nextLine();
  546.        
  547.            
  548.            
  549.            if (inc.equals("1") || inc.equals("2")||inc.equals("3")){
  550.                 FileWriter fw = new FileWriter(path);
  551.             BufferedWriter bw = new BufferedWriter(fw);
  552.                 System.out.println("What would you like to change it to?");
  553.             String editMade = in.nextLine();
  554.             switch (inc) {
  555.             case "1":
  556.                 editLine = editMade + newline + textData[1] + newline + textData[2]+ newline + textData[3] + newline + textData[4] + newline + textData[5];
  557.                 break;
  558.             case "2":
  559.                 editLine = textData[0] + newline + editMade + newline + textData[2] + newline + textData[3] + newline +textData[4] + newline + textData[5];
  560.                 break;
  561.             case "3":
  562.                 editLine = textData[0] + newline + textData[1] + newline + editMade + newline + textData[3] + newline + textData[4]+ newline + textData[5];
  563.                 break;
  564.                
  565.         }
  566.            
  567.               bw.write(editLine);
  568.             bw.flush();
  569.             bw.close();
  570.             FileReader fr = new FileReader(path);
  571.             BufferedReader br = new BufferedReader(fr);
  572.             for (int b = 0; b < numberOfLines; b++) {
  573.             textData[b] = br.readLine(); }
  574.             System.out.println("-----------------------");
  575.             System.out.println(textData[0]);
  576.             System.out.println(textData[1]);
  577.             System.out.println(textData[2]);
  578.             System.out.println("-----------------------");
  579.             } else {
  580.                System.out.println("This is not a valid Input");
  581.                
  582.            }    
  583.            
  584.  
  585.            
  586.          
  587.            
  588.          
  589.    accMng();
  590. }
  591.  
  592. public void custEditAcc(int aa) throws FileNotFoundException, IOException
  593. {
  594.     System.out.println("Editing account number "+aa);
  595.     Scanner i = new Scanner(System.in);
  596.     String editLine = "hi";
  597.     int ach = aa;
  598.     String path = accDir+ach+".txt";
  599.     String newline = System.getProperty("line.separator");
  600.    
  601.            
  602.             FileReader fr1 = new FileReader(path);
  603.             BufferedReader br1 = new BufferedReader(fr1);
  604.            
  605.  
  606.             int numberOfLines = 6;
  607.             String[] textData = new String[numberOfLines];
  608.             for (int b = 0; b < numberOfLines; b++) {        
  609.             textData[b] = br1.readLine(); }
  610.             Scanner in = new Scanner(System.in);
  611.             System.out.println("-----------------------");
  612.             System.out.println("Name = "+textData[0]+" Address = "+textData[1]+" Occupation = "+textData[2]);
  613.             System.out.println("-----------------------");
  614.             br1.close();
  615.            
  616.             System.out.println("What do you want to edit?");
  617.             System.out.println("type 1 for name");
  618.             System.out.println("type 2 for Address");
  619.             System.out.println("type 3 for Occupation");
  620.             String inc = in.nextLine();
  621.            
  622.            
  623.            if (inc.equals("1") || inc.equals("2")||inc.equals("3")){
  624.                 FileWriter fw = new FileWriter(path);
  625.             BufferedWriter bw = new BufferedWriter(fw);
  626.                 System.out.println("What would you like to change it to?");
  627.             String editMade = in.nextLine();
  628.             switch (inc) {
  629.             case "1":
  630.                 editLine = editMade + newline + textData[1] + newline + textData[2]+ newline + textData[3] + newline + textData[4] + newline + textData[5];
  631.                 break;
  632.             case "2":
  633.                 editLine = textData[0] + newline + editMade + newline + textData[2] + newline + textData[3] + newline +textData[4] + newline + textData[5];
  634.                 break;
  635.             case "3":
  636.                 editLine = textData[0] + newline + textData[1] + newline + editMade + newline + textData[3] + newline + textData[4]+ newline + textData[5];
  637.                 break;
  638.                
  639.         }
  640.            
  641.               bw.write(editLine);
  642.             bw.flush();
  643.             bw.close();
  644.             FileReader fr = new FileReader(path);
  645.             BufferedReader br = new BufferedReader(fr);
  646.             for (int b = 0; b < numberOfLines; b++) {
  647.             textData[b] = br.readLine(); }
  648.             System.out.println("-----------------------");
  649.             System.out.println(textData[0]);
  650.             System.out.println(textData[1]);
  651.             System.out.println(textData[2]);
  652.             System.out.println("-----------------------");
  653.             } else {
  654.                System.out.println("This is not a valid Input");
  655.                
  656.            }    
  657.            
  658.  
  659.     custMenu();
  660. }
  661.  
  662.  
  663.  
  664. public void editApp() throws FileNotFoundException, IOException
  665. {
  666.    System.out.println("Which App do you want to edit? (App Number)");
  667.     Scanner impor = new Scanner(System.in);
  668.     String editLine = "hi";
  669.     int ach = impor.nextInt();
  670.     String path = accDir+ach+".txt";
  671.     String newline = System.getProperty("line.separator");
  672.    
  673.             System.out.println(path);
  674.             FileReader fr1 = new FileReader(path);
  675.             BufferedReader br1 = new BufferedReader(fr1);
  676.            
  677.  
  678.             int numberOfLines = 5;
  679.             String[] textData = new String[numberOfLines];
  680.             for (int b = 0; b < numberOfLines; b++) {        
  681.             textData[b] = br1.readLine(); }
  682.             Scanner in = new Scanner(System.in);
  683.             System.out.println("-----------------------");
  684.             System.out.println(textData[0]);
  685.             System.out.println(textData[1]);
  686.             System.out.println(textData[2]);
  687.             System.out.println("-----------------------");
  688.             br1.close();
  689.            
  690.             System.out.println("What do you want to edit?");
  691.             System.out.println("type 1 for name");
  692.             System.out.println("type 2 for description");
  693.             System.out.println("type 3 for cost");
  694.             String inc = in.nextLine();
  695.            
  696.            
  697.            if (inc.equals("1") || inc.equals("2")||inc.equals("3")){
  698.                 FileWriter fw = new FileWriter(path);
  699.             BufferedWriter bw = new BufferedWriter(fw);
  700.                 System.out.println("What would you like to change it to?");
  701.             String editMade = in.nextLine();
  702.             switch (inc) {
  703.             case "1":
  704.                 editLine = editMade + newline + textData[1] + newline + textData[2] + newline + textData[3] + newline + textData[4];
  705.                 break;
  706.             case "2":
  707.                 editLine = textData[0] + newline + editMade + newline + textData[2] + newline + textData[3] + newline + textData[4];
  708.                 break;
  709.             case "3":
  710.                 editLine = textData[0] + newline + textData[1] + newline + textData[2] + newline + Double.parseDouble(editMade) + newline + textData[4];
  711.                 break;
  712.             default:
  713.                
  714.             }
  715.            
  716.             bw.write(editLine);
  717.             bw.flush();
  718.            
  719.             FileReader fr = new FileReader(path);
  720.             BufferedReader br = new BufferedReader(fr);
  721.             for (int b = 0; b < numberOfLines; b++) {
  722.             textData[b] = br.readLine(); }
  723.             System.out.println("-----------------------");
  724.             System.out.println(textData[0]);
  725.             System.out.println(textData[1]);
  726.             System.out.println(textData[2]);
  727.             System.out.println("-----------------------");
  728.            }
  729. else {
  730.                System.out.println("This is not a valid Input");
  731.                
  732.            }    
  733.  
  734.  
  735. appMng();
  736.  
  737.  
  738. }
  739.  
  740.  
  741.  
  742.  
  743.  
  744. //Searchers
  745. public void searchAcc() throws IOException
  746. {
  747.     try
  748.     {
  749.     Scanner in = new Scanner(System.in);
  750.     System.out.println("What account are you looking for?(Account Number)");
  751.    
  752.     int an = in.nextInt();
  753.     String path = accDir+an+".txt";
  754.    
  755.     Account ac = new Account(an);
  756.     System.out.println("-----------------------");
  757.     System.out.println(path);
  758.    
  759.     System.out.println("Name = "+ac.getName()+", Address = "+ac.getAddress()+", Occupation = "+ac.getProfession());
  760.     System.out.println("");
  761.     System.out.println("Has bought = "+ac.getAppsPurchased()+" app(s), has used  = "+ac.getAppsFree()+" app(s).");
  762. chkPrm();
  763.     }
  764.    
  765.     catch (IOException e)
  766.    {
  767.        System.out.println("-----------------------");
  768.        System.out.println("Doesn't exist");
  769.        System.out.println("-----------------------");
  770. chkPrm();
  771.    }
  772.    finally
  773.     {
  774.         System.out.println("-----------------------");
  775.         System.out.println("Doesn't exist");
  776.         System.out.println("-----------------------");
  777. chkPrm();
  778.     }
  779.     }
  780.  
  781. public void listApps() throws IOException
  782. {
  783.     File folder = new File(appDir);
  784.     File[] listOfFiles = folder.listFiles();
  785.  
  786.     for (int i = 0; i < listOfFiles.length-1; i++) {
  787.     if (listOfFiles[i].isFile()) {
  788.     String[] textData = new String[5];
  789.     FileReader fr = new FileReader(appDir+(listOfFiles[i].getName()));
  790.     BufferedReader textReader = new BufferedReader(fr);
  791.     for (int p = 0; p < 5; p++) {textData[p] = textReader.readLine(); }
  792.         System.out.println("Name = "+textData[0]+" Description = "+textData[1]+" Cost = £"+textData[3]);
  793.       } else if (listOfFiles[i].isDirectory()) {
  794.         System.out.println("Directory " + listOfFiles[i].getName());
  795.       }
  796.     }
  797. chkPrm();
  798.     }
  799.  
  800.  
  801. public void searchApp() throws IOException
  802. {
  803.      try {
  804.     Account aA = new Account(activeAccount);
  805.     Scanner in = new Scanner(System.in);
  806.     Scanner inc = new Scanner(System.in);
  807.     System.out.println("What App are you looking for?");
  808.     int an = in.nextInt();
  809.    
  810.     App ap = new App(an);
  811.     System.out.println("name = "+ap.getAppName()+", Description = "+ap.getDesc()+", Developer = "+ap.getDev()+", Cost = "+ap.getCost());
  812.     System.out.println("-----------------------");
  813.     System.out.println("Do you want to add this App to basket? (yes/no)");
  814.     System.out.println("-----------------------");
  815.     String ab = inc.nextLine();
  816.     System.out.println("-----------------------");
  817.     double freeOrPaid = ap.getCost();
  818.     if(ab.equalsIgnoreCase("yes"))
  819.     {  
  820.         if (freeOrPaid == 0)
  821.         {numFreeApps++;}
  822.         else {
  823.         numPaidApps++;
  824.         }
  825.         double tc = aA.getAmountToBePaid()+ap.getCost();
  826.         aA.setAmountToBePaid(tc, activeAccount); chkPrm();
  827.        
  828.        
  829.     }
  830.     else if (ab.equalsIgnoreCase("no")){
  831.    chkPrm();
  832.  
  833.      }
  834.      }
  835.    catch(IOException e)
  836.         {
  837.       System.out.println("-----------------------");
  838.       System.out.println("Doesn't exist");
  839.       System.out.println("-----------------------");
  840.           chkPrm();
  841.         }
  842.      finally {
  843.          chkPrm();}
  844.  
  845. }
  846.  
  847.  
  848. public void listAccounts() throws IOException{
  849.     File folder = new File(accDir);
  850.     File[] listOfFiles = folder.listFiles();
  851.  
  852.     for (int i = 0; i < listOfFiles.length; i++) {
  853.     if (listOfFiles[i].isFile()) {
  854.     String[] textData = new String[5];
  855.     FileReader fr = new FileReader(accDir+(listOfFiles[i].getName()));
  856.     BufferedReader textReader = new BufferedReader(fr);
  857.     for (int p = 0; p < 3; p++) {textData[p] = textReader.readLine(); }
  858.         System.out.println("Name = "+textData[0]+" Address = "+textData[1]+" Occupation = "+textData[2]);
  859.       } else if (listOfFiles[i].isDirectory()) {
  860.         System.out.println("Directory " + listOfFiles[i].getName());
  861.        
  862.     }
  863.     }
  864.     chkPrm();
  865.     }
  866.  
  867. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement