diff --git a/build.xml b/build.xml
new file mode 100644
index 0000000..1a093a1
--- /dev/null
+++ b/build.xml
@@ -0,0 +1,73 @@
+
+
+
+
+
+
+
+
+
+
+ Builds, tests, and runs the project ContractManager.
+
+
+
diff --git a/manifest.mf b/manifest.mf
new file mode 100644
index 0000000..328e8e5
--- /dev/null
+++ b/manifest.mf
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+X-COMMENT: Main-Class will be added automatically by build
+
diff --git a/src/contractmanager/Contract.java b/src/contractmanager/Contract.java
new file mode 100644
index 0000000..ba12432
--- /dev/null
+++ b/src/contractmanager/Contract.java
@@ -0,0 +1,470 @@
+package contractmanager;
+
+import java.io.*;
+import java.util.Calendar;
+import java.text.SimpleDateFormat;
+
+public class Contract {
+ //local variables (contract data) for use in the class
+ private String clientName, clientReference;
+ private int clientPackage, clientDataBundle, clientPeriod;
+ private boolean clientInternationalCalls;
+ public int[][] plans;
+
+ //constructor for init values
+ public Contract()
+ {
+ //init variables to null/empty/default values
+ clientName = "";
+ clientPackage = -1;
+ clientDataBundle = -1;
+ clientReference = "";
+ clientPeriod = -1;
+ clientInternationalCalls = false;
+ //init two dimentional array to store the contract costs
+ plans = new int[][]{
+ {500, 700, 900, -1},
+ {650, 850, 1050, -1},
+ {850, 1050, 1250, 2000}
+ };
+
+ }
+
+ //public getters and setters for vars
+ //returns client name
+ public String getClientName()
+ {
+ return clientName;
+ }
+
+ //sets client's name
+ public boolean setClientName(String n)
+ {
+ //data validation (not null, not empty, most contain a space, muse be longer than 3 and less than 25), returns false
+ if ((n == null) || (n.equals("")) || !n.contains(" ") || n.length() < 3 || n.length() > 25)
+ {
+ return false;
+ }
+ else
+ {
+ clientName = n;
+ return true;
+ }
+
+ }
+
+ //returns client's package
+ public int getClientPackage()
+ {
+ return clientPackage;
+ }
+
+ //sets client's package
+ public boolean setClientPackage(String nS)
+ {
+ //checks to make sure input can be converted to an integer, if not returns false (not a valid input)
+ int n;
+ if (isStringInt(nS))
+ {
+ n = Integer.parseInt(nS);
+ }
+ else
+ {
+ return false;
+ }
+ //data validation (if it's not 1, 2 or 3, return false)
+ if (n != 1 && n != 2 && n != 3)
+ {
+ return false;
+ }
+ else
+ {
+ clientPackage = n;
+ return true;
+ }
+
+ }
+
+ //returns client's data bundle
+ public int getClientDataBundle()
+ {
+ return clientDataBundle;
+ }
+
+ //sets cleint's data bundle
+ public boolean setClientDataBundle(String nS)
+ {
+ //checks to make sure input can be converted to an integer, if not returns false (not a valid input)
+ int n;
+ if (isStringInt(nS))
+ {
+ n = Integer.parseInt(nS);
+ }
+ else
+ {
+ return false;
+ }
+ //data validation (follows data validation rules set by client for the data bundle)
+ if (n != 1 && n != 2 && n != 3 && (n != 4 && (n == 1 || n == 2)))
+ {
+ return false;
+ }
+ else
+ {
+ clientDataBundle = n;
+ return true;
+ }
+ }
+
+ //returns the client's reference code
+ public String getClientReference()
+ {
+ return clientReference;
+ }
+
+ //sets the client's reference code
+ public boolean setClientReference(String n)
+ {
+ //data validation to make sure the format is 'AA111A' (Letter, Letter, Number, Number, Number, Letter)
+ if (n.length() == 6)
+ {
+ //data validation
+ //OLD VALIDATION USING CHAR VALUES; CHANGED TO CHARACTER CLASS CHECKS
+ //if ((n.charAt(0) >= 'A' && n.charAt(0) <= 'Z') && (n.charAt(1) >= 'A' && n.charAt(1) <= 'Z') && (n.charAt(2) >= '0' && n.charAt(2) <= '9') && (n.charAt(3) >= '0' && n.charAt(3) <= '9') && (n.charAt(4) >= '0' && n.charAt(4) <= '9') && (n.charAt(5) >= 'A' && n.charAt(5) <= 'Z'))
+ if (Character.isLetter(n.charAt(0)) && Character.isLetter(n.charAt(1)) && Character.isDigit(n.charAt(2)) && Character.isDigit(n.charAt(3)) && Character.isDigit(n.charAt(4)) && Character.isLetter(n.charAt(5)))
+ {
+ clientReference = n;
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ else
+ {
+ return false;
+ }
+
+ }
+
+ //returns the client's contract period
+ public int getClientPeriod()
+ {
+ return clientPeriod;
+ }
+
+ //sets the client's contract period
+ public boolean setClientPeriod(String nS)
+ {
+ //checks to make sure input can be converted to an integer, if not returns false (not a valid input)
+ int n;
+ if (isStringInt(nS))
+ {
+ n = Integer.parseInt(nS);
+ }
+ else
+ {
+ return false;
+ }
+ //checks to make sure the contract length is valid (1, 12, 18 and 24) else returns false
+ if (n == 1 || n == 12 || n == 18 || n == 24 )
+ {
+ //returns false since business accounts can't be one month long
+ if ((n == 1 && clientReference.charAt(5) == 'B'))
+ {
+ return false;
+ }
+ clientPeriod = n;
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ //returns the client's selection on international calls
+ public boolean getClientInternationalCalls()
+ {
+ return clientInternationalCalls;
+ }
+
+ //sets the clien't selection on international calls
+ public boolean setClientInternationalCalls(String n)
+ {
+ //data validation, yes or no
+ if (n.equalsIgnoreCase("y"))
+ {
+ clientInternationalCalls = true;
+ return true;
+ }
+ else if (n.equalsIgnoreCase("n"))
+ {
+ clientInternationalCalls = false;
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+
+ public int getClientMonthlyRate()
+ {
+ //returns the cost in the package grid
+ return plans[clientPackage-1][clientDataBundle-1];
+ }
+
+ public int getPromotionAmmount()
+ {
+
+ boolean businessAccount = false;
+ //creates the default multiplyer (1)
+ double promoMultiplyer = 1;
+ //checks to see if they're a business account
+ if (clientReference.charAt(5) == 'B')
+ {
+ businessAccount = true;
+ }
+ //if they are they get a 10% discount (also does other calculations to see if they apply for a discount in other areas)
+ if (businessAccount)
+ {
+ promoMultiplyer = promoMultiplyer - 0.1;
+ }
+ else if (clientPeriod == 18 || clientPeriod == 12)
+ {
+ promoMultiplyer = promoMultiplyer - 0.05;
+ }
+ else if (clientPeriod == 24)
+ {
+ promoMultiplyer = promoMultiplyer - 0.1;
+ }
+ if (clientInternationalCalls)
+ {
+ promoMultiplyer = promoMultiplyer + 0.15;
+ }
+ //returns the complete monthly rate including discounts/or adds
+ return (int)(getClientMonthlyRate() * promoMultiplyer);
+ }
+
+ public int getPromotionPercentage()
+ {
+ //this gets the percentage of the promotion
+ boolean businessAccount = false;
+ int promoMultiplyer = 0;
+ if (clientReference.charAt(5) == 'B')
+ {
+ businessAccount = true;
+ }
+ if (businessAccount)
+ {
+ promoMultiplyer = promoMultiplyer + 10;
+ }
+ else if (clientPeriod == 18 || clientPeriod == 12)
+ {
+ promoMultiplyer = promoMultiplyer + 5;
+ }
+ else if (clientPeriod == 24)
+ {
+ promoMultiplyer = promoMultiplyer + 10;
+ }
+
+ return promoMultiplyer;
+ }
+
+ public String getPackageString(int i)
+ {
+ //returns the text for the value of package
+ if (i == 1)
+ {
+ return "Small (300)";
+ }
+ if (i == 2)
+ {
+ return "Medium (600)";
+ }
+ if (i == 3)
+ {
+ return "Large (1200)";
+ }
+ return "";
+ }
+
+ public String getDataString(int i)
+ {
+ //returns the text for the value of the data bundle
+ if (i == 1)
+ {
+ return "Low (1GB)";
+ }
+ if (i == 2)
+ {
+ return "Medium (4GB)";
+ }
+ if (i == 3)
+ {
+ return "High (8GB)";
+ }
+ if (i == 4)
+ {
+ return "Unlimited";
+ }
+ return "";
+ }
+
+ public String getBusinessStatus(String s)
+ {
+ //returns a string of the business type (Business or Regular)
+ if (s.charAt(5) == 'B')
+ {
+ return "Business";
+ }
+ if (s.charAt(5) == 'N')
+ {
+ return "Regular";
+ }
+ return "";
+ }
+
+ public String getIntlCallsYesNo(boolean n)
+ {
+ //returns the string of the value of international calls
+ if (n == true)
+ {
+ return "Yes";
+ }
+ return "No";
+
+ }
+
+
+ private String convertBoolToYN(Boolean n)
+ {
+ //converts a boolean to a string of Y or N
+ if (n)
+ {
+ return "Y";
+ }
+ return "N";
+ }
+
+ //checks if a string can be cast to an int
+ private boolean isStringInt(String nS)
+ {
+ try
+ {
+ Integer.parseInt(nS);
+ }
+ catch(Exception e)
+ {
+ return false;
+ }
+ return true;
+ }
+
+ //writes the whole contract to a line in a text file
+ public boolean writeToFile()
+ {
+ //declares a new file to be used for the writer
+ File contractFile = new File("contracts.txt");
+ PrintWriter output = null;
+
+ //checks to make sure the file exists, if it doesn't it creates a new one
+ if (!contractFile.exists())
+ {
+ try
+ {
+ contractFile.createNewFile();
+ }
+ catch (Exception e)
+ {
+ return false;
+ }
+ }
+ //creates a new FileWriter in the file created earlier, also a printWriter
+ try
+ {
+ FileWriter writeToContract = new FileWriter(contractFile, true);
+ output = new PrintWriter(writeToContract);
+ }
+ catch (Exception e)
+ {
+
+ }
+
+ //get date and create the format for it
+ Calendar cal = Calendar.getInstance();
+ SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");
+
+ //actual writing to file
+ output.append(sdf.format(cal.getTime()) + "\t" + this.clientPackage + "\t" + this.clientDataBundle + "\t" + this.clientPeriod + "\t" + this.convertBoolToYN(this.clientInternationalCalls) + "\t" + this.clientReference + "\t" + this.getPromotionAmmount() + "\t" + this.clientName + "\n");
+ output.close();
+ return true;
+ }
+
+ //used for writing the contract to the screen
+ public String formatStringLine(int lineNumber, String lineData, String lineData2)
+ {
+ //return data needed for the line referenced
+ if (lineNumber == 3)
+ {
+ String spaceLengthData = "| " + lineData;
+ return spaceLengthData + getSpaces(spaceLengthData.length(), 45) + "|";
+ }
+ if (lineNumber == 4)
+ {
+ return "| Ref: " + lineData + " Date: " + lineData2 + " |";
+ }
+ if (lineNumber == 5)
+ {
+ String spaceLengthData = "| Package: " + lineData;
+ String spaceLengthData2 = "Data: " + lineData2;
+ return spaceLengthData + getSpaces(lineData.length(), 15) + spaceLengthData2 + getSpaces(lineData2.length(), 12) + "|";
+ }
+ if (lineNumber == 6)
+ {
+ String spaceLengthData = "| Period: " + lineData;
+ String spaceLengthData2 = "Type: " + lineData2;
+ return spaceLengthData + getSpaces(lineData.length(), 15) + spaceLengthData2 + getSpaces(lineData2.length(), 12) + "|";
+ }
+ if (lineNumber == 8)
+ {
+ String localPercent = " ";
+ if (this.getPromotionPercentage() > 0)
+ {
+ localPercent = "%";
+ }
+ String spaceLengthData = "| Discount: " + lineData + localPercent;
+ String spaceLengthData2 = "Intl. Calls: " + lineData2;
+ return spaceLengthData + getSpaces(lineData.length() + 1, 8) + spaceLengthData2 + getSpaces(lineData2.length(), 12) + "|";
+ }
+ if (lineNumber == 10)
+ {
+ String tempString = (this.getPromotionPercentage() <= 0 ? "" : "Discounted ").concat("Monthly Charge: £" + String.format("%.2f", (float)(getPromotionAmmount() / 100)));
+ int localOffset = 0;
+ //if the length is odd, an offset is needed for the spaces
+ if (tempString.length() % 2 == 1)
+ {
+ localOffset = 1;
+ }
+ return "|" + getSpaces(0, ((int)Math.round(44 - tempString.length()) / 2)) + tempString + getSpaces(0, ((int)Math.round(44 - tempString.length()) / 2 + localOffset)) + "|";
+ }
+ return "";
+ }
+
+ //used for calculating the needed spaces for each line in the printout
+ private String getSpaces(int lineLength, int lineSpaces)
+ {
+ String tempSpaces = "";
+ while (lineLength < lineSpaces)
+ {
+ tempSpaces = tempSpaces + " ";
+ lineLength++;
+ }
+ return tempSpaces;
+ }
+
+
+}
diff --git a/src/contractmanager/ContractFileManager.java b/src/contractmanager/ContractFileManager.java
new file mode 100644
index 0000000..ac7ffcb
--- /dev/null
+++ b/src/contractmanager/ContractFileManager.java
@@ -0,0 +1,279 @@
+package contractmanager;
+
+import java.util.Scanner;
+import java.io.*;
+import java.util.ArrayList;
+import java.util.List;
+
+public class ContractFileManager {
+ final String archive = "archive.txt";
+ final String contracts = "contracts.txt";
+ String[] monthString;
+
+ void ContractFileManager()
+ {
+ //Constructor, creates array with months for later use
+ monthString = new String[]{"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
+ }
+
+ //Method for creating a scanner for a given filename
+ private Scanner createScanner(String fileName)
+ {
+ //Creates a scanner if the file is found (and returns it), if not returns null
+ Scanner fileScanner;
+ try
+ {
+ fileScanner = new Scanner(new File(fileName));
+ }
+ catch(FileNotFoundException e)
+ {
+ return null;
+ }
+ return fileScanner;
+ }
+
+ public int fileLineCount(String fileName, int monthSelected)
+ {
+ //This first section is to detect whether only one month is being searched or not
+ //-1 means all months are searched
+ boolean allMonths = false;
+ if (monthSelected == -1)
+ {
+ allMonths = true;
+ }
+ //declares a new scanner to read text file
+ Scanner fileScanner = createScanner(fileName);
+ if (fileScanner != null)
+ {
+ int counter = 0;
+ boolean isLineNull = false;
+ while (!isLineNull)
+ {
+ try
+ {
+ String nextLine = fileScanner.nextLine();
+ //checks to make sure the line contains text, then checks if a specific month is needed to be searched
+ if (!nextLine.equals("") && (allMonths || getMonthInt(nextLine.substring(3, 6)) == monthSelected))
+ {
+ //counter is increased by 1
+ counter++;
+ }
+ }
+ catch(Exception e)
+ {
+ isLineNull = true;
+ }
+ }
+ fileScanner.close();
+ //return the number of lines detected
+ return counter;
+ }
+ else
+ {
+ return -1;
+ }
+ }
+
+ public int getContractsWithHighUnlimited(String fileName, int monthSelected)
+ {
+ //This first section is to detect whether only one month is being searched or not
+ //-1 means all months are searched
+ boolean allMonths = false;
+ if (monthSelected == -1)
+ {
+ allMonths = true;
+ }
+ Scanner fileScanner = createScanner(fileName);
+ if (fileScanner != null)
+ {
+ int counter = 0;
+ boolean isLineNull = false;
+ while (!isLineNull)
+ {
+ try
+ {
+ String nextLine = fileScanner.nextLine();
+ //checks to make sure the line contains text, then checks if a specific month is needed to be searched
+ if (!nextLine.equals("") && (allMonths || getMonthInt(nextLine.substring(3, 6)) == monthSelected))
+ {
+ //check if the 2nd element in the line contains 3 or 4, if it does increase the counter by 1
+ String[] splitNextLine = nextLine.split("\t");
+ if (splitNextLine[2].equals("3") || splitNextLine[2].equals("4"))
+ {
+ counter++;
+ }
+ }
+ }
+ catch(Exception e)
+ {
+ isLineNull = true;
+ }
+ }
+ fileScanner.close();
+ return counter;
+ }
+ else
+ {
+ return -1;
+ }
+ }
+
+ public int getAverageOfLargePackages(String fileName, int monthSelected)
+ {
+ //This first section is to detect whether only one month is being searched or not
+ //-1 means all months are searched
+ boolean allMonths = false;
+ if (monthSelected == -1)
+ {
+ allMonths = true;
+ }
+ Scanner fileScanner = createScanner(fileName);
+ if (fileScanner != null)
+ {
+ int counter = 0;
+ int totalHigh = 0;
+ boolean isLineNull = false;
+ while (!isLineNull)
+ {
+ try
+ {
+ String nextLine = fileScanner.nextLine();
+ //checks to make sure the line contains text, then checks if a specific month is needed to be searched
+ if (!nextLine.equals("") && (allMonths || getMonthInt(nextLine.substring(3, 6)) == monthSelected))
+ {
+ //
+ String[] splitNextLine = nextLine.split("\t");
+ if (splitNextLine[1].equals("3"))
+ {
+ //get the first element and add it to the totalHigh var
+ totalHigh = Integer.parseInt(splitNextLine[6]) + totalHigh;
+ counter++;
+ }
+ }
+ }
+ catch(Exception e)
+ {
+ isLineNull = true;
+ }
+ }
+ fileScanner.close();
+ //make sure that there's no division by 0!
+ if (counter == 0)
+ {
+ return 0;
+ }
+ //return mean in a currency (/100)
+ return (int)(totalHigh / counter);
+ }
+ else
+ {
+ return -1;
+ }
+ }
+
+ //USED DURING TESTING
+ /*public String[] testStringSplit(String fileName, int monthSelected)
+ {
+ Scanner fileScanner = createScanner(fileName);
+ fileScanner.close();
+ return fileScanner.nextLine().split("\t");
+ }*/
+
+ public int[] getCountOfContractsPerMonth(String fileName, int monthSelected)
+ {
+ //This first section is to detect whether only one month is being searched or not
+ //-1 means all months are searched
+ boolean allMonths = false;
+ if (monthSelected == -1)
+ {
+ allMonths = true;
+ }
+ Scanner fileScanner = createScanner(fileName);
+ if (fileScanner != null)
+ {
+ //create an array for all months
+ int[] monthCounter = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+ boolean isLineNull = false;
+ while (!isLineNull)
+ {
+ try
+ {
+ String nextLine = fileScanner.nextLine();
+ if (!nextLine.equals("") && (allMonths || getMonthInt(nextLine.substring(3, 6)) == monthSelected))
+ {
+ //increases the counter for that month by one
+ monthCounter[getMonthInt(nextLine.substring(3, 6)) - 1]++;
+ }
+ }
+ catch(Exception e)
+ {
+ isLineNull = true;
+ }
+ }
+ fileScanner.close();
+ return monthCounter;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public List getSearchValues(String fileName, String searchValues)
+ {
+ //create an array list for the results from the search, since it can be many
+ List totalSearchValues = new ArrayList();
+ Scanner fileScanner = createScanner(fileName);
+ if (fileScanner != null)
+ {
+ boolean isLineNull = false;
+ while (!isLineNull)
+ {
+ try
+ {
+ String nextLine = fileScanner.nextLine();
+ if (!nextLine.equals(""))
+ {
+ String[] splitNextLine = nextLine.split("\t");
+ //if the 5th or 7th element contains the serach value, the line is added to the list
+ if (splitNextLine[5].toLowerCase().contains(searchValues.toLowerCase()) || splitNextLine[7].toLowerCase().contains(searchValues.toLowerCase()))
+ {
+ totalSearchValues.add(splitNextLine);
+ }
+ }
+ }
+ catch(Exception e)
+ {
+ isLineNull = true;
+ }
+ }
+ fileScanner.close();
+ }
+ //list is then returned
+ return totalSearchValues;
+ }
+
+ //converts a month 3 length string to an integer
+ private int getMonthInt(String monthString)
+ {
+ switch (monthString)
+ {
+ case "Jan" : return 1;
+ case "Feb" : return 2;
+ case "Mar" : return 3;
+ case "Apr" : return 4;
+ case "May" : return 5;
+ case "Jun" : return 6;
+ case "Jul" : return 7;
+ case "Aug" : return 8;
+ case "Sep" : return 9;
+ case "Oct" : return 10;
+ case "Nov" : return 11;
+ case "Dec" : return 12;
+ default : return 0;
+ }
+ }
+
+
+
+}
diff --git a/src/contractmanager/ContractManager.java b/src/contractmanager/ContractManager.java
new file mode 100644
index 0000000..681f43c
--- /dev/null
+++ b/src/contractmanager/ContractManager.java
@@ -0,0 +1,257 @@
+package contractmanager;
+
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Locale;
+import java.util.Scanner;
+
+public class ContractManager {
+ //Public vars
+ /* Moved to Contract Class, private
+ public static String clientName = "";
+ public static int clientPackage = -1;
+ public static int clientDataBundle = -1;
+ public static String clientReference = "";
+ public static int clientPeriod = -1;
+ public static boolean clientInternationalCalls = false;
+ public static double clientMonthlyRate = -1;
+ */
+
+
+ public static void main(String[] args) {
+ int userInput = -1;
+ String userInputString = "";
+ Scanner userInputScanner = new Scanner(System.in);
+
+ //main menu logic, loop used until the user inputs 0
+ while(userInput != 0)
+ {
+ //displays menu after each option is done
+ displayMenu();
+ //gets the user input
+
+ userInputString = userInputScanner.nextLine();
+ try
+ {
+ userInput = Integer.parseInt(userInputString);
+ }
+ catch (Exception e)
+ {
+
+ }
+
+ //if statements for branching and selecting the option the user asked for
+ if (userInput == 1)
+ {
+ //creates a new contract
+ enterNewContract();
+ }
+ else if (userInput == 2)
+ {
+ //creates a local scanner for the options of the user
+ Scanner userInputScannerLocal = new Scanner(System.in);
+ //asks for user input into which file to search
+ System.out.println("Please input '1' for contracts.txt, please input '2' for archive.txt: ");
+ String fileName;
+ if (userInputScannerLocal.hasNext("1"))
+ {
+ fileName = "contracts.txt";
+ }
+ else
+ {
+ fileName = "archive.txt";
+ }
+ //prints out the data
+ taskReturnData(fileName, -1, 2);
+
+ }
+ else if (userInput == 3)
+ {
+ //creates a local scanner for the options of the user
+ Scanner userInputScannerLocal = new Scanner(System.in);
+ //asks for user input into which file to search
+ System.out.println("Please input '1' for contracts.txt, please input '2' for archive.txt: ");
+ String fileName;
+ if (userInputScannerLocal.hasNext("1"))
+ {
+ fileName = "contracts.txt";
+ }
+ else
+ {
+ fileName = "archive.txt";
+ }
+ //asks for the month to search, then executes the search
+ System.out.println("Please input the number of the month you wish to search: ");
+ int monthSelected = userInputScanner.nextInt();
+ taskReturnData(fileName, monthSelected, 3);
+ }
+ else if (userInput == 4)
+ {
+ //creates a local scanner for the options of the user
+ Scanner userInputScannerLocal = new Scanner(System.in);
+ //asks for user input into which file to search
+ System.out.println("Please input '1' for contracts.txt, please input '2' for archive.txt: ");
+ String fileName;
+ if (userInputScannerLocal.hasNext("1"))
+ {
+ fileName = "contracts.txt";
+ }
+ else
+ {
+ fileName = "archive.txt";
+ }
+ System.out.println("Please input the search values: ");
+ executeSearch(userInputScanner.next(), fileName);
+ }
+ else if (userInput != 0)
+ {
+ //show error
+ System.out.println("Please enter a valid option.");
+ }
+ }
+
+ }
+
+ static void displayMenu()
+ {
+ //Displays full menu
+ System.out.println("1. Enter new Contract");
+ System.out.println("2. Display Summary of Contracts");
+ System.out.println("3. Display Summary of Contracts for Selected Month");
+ System.out.println("4. Find and display Contract");
+ System.out.println("0. Exit");
+ }
+
+ static void enterNewContract()
+ {
+ //Create new instance of class
+ Contract localCon = new Contract();
+
+ //Create scanner for user input
+ Scanner userInputScanner = new Scanner(System.in);
+
+
+ System.out.print("Please enter the client's Name: ");
+ while(!localCon.setClientName(userInputScanner.nextLine()))
+ {
+ //Failed to add data
+ System.out.print("Invalid name. Please re-enter the client's name: ");
+ }
+
+ System.out.print("Please enter the Package: ");
+ while (!localCon.setClientPackage(userInputScanner.next()))
+ {
+ //Failed to add data
+ System.out.print("Invalid package. Please re-enter the client's package: ");
+ }
+
+ System.out.print("Please enter the Data Bundle: ");
+ while (!localCon.setClientDataBundle(userInputScanner.next()))
+ {
+ //Failed to add data
+ System.out.print("Invalid Data Bundle. Please re-enter the client's Data Bundle: ");
+ }
+
+ System.out.print("Please enter the Reference Number: ");
+ while(!localCon.setClientReference(userInputScanner.next()))
+ {
+ //Failed to add data
+ System.out.print("Invalid Reference Number. Please re-enter the Reference Number: ");
+ }
+
+ System.out.print("Please enter the Period: ");
+ while(!localCon.setClientPeriod(userInputScanner.next()))
+ {
+ //Failed to add data
+ System.out.print("Invalid contract period. Please re-enter the Contract Period: ");
+ }
+
+ System.out.print("Please enter if the client wants International Calls (Y/N): ");
+ while(!localCon.setClientInternationalCalls(userInputScanner.next()))
+ {
+ //Failed to add data
+ System.out.print("Invalid selection. Please re-enter International Calls (Y/N): ");
+ }
+ printContract(localCon);
+ //write data to file
+ localCon.writeToFile();
+
+ }
+
+ static void printContract(Contract localCon)
+ {
+ //get date in correct format for print
+ Calendar cal = Calendar.getInstance();
+ SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy", Locale.ENGLISH);
+
+ //print final contract
+ System.out.println("|++++++++++++++++++++++++++++++++++++++++++++|");
+ System.out.println("| |");
+ System.out.println(localCon.formatStringLine(3, "Customer: " + localCon.getClientName(), null));
+ System.out.println(localCon.formatStringLine(4, localCon.getClientReference(), sdf.format(cal.getTime())));
+ System.out.println(localCon.formatStringLine(5, localCon.getPackageString(localCon.getClientPackage()), localCon.getDataString(localCon.getClientDataBundle())));
+ System.out.println(localCon.formatStringLine(6, String.valueOf(localCon.getClientPeriod()).concat(localCon.getClientPeriod() == 1 ? " Month" : " Months"), localCon.getBusinessStatus(localCon.getClientReference())));
+ System.out.println("| |");
+ System.out.println(localCon.formatStringLine(8, String.valueOf(localCon.getPromotionPercentage() <= 0 ? "None" : localCon.getPromotionPercentage()), localCon.getIntlCallsYesNo(localCon.getClientInternationalCalls())));
+ System.out.println("| |");
+ System.out.println(localCon.formatStringLine(10, null, null));
+ System.out.println("|++++++++++++++++++++++++++++++++++++++++++++|");
+ }
+
+ //displays the data needed for option 2 & 3
+ private static void taskReturnData(String fileName, int monthSelected, int userSelection)
+ {
+ //calls methods from ContractFileManager class to handle user options
+ ContractFileManager cfm = new ContractFileManager();
+ int[] monthCounts = cfm.getCountOfContractsPerMonth(fileName, monthSelected);
+ String monthResults = "";
+ int counter = 0;
+ // if the user selection is 2, the month's element needs to be outputted
+ if (userSelection == 2)
+ {
+ //check every month
+ for (int countedNumber : monthCounts)
+ {
+ int numberOfSpacesNeeded = 4 - Integer.toString(countedNumber).length();
+ monthResults = monthResults + Integer.toString(countedNumber);
+ //string creation
+ while (numberOfSpacesNeeded >= 0)
+ {
+ monthResults = monthResults + " ";
+ numberOfSpacesNeeded--;
+ }
+ }
+ }
+ //output data
+ System.out.println("");
+ System.out.println("Total number of contracts: " + cfm.fileLineCount(fileName, monthSelected));
+ System.out.println("Contracts with High or Unlimited Data Bundles: " + cfm.getContractsWithHighUnlimited(fileName, monthSelected));
+ System.out.println("Average charge for large packages: " + String.format("%.2f", (float)(((float)cfm.getAverageOfLargePackages(fileName, monthSelected) / 100))));
+ System.out.println("");
+ //only need to output if the user selects 2
+ if (userSelection == 2)
+ {
+ System.out.println("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec");
+ System.out.println(monthResults);
+ }
+ }
+
+ private static void executeSearch(String searchString, String fileName)
+ {
+ ContractFileManager cfm = new ContractFileManager();
+ //for each of the results found, print them to the screen
+ for (String[] searchResult : cfm.getSearchValues(fileName, searchString))
+ {
+ Contract localCon = new Contract();
+ localCon.setClientName(searchResult[7]);
+ localCon.setClientPackage(searchResult[1]);
+ localCon.setClientDataBundle(searchResult[2]);
+ localCon.setClientReference(searchResult[5]);
+ localCon.setClientPeriod(searchResult[3]);
+ localCon.setClientInternationalCalls(searchResult[4]);
+ printContract(localCon);
+ }
+ }
+
+
+}