Advertisement
ProgrammablePeter

java.file

Jan 14th, 2014
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 26.55 KB | None | 0 0
  1. /*
  2.  
  3.  */
  4. package policymanager;
  5.  
  6. import java.io.File;
  7. import java.io.FileNotFoundException;
  8. import java.io.FileOutputStream;
  9. import java.io.FileWriter;
  10. import java.io.IOException;
  11. import java.io.PrintWriter;
  12. import java.util.Scanner;
  13. import java.util.Calendar;
  14. import java.text.SimpleDateFormat;
  15. import java.util.*;
  16.  
  17. /**
  18.  *
  19.  * @author Michael Watts (N3071956) - School of Computing
  20.  */
  21. public class PolicyManager {
  22.  
  23.     final private static Scanner UserInput = new Scanner(System.in);
  24.  
  25.     private static String name;
  26.     private static String ref;
  27.     private static String num;
  28.     private static String payment;
  29.     private static String terms[] = {"Annual", "Monthly"};
  30.     private static String nums[] = {"One", "Two", "Three", "Four", "Five"};
  31.  
  32.     private static int numOfItemsRejected = 0;
  33.     private static int excess;
  34.     private static int gadgetLimit = 0;
  35.     private static int b;
  36.  
  37.     private static double val;
  38.     private static double mostExpensive;
  39.     private static double premium = 0;
  40.     private static double total = 0;
  41.     private static double finishedPremium = 0;
  42.     private static double endPremium = 0;
  43.     private static double finishedTotal = 0;
  44.     private static double premium1[][] = {{4.99, 6.15, 7.30}, {9.99, 12.35, 14.55}, {14.99, 18.60, 21.82}};
  45.    
  46.     /**
  47.      * @param args the command line arguments
  48.      */
  49.     public static void main(String[] args) throws FileNotFoundException, IOException {
  50.  
  51.         //Display Menu
  52.         int choice = returnMenu();
  53.  
  54.         //Menu loop
  55.         while (choice != 0) {
  56.             if (choice == 1) {
  57.  
  58.                 Policy newPolicy = new Policy();
  59.                 newPolicy = createNewPolicy(newPolicy);
  60.  
  61.             } else if (choice == 2) {
  62.  
  63.                 displaySummary();
  64.  
  65.             } else if (choice == 3) {
  66.  
  67.                 displayMonth();
  68.  
  69.             } else if (choice == 4) {
  70.  
  71.             } else {
  72.                 System.out.println("Only menu choises 1-4 are valid");
  73.                 System.out.print("\nSelect menu item: ");
  74.                 choice = UserInput.nextInt();
  75.  
  76.             }
  77.  
  78.             choice = returnMenu();
  79.         }
  80.     }
  81.  
  82.     public static int returnMenu() {
  83.  
  84.         System.out.println("     Gadget Policy Prototype");
  85.         System.out.println("---------------------------------");
  86.         System.out.println("1. Create New Policy");
  87.         System.out.println("---------------------------------");
  88.         System.out.println("2. Display Summary Of Policies");
  89.         System.out.println("---------------------------------");
  90.         System.out.println("3. Current Policies For The Month");
  91.         System.out.println("---------------------------------");
  92.         System.out.println("4. Find and Display Policy");
  93.         System.out.println("---------------------------------");
  94.         System.out.println("0. Exit");
  95.         System.out.println("---------------------------------");
  96.  
  97.         System.out.print("\nPlease Enter Your Choice: ");
  98.         int option = UserInput.nextInt();
  99.         UserInput.nextLine();
  100.         return option;
  101.  
  102.     }
  103.  
  104.     public static Policy createNewPolicy(Policy newPol) throws IOException {
  105.  
  106.         System.out.println("----------------------------------------------------");
  107.  
  108.         System.out.println("Today's date of " + getDate() + " has been recorded on the policy");
  109.         newPol.setPolicyDate(getDate());
  110.  
  111.         System.out.println("----------------------------------------------------");
  112.  
  113.         Scanner keyboardString = new Scanner(System.in);
  114.         Scanner keyboardInt = new Scanner(System.in);
  115.         boolean validate = false;
  116.         while (validate == false)//A NAME, ONLY NEEDS TO BE 20 CHARS OR LESS. SIMPLE VALIDATION
  117.         {
  118.             System.out.println("Client Name Needed?: ");
  119.             name = keyboardString.nextLine();
  120.             if (name.length() > 20) {
  121.                 System.out.println("Name must be a maximum of 20 characters");
  122.                 System.out.println("You used " + name.length() + " characters");
  123.             } else {
  124.                 newPol.setClientName(name);
  125.                 validate = true;
  126.             }
  127.         }
  128.  
  129.         System.out.println("----------------------------------------------------");
  130.  
  131.         validate = false;
  132.         while (validate == false) {
  133.             System.out.println("Please enter reference number?: ");
  134.             ref = keyboardString.next().toUpperCase();
  135.             validate = validateReference(ref);
  136.             if (validate == true) {
  137.                 newPol.setReference(ref);
  138.             }
  139.         }
  140.  
  141.         System.out.println("----------------------------------------------------");
  142.  
  143.         validate = false;
  144.         while (validate == false) {
  145.             System.out.println("Please enter number of items between 1 and 5: ");
  146.             num = keyboardString.next();
  147.             String items = num;
  148.             while (!Character.isDigit(num.charAt(0))) {
  149.                 System.out.println("Your selection needs to be a number.");
  150.                 num = keyboardString.next();
  151.             }
  152.  
  153.             System.out.println("----------------------------------------------------");
  154.  
  155.             validate = false;
  156.             while (!validate) {
  157.                 System.out.print("Highest gadget value? £ ");
  158.                 try {
  159.                     val = keyboardInt.nextDouble();
  160.                     if (val <= 0) {
  161.                         System.out.println("Value must be a positive number");
  162.                     }
  163.  
  164.                     if (val > 0) {
  165.                         val = val * 100;
  166.                         newPol.setHighestGadgetValue((int) val);
  167.                         validate = true;
  168.                     }
  169.                 } catch (Exception e) //Exception handling for non-numbers
  170.                 {
  171.                     System.out.println("Must be in pounds and pence e.g. xx.xx");
  172.                     keyboardInt.next();
  173.                 }
  174.  
  175.             }
  176.  
  177.             System.out.println("----------------------------------------------------");
  178.  
  179.             validate = false;
  180.             while (!validate) {
  181.                 System.out.print("Please enter excess? £ ");
  182.                 try {
  183.                     excess = keyboardInt.nextInt();
  184.                     if (excess == 30 || excess == 40 || excess == 50 || excess == 60 || excess == 70) {
  185.                         newPol.setExcess(excess);
  186.                         validate = true;
  187.                     } else {
  188.                         System.out.println("must be (minimum £30, max £70 in multiples of £10)");
  189.                     }
  190.                 } catch (Exception e) {
  191.                     System.out.println("You entered an invalid input. Please try again");
  192.                     keyboardInt.next();
  193.                 }
  194.             }
  195.  
  196.             System.out.println("----------------------------------------------------");
  197.  
  198.             do {
  199.                 System.out.println("Your payment method?:  a = annual or m = monthly");
  200.                 payment = keyboardString.next();
  201.                 if ((payment.length() == 1) && ((payment.equals("m")) || (payment.equals("a")))) {
  202.                     break;
  203.                 } else {
  204.                     System.out.println("Incorrect input, please enter a valid input.");
  205.                 }
  206.             } while ((payment.length() != 1) || (!payment.equals("m") || (!payment.equals("a"))));
  207.  
  208.             System.out.println("----------------------------------------------------");
  209.  
  210.             if (num.charAt(0) == '1' && mostExpensive > 0 && mostExpensive <= 500) {
  211.                 premium = premium1[0][0];
  212.                 gadgetLimit = 500;
  213.             }
  214.             if (num.charAt(0) == '1' && mostExpensive > 500 && mostExpensive <= 750) {
  215.                 premium = premium1[0][1];
  216.                 gadgetLimit = 750;
  217.             } else if (num.charAt(0) == '1'
  218.                     && mostExpensive > 750 && mostExpensive <= 1000) {
  219.                 premium = premium1[0][2];
  220.                 gadgetLimit = 1000;
  221.             }
  222.  
  223.             if (num.charAt(0) == '2' || num.charAt(0) == '3'
  224.                     && mostExpensive > 0 && mostExpensive <= 500) {
  225.                 premium = premium1[1][0];
  226.                 gadgetLimit = 500;
  227.             }
  228.             if (num.charAt(0) == '2' || num.charAt(0) == '3'
  229.                     && mostExpensive > 500 && mostExpensive <= 750) {
  230.                 premium = premium1[1][1];
  231.                 gadgetLimit = 750;
  232.             } else if (num.charAt(0) == '2' || num.charAt(0) == '3'
  233.                     && mostExpensive > 750 && mostExpensive <= 1000) {
  234.                 premium = premium1[1][2];
  235.                 gadgetLimit = 1000;
  236.             }
  237.  
  238.             if (num.charAt(0) == '4' || num.charAt(0) == '5'
  239.                     && mostExpensive > 0 && mostExpensive <= 500) {
  240.                 premium = premium1[2][0];
  241.                 gadgetLimit = 500;
  242.             }
  243.             if (num.charAt(0) == '4' || num.charAt(0) == '5'
  244.                     && mostExpensive > 500 && mostExpensive <= 750) {
  245.                 premium = premium1[2][1] + 0;
  246.                 gadgetLimit = 750;
  247.             } else if (num.charAt(0) == '4' || num.charAt(0) == '5' && mostExpensive > 750 && mostExpensive <= 1000) {
  248.                 premium = premium1[2][2];
  249.                 gadgetLimit = 1000;
  250.             }
  251.  
  252.             if (excess == 30) {
  253.                 total = premium;
  254.                 finishedPremium = total;
  255.             }
  256.  
  257.             if (excess == 40) {
  258.                 total = premium * .05;
  259.                 finishedPremium = premium - total;
  260.             }
  261.             if (excess == 50) {
  262.                 total = premium * .1;
  263.                 finishedPremium = premium - total;
  264.             }
  265.             if (excess == 60) {
  266.                 total = premium * .15;
  267.                 finishedPremium = premium - total;
  268.             } else if (excess == 70) {
  269.                 total = premium * .2;
  270.                 finishedPremium = premium - total;
  271.             }
  272.  
  273.             if (payment.charAt(0) == 'a') {
  274.                 endPremium = finishedPremium * .1;
  275.                 finishedTotal = (finishedPremium - endPremium) * 12;
  276.             }
  277.             if (payment.charAt(0) == 'm') {
  278.                 finishedTotal = finishedPremium;
  279.             }
  280.  
  281.             if (payment.charAt(0) == 'a') {
  282.                 payment = terms[0];
  283.             } else if (payment.charAt(0) == 'm') {
  284.                 payment = terms[1];
  285.             }
  286.  
  287.             if (num.charAt(0) > '5' || num.charAt(0) <= 0
  288.                     || mostExpensive > 1000 || mostExpensive < 0) {
  289.                 payment = "Rejected";
  290.             }
  291.  
  292.             if (num.charAt(0) == '1') {
  293.                 num = items;
  294.                 num = nums[0];
  295.             }
  296.             if (num.charAt(0) == '2') {
  297.                 num = items;
  298.                 num = nums[1];
  299.             }
  300.             if (num.charAt(0) == '3') {
  301.                 num = items;
  302.                 num = nums[2];
  303.             }
  304.             if (num.charAt(0) == '4') {
  305.                 num = items;
  306.                 num = nums[3];
  307.             } else if (num.charAt(0) == '5') {
  308.                 num = items;
  309.                 num = nums[4];
  310.             }
  311.             //start of the menu
  312.             //output top lines
  313.         System.out.println("+-----------------------------------+");
  314.         System.out.println("|                                   |");
  315.  
  316.         //Outputs client name line
  317.         System.out.print("|  Client: " + name);
  318.  
  319.         //Loops around to make sure that the name is displayed properly
  320.         for (int i = 0; i < 25 - name.length(); i++) {
  321.             System.out.print(" ");
  322.         }
  323.         System.out.println("|");
  324.         System.out.println("|                                   |");
  325.  
  326.         System.out.println("|    Date: " + getDate() + " Ref: " + ref
  327.                 + "  |");
  328.  
  329.         //Print terms and items line
  330.         System.out.print("|   Terms: " + payment);
  331.         if (payment.length() == 6) {
  332.             System.out.print("    ");
  333.         } else if (payment.length() == 7) {
  334.             System.out.print("   ");
  335.         } else {
  336.             System.out.print("  ");
  337.         }
  338.         System.out.print("Items: " + num);
  339.         for (int i = 0; i < 8 - num.length(); i++) {
  340.             System.out.print(" ");
  341.         }
  342.         System.out.println("|");
  343.  
  344.         //Prints excess line
  345.         System.out.print("|  Excess: ");
  346.         System.out.print(excess);
  347.         System.out.println("                       |");
  348.         System.out.println("|                                   |");
  349.  
  350.         //Prints terms and Limit per line
  351.         System.out.print("| " + payment);
  352.         if (payment.length() == 6) {
  353.             System.out.print("    ");
  354.         } else if (payment.length() == 7) {
  355.             System.out.print("   ");
  356.         } else {
  357.             System.out.print("  ");
  358.         }
  359.         System.out.println("     Limit per          |");
  360.  
  361.         //Prints Premium and Gadget line
  362.         System.out.print("| Premium: ");
  363.         if (finishedTotal == -1) {
  364.             System.out.print("-");
  365.             System.out.print("        ");
  366.         } else {
  367.             System.out.printf("£%2.2f", finishedTotal);
  368.             if (finishedTotal < 10) {
  369.                 System.out.print("    ");
  370.             } else if (finishedTotal < 100) {
  371.                 System.out.print("   ");
  372.             } else if (finishedTotal <= 1000) {
  373.                 System.out.print("  ");
  374.             }
  375.         }
  376.         System.out.print("Gadget: " + gadgetLimit);
  377.         if (gadgetLimit < 10) {
  378.             System.out.print("     ");
  379.         } else if (gadgetLimit < 100) {
  380.             System.out.print("    ");
  381.         } else if (gadgetLimit < 1000) {
  382.             System.out.print("   ");
  383.         } else {
  384.             System.out.print("  ");
  385.         }
  386.         System.out.println("  |");
  387.  
  388.         //Prints out bottom two rows
  389.         System.out.println("|                                   |");
  390.         System.out.println("+-----------------------------------+");
  391.    
  392.             //end of the menu
  393.  
  394.             if (num.charAt(0) > 5 && num.charAt(0) <= 0
  395.                     && mostExpensive > 1000 && mostExpensive <= 0) {
  396.                 System.out.println("\nPolicy Rejected");
  397.                 numOfItemsRejected += Integer.parseInt(num);
  398.             }
  399.  
  400.             System.out.println("\nWould you like to re-enter your policy details.");
  401.             System.out.println("Press 1 for Restart and 2 to End: ");
  402.             b = keyboardString.nextInt();
  403.  
  404.             while (b != 1 && b != 2) {
  405.                 System.out.println("\nPress 1 for Restart and 2 to End: ");
  406.  
  407.             }
  408.  
  409.             if (b == 1) {
  410.                 Policy newPolicy = new Policy();
  411.                 newPolicy = createNewPolicy(newPolicy);
  412.  
  413.             } else {
  414.                 System.out.println("Thank you using Policy Manager, you have selected End.");
  415.  
  416.             }
  417.             File Policy = new File("Policy.txt");
  418.  
  419.             try {
  420.                 PrintWriter pw = new PrintWriter(new FileOutputStream(Policy, true));
  421.                 pw.println(getDate() + "\t" + ref + "\t" + num + "\t"
  422.                         + val + "\t" + excess + "\t" + finishedTotal + " " + payment.charAt(0) + "\t"
  423.                         + name);        // write data to file specified by output
  424.  
  425.                 // tidy up and close the file
  426.                 pw.close();
  427.             } catch (FileNotFoundException e) {
  428.  
  429.                 // file already exists, prevent overwriting
  430.                 {
  431.  
  432.                 }
  433.  
  434.             }
  435.             System.exit(0);
  436.         }
  437.         return newPol;
  438.     }
  439.  
  440.     public static boolean validateReference(String ref)// SEPARATE METHOD FOR VALIDATING REFERENCE NUMBER DUE TO COMPLEXITY
  441.     {
  442.         boolean validated = false;
  443.  
  444.         if (ref.length() == 6) // is it 6 digits long?
  445.         {
  446.             if (ref.charAt(0) >= 'A' && ref.charAt(0) <= 'Z') // is character a letter between A and Z?
  447.             {
  448.                 if (ref.charAt(1) >= 'A' && ref.charAt(1) <= 'Z') {
  449.                     if (ref.charAt(2) >= '0' && ref.charAt(2) <= '9') // is it a number?
  450.                     {
  451.                         if (ref.charAt(3) >= '0' && ref.charAt(3) <= '9') {
  452.                             if (ref.charAt(4) >= '0' && ref.charAt(4) <= '9') {
  453.                                 if (ref.charAt(5) >= 'A' && ref.charAt(5) <= 'Z') {
  454.                                     validated = true;
  455.  
  456.                                 }
  457.                             }
  458.                         }
  459.                     }
  460.                 }
  461.             }
  462.         }
  463.  
  464.         if (validated == false) {
  465.             System.out.println("Reference number not recognised format - try again");
  466.  
  467.         }
  468.  
  469.         return validated;
  470.  
  471.     }
  472.  
  473.     public static String getDate() {
  474.         Calendar cal = Calendar.getInstance();
  475.         SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy");
  476.         return sdf.format(cal.getTime());
  477.     }
  478.  
  479.     public static String[] readFile(File Read) throws FileNotFoundException {
  480.         int count = 0;
  481.         Scanner countFile = new Scanner(Read);
  482.         while (countFile.hasNext()) {
  483.  
  484.             countFile.nextLine();
  485.             count++;
  486.         }
  487.         String[] lines = new String[count];
  488.         Scanner readFile = new Scanner(Read);
  489.         for (int i = 0; i < count; i++) {
  490.             lines[i] = readFile.nextLine();
  491.  
  492.         }
  493.         return lines;
  494.     }
  495.  
  496.     public static Policy[] Pol(File Read) throws IOException {
  497.         Policy[] policies = new Policy[readFile(Read).length];
  498.         for (int i = 0; i < readFile(Read).length; i++) {
  499.             String line = readFile(Read)[i];
  500.             Scanner lineScanner = new Scanner(line);
  501.             policies[i] = new Policy();
  502.             policies[i].setPolicyDate(lineScanner.next());
  503.             policies[i].setReference(lineScanner.next());
  504.             policies[i].setNumberOfGadgets(lineScanner.nextInt());
  505.             policies[i].setHighestGadgetValue(lineScanner.nextInt());
  506.             policies[i].setExcess(lineScanner.nextInt());
  507.             policies[i].setPremium(lineScanner.nextInt());
  508.             policies[i].setPaymentTerms(lineScanner.next());
  509.             policies[i].setClientName(lineScanner.next());
  510.  
  511.         }
  512.         return null;
  513.     }
  514.  
  515.     public static void displaySummary() throws FileNotFoundException { //option 2
  516.        
  517.         File a = new File("Policy.txt");
  518.  
  519.         int totalPolicies = 0;
  520.         int numberOfItems = 0;
  521.         int numberPerPolicy = 0;
  522.         double avgPremium = 0.0;
  523.         int RejectedTotal =0;
  524.         int AverageItems =0;
  525.         int finishedTotal = 0;
  526.         String[] months = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  527.         int month1 = 0;
  528.         int month2 = 0;
  529.         int month3 = 0;
  530.         int month4 = 0;
  531.         int month5 = 0;
  532.         int month6 = 0;
  533.         int month7 = 0;
  534.         int month8 = 0;
  535.         int month9 = 0;
  536.         int month10 = 0;
  537.         int month11 = 0;
  538.         int month12 = 0;
  539.  int totalNumberOfLines = 0;
  540.         Scanner keyboardString = new Scanner(a);
  541.        int countMonthlyPolicys = 0;
  542.            int notMonthlyPolicys = 0;
  543.            int totalAvgPremium = 0;
  544.            int annualItems = 0;
  545.            int totalMonthlyItems = 0;
  546.            
  547.            //  Value Holders
  548.            char avgCharHolder;
  549.            int setIntToCharHolder;
  550.          
  551.             int acceptedPolicyCount = 0;
  552.                
  553.                 int calculateItems = 0;
  554.         while (keyboardString.hasNextLine()){
  555.            
  556.             totalNumberOfLines++;
  557.            String premiumLine = keyboardString.nextLine(); // SETS EVERYTHING TO ONE LINE
  558.            avgCharHolder = premiumLine.charAt(19);
  559.            setIntToCharHolder = Character.getNumericValue(avgCharHolder);
  560.            
  561.            
  562.            
  563. //          String getDate = keyboardString.next();
  564. //          String ref = keyboardString.next();
  565. //          numberOfItems = keyboardString.nextInt();
  566. //          String mostExpensive = keyboardString.next();
  567. //          String excess = keyboardString.next();
  568. //          finishedTotal += keyboardString.nextInt();
  569. //          String terms1 = keyboardString.next();
  570. //          String name = keyboardString.nextLine();
  571.        
  572.            
  573.            // locate last tab
  574.            
  575.            int findTerms = premiumLine.lastIndexOf("\t");
  576.                 String theTerms = premiumLine.substring(findTerms -1, findTerms);
  577.                
  578.                 switch(theTerms) {
  579.                     case "A":
  580.                         notMonthlyPolicys++;    
  581.                     case "R":
  582.                         break;
  583.                     case "M":
  584.                     int findPrem = premiumLine.indexOf("\t", 26); // find the first \t in the line
  585.                     String declarePrem = premiumLine.substring(findPrem + 1, findTerms - 2); // locating the premium cost
  586.                     countMonthlyPolicys++;
  587.                    
  588.                     totalAvgPremium = totalAvgPremium + Integer.parseInt(declarePrem);
  589.                      break;
  590.                 }
  591.             avgCharHolder = premiumLine.charAt(19);
  592.      
  593.                 setIntToCharHolder = Character.getNumericValue(avgCharHolder);
  594.          
  595.                  if (avgCharHolder > '0' && avgCharHolder < '6') {
  596.                     //System.out.println(avgCharHolder);
  597.                     setIntToCharHolder = Character.getNumericValue(avgCharHolder);
  598.                     acceptedPolicyCount++;
  599.                     calculateItems = calculateItems + setIntToCharHolder;
  600.                 }
  601.  
  602.        switch(premiumLine.substring(3, 6)) { // LOCATES pos 3 and pos 6 of the String
  603.               case "Jan":
  604.                 month1++;
  605.                 break;
  606.             case "Feb":
  607.                 month2++;
  608.                 break;
  609.             case "Mar":
  610.                 month3++;
  611.                 break;
  612.             case "Apr":
  613.                 month4++;
  614.                 break;
  615.             case "May":
  616.                 month5++;
  617.                 break;
  618.             case "Jun":
  619.                 month6++;
  620.                 break;
  621.             case "Jul":
  622.                 month7++;
  623.                 break;
  624.             case "Aug":
  625.                 month8++;
  626.                 break;
  627.             case "Sep":
  628.                 month9++;
  629.                 break;
  630.             case "Oct":
  631.                 month10++;
  632.                 break;
  633.             case "Nov":
  634.                 month11++;
  635.                 break;
  636.             case "Dec":
  637.                 month12++;
  638.                 break;
  639.        }
  640.         }
  641.        
  642.      
  643.        
  644.            
  645.    
  646.            
  647.        System.out.println("Monthly: "+ totalMonthlyItems);
  648.         System.out.println("---------------------------------------------");
  649.  
  650.         System.out.println("Total Number of policies:" + totalNumberOfLines);  //998
  651.         System.out.println("Average number of items (Accepted policies):" +  calculateItems / acceptedPolicyCount);
  652.         System.out.printf("Average Monthly Premium: £%.2f ", totalAvgPremium / 100.00);//change this to a double
  653.         System.out.println("");
  654.         System.out.println("Number of Policies per Month (inc. non-accepted): ");
  655.         System.out.println(months[0] + "\t" + months[1] + "\t" + months[2] + "\t" + months[3] + "\t" +
  656.                 months[4] + "\t" + months[5] + "\t" + months[6] + "\t" +
  657.                 months[7] + "\t" + months[8] + "\t" + months[9] + "\t" + months[10] + "\t" + months[11] + "\t");
  658.        
  659.         System.out.println(month1 + "\t" + month2 + "\t" + month3 + "\t" + month4 + "\t" + month5 + "\t" + month6 + "\t" +
  660.                 month7 + "\t" + month8 + "\t" + month9 + "\t" + month10 + "\t" + month11 + "\t" + month12 + "\t");
  661.        
  662.  
  663.         System.out.println("\n---------------------------------------------");
  664.  
  665.         System.out.println("\nWould you like to re-start the program?.");
  666.         System.out.println("Press 1 for Restart and 2 to End: ");
  667.         Scanner KeyboardInput = new Scanner(System.in);
  668.         b = KeyboardInput.nextInt();
  669.  
  670.         while (b != 1 && b != 2) {
  671.             System.out.println("\nPress 1 for Restart and 2 to End: ");
  672.  
  673.         }
  674.  
  675.         if (b == 1) {
  676.  
  677.             returnMenu();
  678.  
  679.         } else {
  680.             System.out.println("\n--------------------------------------------------------");
  681.             System.out.println("Thank you for using Policy Manager, you have selected End.");
  682.             System.out.println("\n--------------------------------------------------------");
  683.  
  684.         }
  685.         System.exit(0);
  686.     }
  687.    
  688.  
  689.     public static void displayMonth() { //option 3
  690.        
  691.         String[] months = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  692.        
  693.         Scanner keyboardString = new Scanner(System.in);
  694.  
  695.         System.out.println("---------------------------------------------");
  696.  
  697.         System.out.println("Please enter the name of the file you wish to search?");
  698.         String filename = keyboardString.next();
  699.        
  700.         while (filename.equals("Policy.txt")) {
  701.             File f = new File(filename);
  702.             if (!f.exists())
  703.                 System.out.println("Error: This file does not Exist");
  704.            
  705.         System.out.println("---------------------------------------------");
  706.            
  707.         System.out.println("Please enter specific month: ");
  708.            
  709.         System.out.println("---------------------------------------------");
  710.            
  711.         System.out.println("Total Number of policies:");
  712.         System.out.println("Average number of items (Accepted policies):");
  713.         System.out.println("Average Monthly Premium:");
  714.         System.out.println("Number of Policies for specific month (inc. non-accepted): ");
  715.        
  716.         System.out.println("---------------------------------------------");
  717.        
  718.         System.out.println("\nWould you like to re-start the program?.");
  719.         System.out.println("Press 1 for Restart and 2 to End: ");
  720.         b = keyboardString.nextInt();
  721.  
  722.         while (b != 1 && b != 2) {
  723.             System.out.println("\nPress 1 for Restart and 2 to End: ");
  724.  
  725.         }
  726.  
  727.         if (b == 1) {
  728.  
  729.             returnMenu();
  730.  
  731.         } else {
  732.             System.out.println("Thank you for using Policy Manager, you have selected End.");
  733.  
  734.         }
  735.         System.exit(0);
  736.     }
  737. }
  738. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement