Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Link From A Driver Class To The Subclasses

  1. #1
    Junior Member
    Join Date
    May 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Link From A Driver Class To The Subclasses

    At the moment, my driver class is like a standalone class where it is not link to the Individual, NGO, government and POrganisation classes. Previously, I tried to use the getfunctions to search for the data from the custArray but there were so many errors. So appreciate if anyone could help me with that.

    This is my driver class

    import java.util.*;
    import java.io.*;
    import java.text.*;
    public class driver
    {
     
    //------------------MAIN DRIVER------------------------
    public static void main(String[]args) throws Exception
    {
     
    //System declarations.
    Scanner input = new Scanner(System.in);
    //variable declaration.
    String username, password;
    //log writer
    BufferedReader BR = new BufferedReader(new FileReader("log.txt")); String thisLine;//BR use.
    FileWriter lw = new FileWriter("log.txt", true);
    //Today date and time function.
    Calendar cal = Calendar.getInstance();
    SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    String todayD = df.format(cal.getTime());
    int h = cal.get(Calendar.HOUR_OF_DAY);
    int m = cal.get(Calendar.MINUTE);
    int s = cal.get(Calendar.SECOND);
    //admin menu
    System.out.println("Welcome to CMM System");
    System.out.println("----------------------------------------*");
    System.out.println("Please enter your username: " );
    username = input.nextLine();
    System.out.println("Please enter your password: ");
    password = input.nextLine();
     
    //admin and password checking
    if((!username.equals("admin"))&&(!password.equals("admin")))//add a loop later on;
    {
    System.out.println("Your username or password is incorrect!");
    System.out.println("Try again...");
    } else
    {
    System.out.println("You are checked in!");
    lw.write(h+":"+m+":"+s+" "+todayD+" admin successfully login"+"\r\n");
    lw.close();
    mainMenu();//execute main menu.
    }
    }
     
    //-------------LIST OF METHODS-----------------------//
    public static void mainMenu() throws Exception
    {
    //Today date and time function.
    Calendar cal = Calendar.getInstance();
    SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    String todayD = df.format(cal.getTime());
    int h = cal.get(Calendar.HOUR_OF_DAY);
    int m = cal.get(Calendar.MINUTE);
    int s = cal.get(Calendar.SECOND);
    //System declaration.
    Scanner input = new Scanner(System.in);
    FileWriter lw = new FileWriter("log.txt",true);
    int option;
    do
    {
    //Main Menu
    System.out.println("");
    System.out.println("--------MENU--------");
    System.out.println("");
    System.out.println("1. Customer profile");
    System.out.println("2. Manage customer account");
    System.out.println("3. Manage customer services");
    System.out.println("4. Manage Subscribe Packages item");
    System.out.println("5. Manage Packages item");
    System.out.println("6. Manage TV Programmes");
    System.out.println("7. Add TV programme to packages item");
    System.out.println("8. Read report");
    System.out.println("9. Exit Program");
    //Allow staff to select options
    System.out.println("Please enter your option: ");
    option = input.nextInt();
    }while((option>9)||(option<1));//check validity
    switch(option)
    {
    case 1 :
    try
    {
    customerProfile();
    break;
    }catch(Exception e)
    {
    input.nextLine();
    //customerProfile();//test.
    }break;
    case 2 :
    try
    {
    manageCustomer();
    break;
    }catch(InputMismatchException e)
    {
    input.nextLine();
    }break;
    case 3 :
    try
    {
    manageService();
    break;
    }catch(InputMismatchException e)
    {
    input.nextLine();
    }break;
    case 4 :
    try
    {
    manageSubPackage();
    break;
    }catch(InputMismatchException e)
    {
    input.nextLine();
    }break;
    case 5 :
    try
    {
    managePack();
    break;
    }catch(InputMismatchException e)
    {
    input.nextLine();
    }break;
    case 6 :
    try
    {
    manageProg();
    break;
    }catch(InputMismatchException e)
    {
    input.nextLine();
    }break;
    case 7 :
    try
    {
    addProgToPack();
    break;
    }catch(InputMismatchException e)
    {
    input.nextLine();
    }break;
    case 8 :
    try
    {
    report();
    break;
    }catch(InputMismatchException e)
    {
    input.nextLine();
    }break;
    case 9 :
    System.out.println("Logging out..");
    lw.write(h+":"+m+":"+s+" "+todayD+" admin logged out");
    lw.close();
    System.exit(0);
    break;
     
    default	: System.out.println("problem at main menu.");
    break;//end of main menu
    }
    }
     
    public static void proceed() throws Exception //proceed to main menu.
    {	Scanner input = new Scanner(System.in);
    boolean check = false;
    String yesno;
    System.out.println("-*-*-*-*-*-*-*-*-*-*-*-*-*");
    System.out.println("Press y to continue..");
    do
    {
    yesno = input.nextLine();
    check = validation.validateDecision(yesno);
    }while(check == false);
     
     
    System.out.println("Do you wish to continue..?");
    if(check==true)
    {
    mainMenu();
    }else if(check==false)
    {	System.out.println("You have been logged off.");
    System.exit(0);
    }
     
     
     
    }
     
    public static void customerProfile() throws Exception
    {
    //System declarations.
    Scanner input = new Scanner(System.in);
    BufferedReader BR = new BufferedReader(new FileReader("customer.txt")); String thisLine;//BR use.
    FileWriter lw = new FileWriter("log.txt",true);
    BR.mark(7000);//whenever BR.reset() is called, it will return to the wherever you call mark. which is beginning of the file.
    //others declaration.
    boolean check = false;
    int counter = 0;
    //Today date function.
    Calendar cal = Calendar.getInstance();
    SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    String todayD = df.format(cal.getTime());
    int h = cal.get(Calendar.HOUR_OF_DAY);
    int m = cal.get(Calendar.MINUTE);
    int s = cal.get(Calendar.SECOND);
    //WELCOME NOTE.
    System.out.println("You have selected customer profile. ");
    //Options.
    System.out.println("1. Search customer profile");
    System.out.println("2. Return to main menu");//consider edit profile.
    System.out.println("Select your options: ");
    int choice;
    choice = input.nextInt();
     
    switch(choice)
    {	case 1 : //search file and compare.
    while(check == false)
    {
    System.out.println("Please enter client's account number: ");
    String accNo = input.nextLine(); accNo = input.nextLine();//avoid bug. test using int (preferably.)
    while((thisLine=BR.readLine())!=null)// make a comparison if it doesn't exist.
    {	String[] custArray = thisLine.split("--");
    if(accNo.equals(custArray[0]))
    {
    check=true;
    System.out.println("-------Customer informations-------");
    System.out.println("Customer's account number: " + custArray[0]);
    System.out.println("Customer's account type: " + custArray[1]);
    System.out.println("Customer's account name: " + custArray[2]);
    System.out.println("Customer's account ID: " + custArray[3]);
    System.out.println("Customer's account address: " + custArray[4]);
    System.out.println("Customer's account contact number: " + custArray[5]);
    System.out.println("Customer's account creation date: " + custArray[6]);
    System.out.println("Customer's status: " + custArray[7] + "\r\n");
    lw.write(h+":"+m+":"+s+" "+todayD+" admin view "+accNo+" information");
    lw.close();
    BufferedReader BRsc = new BufferedReader(new FileReader("smartcard.txt"));//BR for smartcard.txt
    while((thisLine=BRsc.readLine())!=null)
    {
     
    String scArray[] = thisLine.split("--");
    if(custArray[0].equals(scArray[0]))
    {counter++;
    String result = thisLine.replaceAll("--", " ");
     
    System.out.println("-------Smartcard informations-------");
    System.out.println("Smartcard's subs no : " + counter);
    System.out.println("Smartcard's account number: " + scArray[0]);//smartcard account holder's acc number.
    System.out.println("Smartcard's smartcard number: " + scArray[1]);
    System.out.println("Smartcard's decoder number: " + scArray[2]);
    System.out.println("Smartcard's installation address: " + scArray[3]);
    System.out.println("Smartcard's status: " + scArray[4] + "\r\n");
    System.out.println();
    }
     
    }
    }
    }BR.reset();
    }
    case 2 : // return to main menu
    mainMenu();
    default	: System.out.println("Invalid input. Please try again..");
    break;
    }
    }
     
    public static void manageCustomer() throws Exception
    {
    //System declarations.
    Scanner input = new Scanner(System.in);
    BufferedReader BR = new BufferedReader(new FileReader("customer.txt")); String thisLine, thatLine;//BR use.
    FileWriter FWtmp = new FileWriter("customerstmp.txt", true);//temporarily store into customerstmp.txt
    FileWriter FW = new FileWriter("customer.txt", true);
    FileWriter lw = new FileWriter("log.txt",true);
    BR.mark(7000);//whenever BR.reset() is called, it will return to the wherever you call mark. which is beginning of the file.
    //Other declaration.
    Random rand = new Random();
    boolean check = false;
    boolean checks = false; //change from check to checks to avoid complication.
    //Declaring tmp files.
    File fOld = new File("customer.txt");
    File fNew = new File("customerstmp.txt");
    //Today date function.
    Calendar cal = Calendar.getInstance();
    SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    String todayD = df.format(cal.getTime());
    int h = cal.get(Calendar.HOUR_OF_DAY);
    int m = cal.get(Calendar.MINUTE);
    int s = cal.get(Calendar.SECOND);
    //variable declations.
    String name, ID, address, contact;
    int choice;
    String yesno;//validate yes or no.
    //WELCOME NOTE.
    System.out.println("You have selected manage customer account. ");
    //Options.
    System.out.println("1. Create a new customer account");
    System.out.println("2. Edit an existing customer account");
    System.out.println("3. Terminate an account");
    System.out.println("Select your options: ");
    choice = input.nextInt();
     
    switch(choice)
    {	//add try catch later.
    case 1 : //Create a new profile.
    System.out.println();
    System.out.println("Please choose your client type: ");
    System.out.println("1. Individual");
    System.out.println("2. Private Organization");
    System.out.println("3. Government");
    System.out.println("4. Non-Government Organization");
    choice = input.nextInt();
     
    do{
    System.out.println("Please enter client's full name: ");
    name = input.nextLine();name = input.nextLine();
    check = validation.validateName(name);
    }while(check==false);
    do{
    System.out.println("Please enter client's address: ");//test for bugs for ID and address.
    address = input.nextLine();
    check = validation.validateAddress(address);
    }while(check==false);
    do{
    System.out.println("Please enter ID number: ");
    ID = input.nextLine();
    check = validation.validateID(ID);
    }while(check==false);
    do{
    System.out.println("Please enter contact number: ");
    System.out.println("e.g. HP: 0121234567 ");
    contact = input.nextLine();
    check = validation.validateContact(contact);
    }while(check==false);
     
    int randAccNo = rand.nextInt(999999);//make account number to a string, A123456.
     
    switch(choice)
    {
    case 1://Individual
    FW.write(randAccNo+"--"+"Individual"+"--"+name+"--"+ID+"--"+address+"--"+contact+"--"+todayD+"--"+"Activate"+"\r\n");
    FW.close();
    lw.write(h+":"+m+":"+s+" "+todayD+" "+"Admin create individual account \r\nDetailed: "+randAccNo+"--"+"Individual"+"--"+name+"--"+ID+"--"+address+"--"+contact+"--"+todayD+"--"+"Activate"+"\r\n");
    lw.close();
    System.out.println("Account has been successfully created.");
    break;
    case 2://Private Organization
    FW.write(randAccNo+"--"+"Private Organization"+"--"+name+"--"+ID+"--"+address+"--"+contact+"--"+todayD+"--"+"Activate"+"\r\n");
    FW.close();
    lw.write(h+":"+m+":"+s+" "+todayD+" "+"Admin create Private Organization account \r\nDetailed: "+randAccNo+"--"+"Private organization"+"--"+name+"--"+ID+"--"+address+"--"+contact+"--"+todayD+"--"+"Activate"+"\r\n");
    lw.close();
    System.out.println("Account has been successfully created.");
    case 3://Government
    FW.write(randAccNo+"--"+"Government"+"--"+name+"--"+ID+"--"+address+"--"+contact+"--"+todayD+"--"+"Activate"+"\r\n");
    FW.close();
    lw.write(h+":"+m+":"+s+" "+todayD+" "+"Admin create Govenment account \r\nDetailed: "+randAccNo+"--"+"Government"+"--"+name+"--"+ID+"--"+address+"--"+contact+"--"+todayD+"--"+"Activate"+"\r\n");
    lw.close();
    System.out.println("Account has been successfully created.");
    break;
    case 4://NGO
    FW.write(randAccNo+"--"+"NGO"+"--"+name+"--"+ID+"--"+address+"--"+contact+"--"+todayD+"--"+"Activate"+"\r\n");
    FW.close();
    lw.write(h+":"+m+":"+s+" "+todayD+" "+"Admin create NGO account \r\n Detailed:"+randAccNo+"--"+"NGO"+"--"+name+"--"+ID+"--"+address+"--"+contact+"--"+todayD+"--"+"Activate"+"\r\n");
    lw.close();
    System.out.println("Account has been successfully created.");
    break;
    default : System.out.println("ERROR?");
    }
    proceed();
    break;//end of create a new profile.
     
    case 2 : //Edit a customer profile.
    System.out.println("Please select your option");
    System.out.println("1. Edit an existing customer account");
    System.out.println("2. Return to main menu");
    choice = input.nextInt();
     
    switch(choice)
    {
    case 1 : //Edit customer profile.
    while(check == false)
    {
    System.out.println("Please enter client's account number: ");
    String accNo = input.nextLine(); accNo = input.nextLine();//avoid bug.
    while((thisLine=BR.readLine())!=null)
    {
    String[] custArray = thisLine.split("--");
    System.out.println("-------Customer informations-------");
    System.out.println("Customer's account number: " + custArray[0]);
    System.out.println("Customer's account type: " + custArray[1]);
    System.out.println("Customer's account name: " + custArray[2]);
    System.out.println("Customer's account ID: " + custArray[3]);
    System.out.println("Customer's account address: " + custArray[4]);
    System.out.println("Customer's account contact number: " + custArray[5]);
    System.out.println("Customer's account creation date: " + custArray[6]);
    System.out.println("Customer's status: " + custArray[7] + "\r\n");
    if(accNo.equals(custArray[0]))
    {
    String result = thisLine.replaceAll("--", " ");
    System.out.println("Customer information: " + result);
    check=true;
    lw.write(h+":"+m+":"+s+" "+todayD+" "+"Admin edit"+custArray[0]);
    lw.close();
     
    System.out.println("Which information you would like to edit?");
    System.out.println("1. Customer name"); //reasons to edit : Staff input wrongly.
    System.out.println("2. Customer address");
    System.out.println("3. Customer ID");
    System.out.println("4. Customer contact");
    choice = input.nextInt();
     
    switch(choice)
    {
    case 1: //customer name
    System.out.println("Account No: "+custArray[0]+"\r\nCurrent name: "+custArray[2]);
    System.out.println("Please enter customer's new name: ");
    name = input.nextLine(); name = input.nextLine(); //avoid bug.
     
    BR.reset();//ensure BR read from top of the file again.
    while((thatLine=BR.readLine())!=null)
    {
    if(!thatLine.equals(thisLine))
    {
    FWtmp.write(thatLine+"\r\n");
    } else
    {
    FWtmp.write(custArray[0]+"--"+custArray[1]+"--"+name+"--"+custArray[3]+"--"+custArray[4]+"--"+
    custArray[5]+"--"+custArray[6]+"--"+custArray[7]+"\r\n");
    }
    }FWtmp.close();FW.close();BR.close();
    fOld.delete();//not working. return false!
    fNew.renameTo(new File("customer.txt"));
    lw.write(h+":"+m+":"+s+" "+todayD+" "+"Admin change name--account no: "+custArray[0]+" "+custArray[1]+" to "+name);
    lw.close();
    System.out.println("Client's name has been updated successfully. ");
    proceed();
    break;
     
    case 2: //customer address
    System.out.println("Account No: "+custArray[0]+"\r\nCurrent address: "+custArray[4]);
    do{
    System.out.println("Please enter customer's new address: ");
    address = input.nextLine(); address = input.nextLine(); //avoid bug.
    check = validation.validateAddress(address);
    }while(check==false);
     
    BR.reset();//ensure BR read from top of the file again.
    while((thatLine=BR.readLine())!=null)
    {
    if(!thatLine.equals(thisLine))
    {
    FWtmp.write(thatLine+"\r\n");
    } else
    {
    FWtmp.write(custArray[0]+"--"+custArray[1]+"--"+custArray[2]+"--"+custArray[3]+"--"+address+"--"+
    custArray[5]+"--"+custArray[6]+"--"+custArray[7]+"\r\n");
    }
    }FWtmp.close();FW.close();BR.close();
    fOld.delete();//not working. return false!
    fNew.renameTo(new File("customer.txt"));
    lw.write(h+":"+m+":"+s+" "+todayD+" "+"Admin change address--account no: "+custArray[0]+" "+custArray[4]+" to "+address);
    lw.close();
    System.out.println("Client's address has been updated successfully. ");
    proceed();
    break;
     
    case 3: //customer ID // NOT ACCOUNT NUMBER.
    System.out.println("Account No: "+custArray[0]+"\r\nCurrent ID: "+custArray[3]);
    do{
    System.out.println("Please enter customer's new ID: ");
    ID = input.nextLine(); ID = input.nextLine(); //avoid bug.
    check = validation.validateID(ID);
    }while(check==false);
     
    BR.reset();//ensure BR read from top of the file again.
    while((thatLine=BR.readLine())!=null)
    {
    if(!thatLine.equals(thisLine))
    {
    FWtmp.write(thatLine+"\r\n");
    } else
    {
    FWtmp.write(custArray[0]+"--"+custArray[1]+"--"+custArray[2]+"--"+ID+"--"+custArray[4]+"--"+
    custArray[5]+"--"+custArray[6]+"--"+custArray[7]+"\r\n");
    }
    }FWtmp.close();FW.close();BR.close();
    fOld.delete();//not working. return false!
    fNew.renameTo(new File("customer.txt"));
    lw.write(h+":"+m+":"+s+" "+todayD+" "+"Admin change customer id--account no: "+custArray[0]+" "+custArray[3]+" to "+ID);
    lw.close();
    System.out.println("Client's ID has been updated successfully. ");
    proceed();
    break;
     
    case 4: //customer contact
    System.out.println("Account No: "+custArray[0]+"\r\nCurrent contact: "+custArray[5]);
    do{//validate
    System.out.println("Please enter customer's new contact: ");
    System.out.println("e.g. HP: 0121234567 ");
    contact = input.nextLine(); contact = input.nextLine();
    check = validation.validateContact(contact);
    }while(check==false);
     
    BR.reset();//ensure BR read from top of the file again.
    while((thatLine=BR.readLine())!=null)
    {
    if(!thatLine.equals(thisLine))
    {
    FWtmp.write(thatLine+"\r\n");
    } else
    {
    FWtmp.write(custArray[0]+"--"+custArray[1]+"--"+custArray[2]+"--"+custArray[3]+"--"+custArray[4]+"--"+
    contact+"--"+custArray[6]+"--"+custArray[7]+"\r\n");
    }
    }FWtmp.close();FW.close();BR.close();
    fOld.delete();//not working. return false!
    fNew.renameTo(new File("customer.txt"));
    lw.write(h+":"+m+":"+s+" "+todayD+" "+"Admin change contact no--account no: "+custArray[0]+"--"+custArray[1]+"--"+custArray[2]+"--"+custArray[3]+"--"+custArray[4]+"--"+contact+"--"+custArray[6]+"--"+custArray[7]+"\r\n");
    lw.close();
    System.out.println("Client's contact has been updated successfully. ");
    proceed();
    break;
    }
    }
    }BR.reset();
    }
    break;//End of editing customer account.
     
    case 2://Return to main menu.
    mainMenu();
    break;
    }proceed();//check may have prob.
    break;
     
    case 3 /Terminate a customer account.)
    System.out.println("1. Terminate an existing customer account");
    System.out.println("2. Return to main menu");
    System.out.print("Please select your option: ");
    choice = input.nextInt();
     
    switch(choice)
    {
    case 1 : //Terminate an existing customer profile
    while(check == false)
    {
    System.out.println("Please enter client's account number: ");
    String accNo = input.nextLine(); accNo = input.nextLine();//avoid bug.
     
    while((thisLine=BR.readLine())!=null)
    {
    String[] custArray = thisLine.split("--");
    if(accNo.equals(custArray[0]))
    {
    String result = thisLine.replaceAll("--", " ");
    System.out.println("-------Customer informations-------");
    System.out.println("Customer's account number: " + custArray[0]);
    System.out.println("Customer's account type: " + custArray[1]);
    System.out.println("Customer's account name: " + custArray[2]);
    System.out.println("Customer's account ID: " + custArray[3]);
    System.out.println("Customer's account address: " + custArray[4]);
    System.out.println("Customer's account contact number: " + custArray[5]);
    System.out.println("Customer's account creation date: " + custArray[6]);
    System.out.println("Customer's status: " + custArray[7] + "\r\n");
    check=true;
    System.out.println("Are you sure you would like to terminate this account?");
    do
    {
    System.out.print("Confirm(y/n): ");
    yesno = input.nextLine();
    checks = validation.validateDecision(yesno);
    }while(checks == false);
     
    if(checks==true)
    {	BR.reset();
    while((thatLine=BR.readLine())!=null)
    {
    if(!thatLine.equals(thisLine))
    {
    FWtmp.write(thatLine+"\r\n");
    } else
    {
    FWtmp.write(custArray[0]+"--"+custArray[1]+"--"+custArray[2]+"--"+custArray[3]+"--"+custArray[4]+"--"+
    custArray[5]+"--"+custArray[6]+"--"+"Terminated"+"\r\n");
    }
    }FWtmp.close();FW.close();BR.close();
    fOld.delete();//not working. return false!
    fNew.renameTo(new File("customer.txt"));
    lw.write(h+":"+m+":"+s+" "+todayD+" admin successfully terminate this account "+accNo+"Customer name: "+custArray[2]);
    lw.close();
    System.out.println("Customer account: "+custArray[0]+"\r\n"+"Customer name: "+custArray[2]+"\r\n"+
    "This account has been successfully terminated.");
    proceed();//prompt user to continue.
    }else if(check==false)
    {
    System.out.println("You have chosen NO to terminate an account. You are now returned to the main menu..");
    mainMenu();
    break;
    }
    }
    }
    }
    default	: System.out.println("Problem in manage account.");
    break;
    }
    }
    }
     
    public static void manageService() throws Exception
    {
    //System declarations.
    Scanner input = new Scanner(System.in);
    BufferedReader BR = new BufferedReader(new FileReader("smartcard.txt")); String thisLine, thatLine;//BR use.
    FileWriter FWtmp = new FileWriter("smartcardtmp.txt", true);//temporarily store into customerstmp.txt
    FileWriter FW = new FileWriter("smartcard.txt", true);
    FileWriter lw = new FileWriter("log.txt",true);
    BR.mark(7000);//whenever BR.reset() is called, it will return to the wherever you call mark. which is beginning of the file.
    //Other declaration.
    Random rand = new Random();
    boolean check = false;
    boolean checks = false; //change from check to checks to avoid complication.
    //Declaring tmp files.
    File fOld = new File("smartcard.txt");
    File fNew = new File("smartcardtmp.txt");
    //Today date function.
    Calendar cal = Calendar.getInstance();
    SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    String todayD = df.format(cal.getTime());
    int h = cal.get(Calendar.HOUR_OF_DAY);
    int m = cal.get(Calendar.MINUTE);
    int s = cal.get(Calendar.SECOND);
    //variable declations.
    String accNo, name, ID, address, contact;
    //manageService variables declaration
    String SmartcardNo, DecoderNo, subsNo;
    int choice;
    String yesno;//validate yes or no.
    //WELCOME NOTE.
    System.out.println("You have selected manage customer services. ");
    //Options.
    System.out.println("1. Add a customer service to an account");
    System.out.println("2. Edit existing customer service");
    System.out.println("3. Terminate a service");
    System.out.println("Select your options: ");
    choice = input.nextInt();
     
    switch(choice)
    {	//add try catch later.
    case 1 : //Create a new profile.
    System.out.println();
    System.out.println("Please select your options ");
    System.out.println("1. Add a smartcard to an account");
    System.out.println("2. Return to main menu");
    choice = input.nextInt();
     
    System.out.println("Please enter client's account number: ");//<--smartcard to be added to this account.
    accNo = input.nextLine(); accNo = input.nextLine(); //avoid bug.
     
    //reconsider doing subs no. //later in while loop SOP total subs no?
     
    do{
    System.out.println("Please enter new smarcard number: ");//check if it exist?
    SmartcardNo = input.nextLine();
    check = validation.validateSmartcardNo(SmartcardNo);
    }while(check==false);
     
    do{
    System.out.println("Please enter decoder number: ");
    DecoderNo = input.nextLine();
    check = validation.validateID(DecoderNo);
    }while(check==false);
     
    do{
    System.out.println("Please enter installation address: "); //open for any address?
    address = input.nextLine();
    check = validation.validateAddress(address);
    }while(check==false);
     
    switch(choice)
    {
    case 1://writing new smartcard to smartcard.txt
    FW.write(accNo+"--"+SmartcardNo+"--"+DecoderNo+"--"+address+"--"+"Active"+"\r\n");
    FW.close();
    lw.write(h+":"+m+":"+s+" "+todayD+" admin create an account\r\ndetailed:"+accNo+"--"+SmartcardNo+"--"+DecoderNo+"--"+address+"--"+"Active"+"\r\n");
    lw.close();
    System.out.println("Account has been successfully created.");
    proceed();
    break;
     
    default : System.out.println("ERROR?");
    }
    break;//end of create a new service.
     
    case 2 : //Edit a customer services.
    System.out.println("Please select your option");
    System.out.println("1. Edit an existing customer service");
    System.out.println("2. Return to main menu");
    choice = input.nextInt();
     
    switch(choice)
    {
    case 1 : //Edit customer service
    while(check == false)
    {
    System.out.println("Please enter client's account number: ");
    accNo = input.nextLine(); accNo = input.nextLine();//avoid bug.
    while((thisLine=BR.readLine())!=null)
    {
    String[] scArray = thisLine.split("--");//smartcard array.
    if(accNo.equals(scArray[0]))
    {
    String result = thisLine.replaceAll("--", " ");
    System.out.println("-------Smartcard informations-------");
    System.out.println("Smartcard's account number: " + scArray[0]);//smartcard account holder's acc number.
    System.out.println("Smartcard's smartcard number: " + scArray[1]);
    System.out.println("Smartcard's decoder number: " + scArray[2]);
    System.out.println("Smartcard's installation address: " + scArray[3]);
    System.out.println("Smartcard's status: " + scArray[4] + "\r\n");
     
    check=true;
     
    System.out.println("Which information you would like to edit?");
    System.out.println("1. Smartcard no."); //reasons to edit : Staff input wrongly.
    System.out.println("2. Decoder no. ");
    System.out.println("3. Installation address");
    choice = input.nextInt();
     
    switch(choice)
    {
    case 1: //edit smartcard no.
    System.out.println("Account No: "+scArray[0]+"\r\nSmartcard no: "+scArray[1]);
    System.out.println("Please enter smartcard's new smartcard no. : ");
    SmartcardNo = input.nextLine(); SmartcardNo = input.nextLine(); //avoid bug.
     
    BR.reset();//ensure BR read from top of the file again.
    while((thatLine=BR.readLine())!=null)
    {
    if(!thatLine.equals(thisLine))
    {
    FWtmp.write(thatLine+"\r\n");
    } else
    {
    FWtmp.write(scArray[0]+"--"+SmartcardNo+"--"+scArray[2]+"--"+scArray[3]+"--"+scArray[4]+"\r\n");
    }
    }FWtmp.close();FW.close();BR.close();
    fOld.delete();//not working. return false!
    fNew.renameTo(new File("smartcard.txt"));
    lw.write(h+":"+m+":"+s+" "+todayD+" admin successfully edited the smartcard\r\ndetailed: "+scArray[0]+"--"+SmartcardNo+"--"+scArray[2]+"--"+scArray[3]+"--"+scArray[4]+"\r\n");
    lw.close();
    System.out.println("Smartcard's new smartcard number has been updated successfully. ");
    proceed();
    break;
     
    case 2: //edit decoder no.
    System.out.println("Account No: "+scArray[0]+"\r\nCurrent decoder no.: "+scArray[2]);
    do{
    System.out.println("Please enter smartcard's new decoder no. : ");
    DecoderNo = input.nextLine(); DecoderNo = input.nextLine(); //avoid bug.
    check = validation.validateDecoderNo(DecoderNo);
    }while(check==false);
     
    BR.reset();//ensure BR read from top of the file again.
    while((thatLine=BR.readLine())!=null)
    {
    if(!thatLine.equals(thisLine))
    {
    FWtmp.write(thatLine+"\r\n");
    } else
    {
    FWtmp.write(scArray[0]+"--"+scArray[1]+"--"+DecoderNo+"--"+scArray[3]+"--"+scArray[4]+"\r\n");
    }
    }FWtmp.close();FW.close();BR.close();
    fOld.delete();//not working. return false!
    fNew.renameTo(new File("smartcard.txt"));
    lw.write(h+":"+m+":"+s+" "+todayD+" admin successfully edited the decoder\r\ndetailed: "+scArray[0]+"--"+scArray[1]+"--"+DecoderNo+"--"+scArray[3]+"--"+scArray[4]+"\r\n");
    lw.close();
    System.out.println("Smartcard's decoder number has been updated successfully. ");
    proceed();
    break;
     
    case 3: //Installation address
    System.out.println("Account No: "+scArray[0]+"\r\nCurrent installation address: "+scArray[3]);
    do{
    System.out.println("Please enter smartcard's new installation address: ");
    address = input.nextLine(); address = input.nextLine(); //avoid bug.
    check = validation.validateAddress(address);
    }while(check==false);
     
    BR.reset();//ensure BR read from top of the file again.
    while((thatLine=BR.readLine())!=null)
    {
    if(!thatLine.equals(thisLine))
    {
    FWtmp.write(thatLine+"\r\n");
    } else
    {
    FWtmp.write(scArray[0]+"--"+scArray[1]+"--"+scArray[2]+"--"+address+"--"+scArray[4]+"\r\n");
    }
    }FWtmp.close();FW.close();BR.close();
    fOld.delete();//not working. return false!
    fNew.renameTo(new File("smartcard.txt"));
    lw.write(h+":"+m+":"+s+" "+todayD+" admin successfully edited the installation address \r\ndetailed: "+scArray[0]+"--"+scArray[1]+"--"+scArray[2]+"--"+address+"--"+scArray[4]+"\r\n");
    lw.close();
    System.out.println("Smartcard's installation address has been updated successfully. ");
    proceed();
    break;
     
    }
    }
    }BR.reset();
    }
    break;//End of editing smartcard.
     
    case 2://Return to main menu.
    mainMenu();
    break;
    } proceed();
    break;//may have break problem.
     
    case 3 /Terminate a smartcard
    System.out.println("Please select your option");
    System.out.println("1. Terminate an existing smartcard");
    System.out.println("2. Return to main menu");
    choice = input.nextInt();
     
    switch(choice)
    {
    case 1 : //Terminate an existing smartcard
    while(check == false)
    {
    System.out.println("Please enter client's smartcard number: ");
    SmartcardNo = input.nextLine(); SmartcardNo = input.nextLine();//avoid bug.
     
    while((thisLine=BR.readLine())!=null)
    {
    String[] scArray = thisLine.split("--");
    if(SmartcardNo.equals(scArray[1]))
    {
    String result = thisLine.replaceAll("--", " ");
    System.out.println("-------Smartcard informations-------");
    System.out.println("Smartcard's account number: " + scArray[0]);//smartcard account holder's acc number.
    System.out.println("Smartcard's smartcard number: " + scArray[1]);
    System.out.println("Smartcard's decoder number: " + scArray[2]);
    System.out.println("Smartcard's installation address: " + scArray[3]);
    System.out.println("Smartcard's status: " + scArray[4] + "\r\n");
    check=true;
    System.out.println("Are you sure you would like to terminate this account?");
    do
    {
    System.out.print("Confirm(y/n): ");
    yesno = input.nextLine();
    checks = validation.validateDecision(yesno);
    }while(checks == false);
     
    //char yesnoo = input.nextLine().charAt(0);
    if(checks==true)
    {	BR.reset();
    while((thatLine=BR.readLine())!=null)
    {
    if(!thatLine.equals(thisLine))
    {
    FWtmp.write(thatLine+"\r\n");
    } else
    {
    FWtmp.write(scArray[0]+"--"+scArray[1]+"--"+scArray[2]+"--"+scArray[3]+"--"+"Terminated"+"\r\n");
    }
    }FWtmp.close();FW.close();BR.close();
    fOld.delete();//not working. return false!
    fNew.renameTo(new File("customer.txt"));
    lw.write(h+":"+m+":"+s+" "+todayD+" admin successfully terminated the smartcard \r\ndetailed: "+scArray[0]+"--"+scArray[1]+"--"+scArray[2]+"--"+scArray[3]+"--"+"Terminated"+"\r\n");
    lw.close();
    System.out.println("Customer account: "+scArray[0]+"\r\n"+"Smartcard number: "+scArray[1]+"\r\n"+
    "This smartcard number has been successfully terminated.");
    proceed();
    break;
    }else if(checks==false)
    {
    System.out.println("You have chosen NO to terminate a smartcard. You are now returned to the main menu..");
    mainMenu();
    break;
    }
    }
    }
    }
    default	: System.out.println("Problem in manage services.");
    break;
    }proceed();
    break;//check may have error. remove if necessary.
    }
    }
     
    public static void manageSubPackage() throws Exception //Customer's smartcard subscribe to what packages.
    {
    //System declarations.
    Scanner input = new Scanner(System.in);
    BufferedReader BR = new BufferedReader(new FileReader("subpackage.txt")); String thisLine, thatLine;//BR use.
    FileWriter FWtmp = new FileWriter("subpackagetmp.txt", true);//temporarily store into subpackagetmp.txt
    FileWriter FW = new FileWriter("subpackage.txt", true);
    FileWriter lw = new FileWriter("log.txt",true);
    BR.mark(7000);//whenever BR.reset() is called, it will return to the wherever you call mark. which is beginning of the file.
    //Other declaration.
    Random rand = new Random();
    boolean check = false;
    boolean checks = false; //add check and checks to avoid complication.
    //Declaring tmp files.
    File fOld = new File("subpackage.txt");
    File fNew = new File("subpackagetmp.txt");
    //Today date function.
    Calendar cal = Calendar.getInstance();
    SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    String todayD = df.format(cal.getTime());
    int h = cal.get(Calendar.HOUR_OF_DAY);
    int m = cal.get(Calendar.MINUTE);
    int s = cal.get(Calendar.SECOND);
    //variable declations.
    String accNo, SmartcardNo, name, ID, address, contact;
    //manageService variables declaration
    String packageCode, packageName, dateSub, dateT;
    int choice;
    String yesno;//validate yes or no.
    //WELCOME NOTE.
    System.out.println("You have selected manage subscribe packages item. ");
    //Options.
    System.out.println("1. Add a package to a smartcard");
    System.out.println("2. Edit an existing subscribed package");
    System.out.println("3. Terminate a package subscribed");
    System.out.println("Select your options: ");
    choice = input.nextInt();
     
    switch(choice)
    {	//add try catch later.
    case 1 : //Add a package to a smartcard
    System.out.println();
    System.out.println("1. Subscribe a package to a smartcard");
    System.out.println("2. Return to main menu");
    System.out.print("Please select your options ");
    choice = input.nextInt();
    //add a return menu later on.
     
    System.out.println("Please enter client's smartcard number: ");//<--package to be subscribe to this smartcard.
    SmartcardNo = input.nextLine(); SmartcardNo = input.nextLine(); //avoid bug.
    //consider print info for checking purpose.
    System.out.println("Please enter package code to be added to the smartcard: ");//check if it exist? //read package.txt for it's existence? CONSIDER!
    packageCode = input.nextLine();
    System.out.println("Please enter package name: ");
    packageName = input.nextLine();packageName = input.nextLine();packageName = input.nextLine();//BUG?ZZ!
     
    while(check==false)//check if package code exist.
    {
    BufferedReader BRtmp = new BufferedReader(new FileReader("package.txt"));BR.mark(7000);
    while((thisLine=BRtmp.readLine())!=null)
    {
    String packArray[] = thisLine.split("--");
    if(packageCode.equals(packArray[1]))
    {
    if(packageName.equals(packArray[0])) //problem. does not packageName does not work.
    check=true;
    System.out.println("Package code exist. ");
    }
    }
    }
     
    switch(choice)
    {
    case 1://writing new package added to smartcard to subpackage.txt
    FW.write(SmartcardNo+"--"+packageCode+"--"+packageName+"--"+todayD+"--"+"null"+"--"+"Active"+"\r\n");
    FW.close();
    lw.write(h+":"+m+":"+s+" "+todayD+" admin has added a new package to smartcard\r\ndetailed:"+SmartcardNo+"--"+packageCode+"--"+packageName+"--"+todayD+"--"+"null"+"--"+"Active"+"\r\n");
    lw.close();
    System.out.println("Package: "+packageCode+" has been successfully added to this smartcard no. "+SmartcardNo);
    proceed();
    break;
     
    default : System.out.println("ERROR?");
    }proceed();
    break;//end of adding package to a smartcard.
     
    case 2 : //Edit a package from a smartcard.
    System.out.println("Please select your option");
    System.out.println("1. Edit an existing package from a smartcard");
    System.out.println("2. Return to main menu");
    choice = input.nextInt();
     
    switch(choice)
    {
    case 1 : //Edit an existing package from a smartcard.
    while(check == false)
    {
    System.out.println("Please enter customer's smartcard number: ");
    SmartcardNo = input.nextLine(); SmartcardNo = input.nextLine();//avoid bug.
    while((thisLine=BR.readLine())!=null)// POSSIBLE HAVING READ PROB AS EARLIER USE READER TO CHECK
    {
    String[] spackArray = thisLine.split("--");//subscribe package array.
    if(SmartcardNo.equals(spackArray[0]))
    {
    String result = thisLine.replaceAll("--", " ");
    System.out.println("-------Package Subscribed Information-------");
    System.out.println("Smartcard's account number: " + spackArray[0]);//smartcard account holder's acc number.
    System.out.println("Subscribed package code: " + spackArray[1]);
    System.out.println("Subscribed package name: " + spackArray[2]);
    System.out.println("Subscription date: " + spackArray[3]);
    System.out.println("Termination date" + spackArray[4]);
    System.out.println("Subscribed package status: " + spackArray[5] + "\r\n");
     
    check=true;
     
    System.out.println("Which information you would like to edit?");
    System.out.println("1. Package code"); //reasons to edit : Staff input wrongly. probably subscribe to wrong package.
    System.out.println("2. Return to main menu");
    choice = input.nextInt();//ensure when EDIT package code. it auto input package name too.
     
    switch(choice)
    {
    case 1: //edit package code.
    System.out.println("Smartcard no: "+spackArray[0]+"\r\nPackage code: "+spackArray[1]);
    System.out.println("Please enter new package code : ");
    packageCode = input.nextLine(); packageCode = input.nextLine(); //avoid bug.
    System.out.println("Please enter new package name : ");
    packageName = input.nextLine();
    BR.reset();//ensure BR read from top of the file again.
    while((thatLine=BR.readLine())!=null)
    {
    if(!thatLine.equals(thisLine))
    {
    FWtmp.write(thatLine+"\r\n");
    } else
    {
    while(check==false)//check if package name exist.
    {
    BufferedReader BRtmp = new BufferedReader(new FileReader("package.txt"));
    while((thisLine=BRtmp.readLine())!=null)
    {
    String packArray[] = thisLine.split("--");
    if(spackArray[2].equals(packArray[0]))//comparing package name.
    {
    packageName = packArray[0];
    check=true;
    System.out.println("Package name exist. ");//to be delete?
    }else System.out.println("Package name does not exist. Please try again.. ");
    }
    }
    FWtmp.write(SmartcardNo+"--"+packageCode+"--"+packageName+"--"+spackArray[3]+"--"+spackArray[4]
    +"--"+spackArray[5]+"\r\n");
    }
    }FWtmp.close();FW.close();BR.close();
    fOld.delete();//not working. return false!
    fNew.renameTo(new File("subpackage.txt"));
    lw.write(h+":"+m+":"+s+" "+todayD+" admin successfully edit package code \r\ndetailed:"+SmartcardNo+"--"+packageCode+"--"+packageName+"--"+spackArray[3]+"--"+spackArray[4]
    +"--"+spackArray[5]+"\r\n");
    lw.close();
    System.out.println("Package code has been updated successfully. ");
    proceed();
    break;
     
    case 2: // return main menu.
    mainMenu();
    break;
     
    }
    }
    }BR.reset();
    }
    break;//End of editing smartcard.
     
    case 2://Return to main menu.
    mainMenu();
    break;
    }
     
    case 3 /Terminate a smartcard
    System.out.println("Please select your option");
    System.out.println("1. Terminate an existing smartcard");
    System.out.println("2. Return to main menu");
    choice = input.nextInt();
     
    switch(choice)
    {
    case 1 : //Terminate an existing smartcard
    while(check == false)
    {
    System.out.println("Please enter client's smartcard number: ");
    SmartcardNo = input.nextLine(); SmartcardNo = input.nextLine();//avoid bug.
     
    while((thisLine=BR.readLine())!=null)
    {
    String[] scArray = thisLine.split("--");
    if(SmartcardNo.equals(scArray[1]))
    {
    String result = thisLine.replaceAll("--", " ");
    System.out.println("-------Smartcard informations-------");
    System.out.println("Smartcard's account number: " + scArray[0]);//smartcard account holder's acc number.
    System.out.println("Smartcard's smartcard number: " + scArray[1]);
    System.out.println("Smartcard's decoder number: " + scArray[2]);
    System.out.println("Smartcard's installation address: " + scArray[3]);
    System.out.println("Smartcard's status: " + scArray[4] + "\r\n");
    check=true;
    System.out.println("Are you sure you would like to terminate this account?");
    do
    {
    System.out.print("Confirm(y/n): ");
    yesno = input.nextLine();
    checks = validation.validateDecision(yesno);
    }while(checks == false);
     
    //char yesnoo = input.nextLine().charAt(0);
    if(checks==true)
    {	BR.reset();
    while((thatLine=BR.readLine())!=null)
    {
    if(!thatLine.equals(thisLine))
    {
    FWtmp.write(thatLine+"\r\n");
    } else
    {
    FWtmp.write(scArray[0]+"--"+scArray[1]+"--"+scArray[2]+"--"+scArray[3]+"--"+"Terminated"+"\r\n");
    }
    }FWtmp.close();FW.close();BR.close();
    fOld.delete();//not working. return false!
    fNew.renameTo(new File("smartcard.txt"));
    lw.write(h+":"+m+":"+s+" "+todayD+" admin successfully terminate a smartcard \r\ndetailed:"+scArray[0]+"--"+scArray[1]+"--"+scArray[2]+"--"+scArray[3]+"--"+"Terminated"+"\r\n");
    lw.close();
    System.out.println("Customer account: "+scArray[0]+"\r\n"+"Smartcard number: "+scArray[1]+"\r\n"+
    "This package item has been successfully terminated.");
    proceed();
    break;
    }else if(checks==false)
    {
    System.out.println("You have chosen NO to terminate a subscribed package. You are now returned to the main menu..");
    mainMenu();
    break;
    }
    }
    }
    }
    default	: System.out.println("Problem in manage subscription package..");
    break;
    }proceed();
    break;
    }
    }
     
    public static void managePack() throws Exception
    {
    //System declarations.
    Scanner input = new Scanner(System.in);
    BufferedReader BR = new BufferedReader(new FileReader("package.txt")); String thisLine, thatLine;//BR use.
    FileWriter FWtmp = new FileWriter("packagetmp.txt", true);//temporarily store into subpackagetmp.txt
    FileWriter FW = new FileWriter("package.txt", true);
    FileWriter lw = new FileWriter("log.txt",true);
    BR.mark(7000);//whenever BR.reset() is called, it will return to the wherever you call mark. which is beginning of the file.
    //Other declaration.
    Random rand = new Random();
    boolean check = false;
    boolean checks = false; //add check and checks to avoid complication.
    //Declaring tmp files.
    File fOld = new File("package.txt");
    File fNew = new File("packagetmp.txt");
    //Today date function.
    Calendar cal = Calendar.getInstance();
    SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    String todayD = df.format(cal.getTime());
    int h = cal.get(Calendar.HOUR_OF_DAY);
    int m = cal.get(Calendar.MINUTE);
    int s = cal.get(Calendar.SECOND);
    //variable declations.
    String accNo, SmartcardNo, name, ID, address, contact;
    //managePackage variables declaration
    String prog = null;
    String packageCode, packageName, dateS, dateT, cType;// cType = charge type.
    int choice; double price;
    String yesno;//validate yes or no.
    //WELCOME NOTE.
    System.out.println("You have selected manage packages item. ");
    //Options.
    System.out.println("1. Create a new package item");
    System.out.println("2. Edit an existing package item");
    System.out.println("3. Terminate a package item");
    System.out.print("Select your options: ");
    choice = input.nextInt();
     
    switch(choice)
    {	//add try catch later.
    case 1 : //Create a new package item
    System.out.println();
    System.out.println("1. Create a new package item");
    System.out.println("2. Return to main menu");
    System.out.print("Please select your options ");
    choice = input.nextInt();
     
    switch(choice)
    {
    case 1://create new package item.
    System.out.println("Please enter new package code: ");//<--Unique key.
    packageCode = input.nextLine(); packageCode = input.nextLine(); //avoid bug.
    //need a function check if it exist! same for all others. eg add customer.
     
    System.out.println("Please enter package name: ");
    packageName = input.nextLine();//validation.
     
    System.out.println("Please enter price charged: ");
    price = input.nextDouble();
     
    System.out.println("Please enter charge type: ");
    cType = input.nextLine();
     
    FW.write(packageCode+"--"+packageName+"--"+todayD+"--"+"null"+"--"+price+"--"+cType+"--"+prog+"\r\n");
    FW.close();
    lw.write(h+":"+m+":"+s+" "+todayD+" admin successfully created package item\r\ndetailed:"+packageCode+"--"+packageName+"--"+todayD+"--"+"null"+"--"+price+"--"+cType+"--"+prog+"\r\n");
    lw.close();
    System.out.println("Package: "+packageCode+" has been successfully created.");
    proceed();
    break;
     
    case 2://Return to main menu.
    mainMenu();
    break;
    //if invalid input.
    default: System.out.println("Please select option 1 or 2 ONLY.");
    break;
    }
    break;//End of creating a new package item.
     
    case 2 : //Edit an existing package item
    System.out.println("1. Edit an existing package from a smartcard");
    System.out.println("2. Return to main menu");
    System.out.print("Please select your option");
    choice = input.nextInt();
     
    switch(choice)
    {
    case 1 : //Edit an existing package from a smartcard.
    while(check == false)
    {
    System.out.println("Please enter package code");
    packageCode = input.nextLine(); packageCode = input.nextLine();//avoid bug.
    while((thisLine=BR.readLine())!=null)// POSSIBLE HAVING READ PROB AS EARLIER USE READER TO CHECK
    {
    String[] packArray = thisLine.split("--");//subscribe package array.
    if(packageCode.equals(packArray[0]))
    {
    String result = thisLine.replaceAll("--", " ");
    System.out.println("-------Package item Information-------");
    System.out.println("Package item code: " + packArray[0]);
    System.out.println("Package item name: " + packArray[1]);
    System.out.println("Package item date started: " + packArray[2]);
    System.out.println("Package item date terminated: " + packArray[3]);
    System.out.println("Package item price charged" + packArray[4]);
    System.out.println("Package item charge type: " + packArray[5] + "\r\n");
     
    check=true;
    System.out.println("Which information you would like to edit?");
    System.out.println("1. Package item code"); //reasons to edit : Staff input wrongly. probably subscribe to wrong package.
    System.out.println("2. Package item name");
    System.out.println("3. Package item price charged");
    System.out.println("4. Package item charge type");
    System.out.println("5. Return to main menu");
    choice = input.nextInt();
     
    switch(choice)
    {
    case 1: //edit package item code.
    System.out.println("Package item name: "+packArray[1]+"\r\nPackage item code: "+packArray[0]);
    System.out.println("Please enter new package item code : ");
    packageCode = input.nextLine(); packageCode = input.nextLine(); //avoid bug.
    BR.reset();//ensure BR read from top of the file again.
    while((thatLine=BR.readLine())!=null)
    {
    if(!thatLine.equals(thisLine))
    {
    FWtmp.write(thatLine+"\r\n");
    } else
    {
    FWtmp.write(packageCode+"--"+packArray[1]+"--"+packArray[2]+"--"+packArray[3]+"--"+packArray[4]
    +"--"+packArray[5]+"--"+packArray[6]+"\r\n");
    }
    }FWtmp.close();FW.close();BR.close();
    fOld.delete();//not working. return false!
    fNew.renameTo(new File("package.txt"));
    lw.write(h+":"+m+":"+s+" "+todayD+" admin successfully updated package item code \r\ndetailed:"+packageCode+"--"+packArray[1]+"--"+packArray[2]+"--"+packArray[3]+"--"+packArray[4]+"--"+packArray[5]+"--"+packArray[6]+"\r\n");
    lw.close();
    System.out.println("Package item code has been updated successfully. ");
    proceed();
    break;
     
    case 2: //edit package item name.
    System.out.println("Package item name: "+packArray[1]+"\r\nPackage item code: "+packArray[0]);
    System.out.println("Please enter new package item name : ");
    packageName = input.nextLine(); packageName = input.nextLine(); //avoid bug.
    BR.reset();//ensure BR read from top of the file again.
    while((thatLine=BR.readLine())!=null)
    {
    if(!thatLine.equals(thisLine))
    {
    FWtmp.write(thatLine+"\r\n");
    } else
    {
    FWtmp.write(packArray[0]+"--"+packageCode+"--"+packArray[2]+"--"+packArray[3]+"--"+packArray[4]
    +"--"+packArray[5]+"--"+packArray[6]+"\r\n");
    }
    }FWtmp.close();FW.close();BR.close();
    fOld.delete();//not working. return false!
    fNew.renameTo(new File("package.txt"));
    lw.write(h+":"+m+":"+s+" "+todayD+" admin successfully updated package name\r\ndetailed:"+packArray[0]+"--"+packageCode+"--"+packArray[2]+"--"+packArray[3]+"--"+packArray[4]
    +"--"+packArray[5]+"--"+packArray[6]+"\r\n");
    lw.close();
    System.out.println("Package item name has been updated successfully. ");
    proceed();
    break;
     
    case 3: //edit package item price charged.
    System.out.println("Package item name: "+packArray[1]+"\r\nPackage item code: "+packArray[0]);
    System.out.println("Please enter new package item price charged : ");
    price = input.nextDouble(); price = input.nextDouble(); //avoid bug.
    BR.reset();//ensure BR read from top of the file again.
    while((thatLine=BR.readLine())!=null)
    {
    if(!thatLine.equals(thisLine))
    {
    FWtmp.write(thatLine+"\r\n");
    } else
    {
    FWtmp.write(packArray[0]+"--"+packArray[1]+"--"+packArray[2]+"--"+packArray[3]+"--"+price
    +"--"+packArray[5]+"--"+packArray[6]+"\r\n");
    }
    }FWtmp.close();FW.close();BR.close();
    fOld.delete();//not working. return false!
    fNew.renameTo(new File("package.txt"));
    lw.write(h+":"+m+":"+s+" "+todayD+" admin successfully updated package price\r\ndetailed:"+packArray[0]+"--"+packArray[1]+"--"+packArray[2]+"--"+packArray[3]+"--"+price
    +"--"+packArray[5]+"--"+packArray[6]+"\r\n");
    lw.close();
    System.out.println("Package item price charged has been updated successfully. ");
    proceed();
    break;
     
    case 4: //edit package item charge type.
    System.out.println("Package item name: "+packArray[1]+"\r\nPackage item code: "+packArray[0]);
    System.out.println("Please enter new package item charge type : ");
    cType = input.nextLine(); cType = input.nextLine(); //avoid bug.
    BR.reset();//ensure BR read from top of the file again.
    while((thatLine=BR.readLine())!=null)
    {
    if(!thatLine.equals(thisLine))
    {
    FWtmp.write(thatLine+"\r\n");
    } else
    {
    FWtmp.write(packArray[0]+"--"+packArray[1]+"--"+packArray[2]+"--"+packArray[3]+"--"+packArray[4]
    +"--"+cType+"--"+packArray[6]+"\r\n");
    }
    }FWtmp.close();FW.close();BR.close();
    fOld.delete();//not working. return false!
    fNew.renameTo(new File("package.txt"));
    lw.write(h+":"+m+":"+s+" "+todayD+" admin successfully updated item charge type\r\ndetailed:"+packArray[0]+"--"+packArray[1]+"--"+packArray[2]+"--"+packArray[3]+"--"+packArray[4]
    +"--"+cType+"--"+packArray[6]+"\r\n");
    lw.close();
    System.out.println("Package item charge type has been updated successfully. ");
    proceed();
    break;
     
    case 5: // return main menu.
    mainMenu();
    break;
     
    }
    }
    }BR.reset();
    }proceed();
    break;//End of editing package item.
     
    case 2://Return to main menu.
    mainMenu();
    break;
    }
     
    case 3 /Terminate a package item.
    System.out.println("1. Terminate an existing smartcard");
    System.out.println("2. Return to main menu");
    System.out.print("Please select your option");
    choice = input.nextInt();
     
    switch(choice)
    {
    case 1 : //Terminate a package item.
    while(check == false)
    {
    System.out.println("Please enter package item code: ");
    packageCode = input.nextLine(); packageCode = input.nextLine();//avoid bug.
     
    while((thisLine=BR.readLine())!=null)
    {
    String[] packArray = thisLine.split("--");
    if(packageCode.equals(packArray[0]))
    {
    String result = thisLine.replaceAll("--", " ");
    System.out.println("-------Package item informations-------");
    System.out.println("Package item code: " + packArray[0]);
    System.out.println("Package item name: " + packArray[1]);
    System.out.println("Package item date started: " + packArray[2]);
    System.out.println("Package item date terminated: " + packArray[3]);
    System.out.println("Package item price charged" + packArray[4]);
    System.out.println("Package item charge type: " + packArray[5] + "\r\n");
    check=true;
     
    System.out.println("Are you sure you would like to terminate this account?");
    do
    {
    System.out.print("Confirm(y/n): ");
    yesno = input.nextLine();
    checks = validation.validateDecision(yesno);
    }while(checks == false);
     
    //char yesnoo = input.nextLine().charAt(0);
    if(checks==true)//not working. bug . help.
    {	BR.reset();
    while((thatLine=BR.readLine())!=null)
    {
    if(!thatLine.equals(thisLine))
    {
    FWtmp.write(thatLine+"\r\n");
    } else
    {
    FWtmp.write(packArray[0]+"--"+packArray[1]+"--"+packArray[2]+"--"+todayD+"--"+packArray[4]
    +"--"+packArray[5]+"--"+packArray[6]+"\r\n");
    }
    }FWtmp.close();FW.close();BR.close();
    fOld.delete();//not working. return false!
    fNew.renameTo(new File("customer.txt"));
    lw.write(h+":"+m+":"+s+" "+todayD+" admin successfully terminated package item type\r\ndetailed:"+packArray[0]+"--"+packArray[1]+"--"+packArray[2]+"--"+todayD+"--"+packArray[4]
    +"--"+packArray[5]+"--"+packArray[6]+"\r\n");
    lw.close();
    System.out.println("Package item code: "+packArray[0]+"\r\n"+"Package item name: "+packArray[1]+"\r\n"+
    "This smartcard number has been successfully terminated.");
    proceed();
    break;
    }else if(checks==false)
    {
    System.out.println("You have chosen NO to terminate a package item. You are now returned to the main menu..");
    mainMenu();
    break;
    }
    }
    }
    }
    default	: System.out.println("Problem in manage package item class..");
    break;
    }
    }
    }
     
    public static void manageProg() throws Exception
    {
    //System declarations.
    Scanner input = new Scanner(System.in);
    BufferedReader BR = new BufferedReader(new FileReader("programmes.txt")); String thisLine, thatLine;//BR use.
    FileWriter FWtmp = new FileWriter("programmestmp.txt", true);//temporarily store into subpackagetmp.txt
    FileWriter FW = new FileWriter("programmes.txt", true);
    FileWriter lw = new FileWriter("log.txt", true);
    BR.mark(7000);//whenever BR.reset() is called, it will return to the wherever you call mark. which is beginning of the file.
    //Other declaration.
    Random rand = new Random();
    boolean check = false;
    boolean checks = false; //add check and checks to avoid complication.
    //Declaring tmp files.
    File fOld = new File("programmes.txt");
    File fNew = new File("programmestmp.txt");
    //Today date function.
    //Today date function.
    Calendar cal = Calendar.getInstance();
    SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    String todayD = df.format(cal.getTime());
    int h = cal.get(Calendar.HOUR_OF_DAY);
    int m = cal.get(Calendar.MINUTE);
    int s = cal.get(Calendar.SECOND);
    //variable declations.
    String accNo, SmartcardNo, name, ID, address, contact;
    //manageProg variables declaration
    String prog = null;
    String progCode, progName, status, viewStat, type, contentOri, desc;
    int choice;
    String yesno;//validate yes or no.
    //WELCOME NOTE.
    System.out.println("You have selected manage TV programme. ");
    //Options.
    System.out.println("1. Create a new TV programme");
    System.out.println("2. Edit an existing TV programme");
    System.out.println("3. Terminate a TV programme");
    System.out.print("Select your options: ");
    choice = input.nextInt();
     
    switch(choice)
    {
    case 1://create new TV programme.
    System.out.println("Please enter new TV programme code: ");//<--Unique key.
    progCode = input.nextLine(); progCode = input.nextLine(); //avoid bug.
    //need a function check if it exist! same for all others. eg add customer.
     
    System.out.println("Please enter TV programme name: ");
    progName = input.nextLine();//validation.
     
    System.out.println("Please enter TV programme description: ");
    desc = input.nextLine();
     
    System.out.println("Please enter TV programme content origin: ");
    contentOri = input.nextLine();
     
    System.out.println("Please enter TV programme viewer status: ");
    viewStat = input.nextLine();
     
    System.out.println("Please enter TV programme type: ");
    type = input.nextLine();
     
    System.out.println("Please enter TV programme note: ");
    contentOri = input.nextLine();
     
    FW.write(progCode+"--"+progName+"--"+desc+"--"+contentOri+"--"+todayD+"--"+"Active"+"--"+viewStat+"--"+type+"\r\n");
    FW.close();
    lw.write(h+":"+m+":"+s+" "+todayD+" admin successfully created tv program \r\ndetailed:"+progCode+"--"+progName+"--"+desc+"--"+contentOri+"--"+todayD+"--"+"Active"+"--"+viewStat+"--"+type+"\r\n");
    lw.close();
    System.out.println("A new TV programme has been successfully created.");
    proceed();
    break;//End of creating a new TV programme.
     
    case 2 : //Edit an existing TV programme
    System.out.println("1. Edit an existing TV programme");
    System.out.println("2. Return to main menu");
    System.out.print("Please select your option");
    choice = input.nextInt();
     
    switch(choice)
    {
    case 1 : //Edit an existing package from a smartcard.
    while(check == false)
    {
    System.out.println("Please enter TV programme code:");
    progCode = input.nextLine(); progCode = input.nextLine();//avoid bug.
    while((thisLine=BR.readLine())!=null)// POSSIBLE HAVING READ PROB AS EARLIER USE READER TO CHECK
    {
    String[] progArray = thisLine.split("--");//subscribe package array.
    if(progCode.equals(progArray[0]))
    {
    String result = thisLine.replaceAll("--", " ");
    System.out.println("-------TV Programme Information-------");
    System.out.println("TV programme's code: " + progArray[0]);
    System.out.println("TV programme's title: " + progArray[1]);
    System.out.println("TV programme's description: " + progArray[2]);
    System.out.println("TV programme content origin: " + progArray[3]);
    System.out.println("TV programme's creation date" + progArray[4]);
    System.out.println("TV programme's status: " + progArray[5]);
    System.out.println("TV programme's viewer status" + progArray[6]);
    System.out.println("TV programme's type" + progArray[7]);
    System.out.println("TV programme's notes" + progArray[8]+"\r\n");
     
    check=true;
    System.out.println("Which information you would like to edit?");
    System.out.println("1. TV programme's code: ");
    System.out.println("2. TV programme's title: ");
    System.out.println("3. TV programme's description: ");
    System.out.println("4. TV programme content origin: ");
    System.out.println("5. TV programme's viewer status");
    System.out.println("6. TV programme's type");
    System.out.println("7. Return to main menu");
    choice = input.nextInt();
     
    switch(choice)
    {
    case 1: //edit TV programme code
    System.out.println("TV programme code: "+progArray[0]+"\r\nTV programme title: "+progArray[1]);
    System.out.println("Please enter new TV programme's code : ");
    progCode = input.nextLine(); progCode = input.nextLine(); //avoid bug.
    BR.reset();//ensure BR read from top of the file again.
    while((thatLine=BR.readLine())!=null)
    {
    if(!thatLine.equals(thisLine))
    {
    FWtmp.write(thatLine+"\r\n");
    } else
    {
    FWtmp.write(progCode+"--"+progArray[1]+"--"+progArray[2]+"--"+progArray[3]+"--"+progArray[4]
    +"--"+progArray[5]+"--"+progArray[6]+"--"+progArray[7]+"--"+progArray[8]+"\r\n");
    }
    }FWtmp.close();FW.close();BR.close();
    fOld.delete();//not working. return false!
    fNew.renameTo(new File("programmes.txt"));
    lw.write(h+":"+m+":"+s+" "+todayD+" admin successfully edit tv program code\r\ndetailed:"+progCode+"--"+progArray[1]+"--"+progArray[2]+"--"+progArray[3]+"--"+progArray[4]
    +"--"+progArray[5]+"--"+progArray[6]+"--"+progArray[7]+"--"+progArray[8]+"\r\n");
    lw.close();
    System.out.println("TV programme's code has been updated successfully. ");
    proceed();
    break;
     
    case 2: //edit TV programme code
    System.out.println("TV programme code: "+progArray[0]+"\r\nTV programme title: "+progArray[1]);
    System.out.println("Please enter new TV programme's name : ");
    progName = input.nextLine(); progName = input.nextLine(); //avoid bug.
    BR.reset();//ensure BR read from top of the file again.
    while((thatLine=BR.readLine())!=null)
    {
    if(!thatLine.equals(thisLine))
    {
    FWtmp.write(thatLine+"\r\n");
    } else
    {
    FWtmp.write(progArray[0]+"--"+progName+"--"+progArray[2]+"--"+progArray[3]+"--"+progArray[4]
    +"--"+progArray[5]+"--"+progArray[6]+"--"+progArray[7]+"--"+progArray[8]+"\r\n");
    }
    }FWtmp.close();FW.close();BR.close();
    fOld.delete();//not working. return false!
    fNew.renameTo(new File("programmes.txt"));
    lw.write(h+":"+m+":"+s+" "+todayD+" admin successfully edit tv program name\r\ndetailed:"+progArray[0]+"--"+progName+"--"+progArray[2]+"--"+progArray[3]+"--"+progArray[4]
    +"--"+progArray[5]+"--"+progArray[6]+"--"+progArray[7]+"--"+progArray[8]+"\r\n");
    lw.close();
    System.out.println("TV programme's name has been updated successfully. ");
    proceed();
    break;
     
    case 3: //edit TV programme description.
    System.out.println("TV programme code: "+progArray[0]+"\r\nTV programme title: "+progArray[1]);
    System.out.println("Please enter new TV programme's description : ");
    desc = input.nextLine(); desc = input.nextLine(); //avoid bug.
    BR.reset();//ensure BR read from top of the file again.
    while((thatLine=BR.readLine())!=null)
    {
    if(!thatLine.equals(thisLine))
    {
    FWtmp.write(thatLine+"\r\n");
    } else
    {
    FWtmp.write(progArray[0]+"--"+progArray[1]+"--"+desc+"--"+progArray[3]+"--"+progArray[4]
    +"--"+progArray[5]+"--"+progArray[6]+"--"+progArray[7]+"--"+progArray[8]+"\r\n");
    }
    }FWtmp.close();FW.close();BR.close();
    fOld.delete();//not working. return false!
    fNew.renameTo(new File("programmes.txt"));
    lw.write(h+":"+m+":"+s+" "+todayD+" admin successfully edit tv program description\r\ndetailed:"+progArray[0]+"--"+progArray[1]+"--"+desc+"--"+progArray[3]+"--"+progArray[4]+"--"+progArray[5]+"--"+progArray[6]+"--"+progArray[7]+"--"+progArray[8]+"\r\n");
    lw.close();
    System.out.println("TV programme's descrption has been updated successfully. ");
    proceed();
    break;
     
    case 4: //edit TV programme content origin
    System.out.println("TV programme code: "+progArray[0]+"\r\nTV programme title: "+progArray[1]);
    System.out.println("Please enter new TV programme's content origin : ");
    contentOri = input.nextLine(); contentOri = input.nextLine(); //avoid bug.
    BR.reset();//ensure BR read from top of the file again.
    while((thatLine=BR.readLine())!=null)
    {
    if(!thatLine.equals(thisLine))
    {
    FWtmp.write(thatLine+"\r\n");
    } else
    {
    FWtmp.write(progArray[0]+"--"+progArray[1]+"--"+progArray[2]+"--"+contentOri+"--"+progArray[4]
    +"--"+progArray[5]+"--"+progArray[6]+"--"+progArray[7]+"--"+progArray[8]+"\r\n");
    }
    }FWtmp.close();FW.close();BR.close();
    fOld.delete();//not working. return false!
    fNew.renameTo(new File("programmes.txt"));
    lw.write(h+":"+m+":"+s+" "+todayD+" admin successfully edit tv program origin\r\ndetailed:"+progArray[0]+"--"+progArray[1]+"--"+progArray[2]+"--"+contentOri+"--"+progArray[4]
    +"--"+progArray[5]+"--"+progArray[6]+"--"+progArray[7]+"--"+progArray[8]+"\r\n");
    lw.close();
    System.out.println("TV programme's content origin has been updated successfully. ");
    proceed();
    break;
     
    case 5: //edit TV programme viewer status
    System.out.println("TV programme code: "+progArray[0]+"\r\nTV programme title: "+progArray[1]);
    System.out.println("Please enter new TV programme's viewer status : ");
    viewStat = input.nextLine(); viewStat = input.nextLine(); //avoid bug.
    BR.reset();//ensure BR read from top of the file again.
    while((thatLine=BR.readLine())!=null)
    {
    if(!thatLine.equals(thisLine))
    {
    FWtmp.write(thatLine+"\r\n");
    } else
    {
    FWtmp.write(progArray[0]+"--"+progArray[1]+"--"+progArray[2]+"--"+progArray[3]+"--"+progArray[4]
    +"--"+progArray[5]+"--"+viewStat+"--"+progArray[7]+"--"+progArray[8]+"\r\n");
    }
    }FWtmp.close();FW.close();BR.close();
    fOld.delete();//not working. return false!
    fNew.renameTo(new File("programmes.txt"));
    lw.write(h+":"+m+":"+s+" "+todayD+" admin successfully edit tv program status\r\ndetailed:"+progArray[0]+"--"+progArray[1]+"--"+progArray[2]+"--"+progArray[3]+"--"+progArray[4]
    +"--"+progArray[5]+"--"+viewStat+"--"+progArray[7]+"--"+progArray[8]+"\r\n");
    lw.close();
    System.out.println("TV programme's viewer status has been updated successfully. ");
    proceed();
    break;
     
    case 6: //edit TV programme type //Comedy etc.
    System.out.println("TV programme code: "+progArray[0]+"\r\nTV programme title: "+progArray[1]);
    System.out.println("Please enter new TV programme's type : ");
    type = input.nextLine(); type = input.nextLine(); //avoid bug.
    BR.reset();//ensure BR read from top of the file again.
    while((thatLine=BR.readLine())!=null)
    {
    if(!thatLine.equals(thisLine))
    {
    FWtmp.write(thatLine+"\r\n");
    } else
    {
    FWtmp.write(progArray[0]+"--"+progArray[1]+"--"+progArray[2]+"--"+progArray[3]+"--"+progArray[4]
    +"--"+progArray[5]+"--"+progArray[6]+"--"+type+"--"+progArray[8]+"\r\n");
    }
    }FWtmp.close();FW.close();BR.close();
    fOld.delete();//not working. return false!
    fNew.renameTo(new File("programmes.txt"));
    lw.write(h+":"+m+":"+s+" "+todayD+" admin successfully edit tv program type\r\ndetailed:"+progArray[0]+"--"+progArray[1]+"--"+progArray[2]+"--"+progArray[3]+"--"+progArray[4]
    +"--"+progArray[5]+"--"+progArray[6]+"--"+type+"--"+progArray[8]+"\r\n");
    lw.close();
    System.out.println("TV programme's type has been updated successfully. ");
    proceed();
    break;
     
    case 7: //Return main menu.
    mainMenu();
    break;
     
    }
    }
    }BR.reset();
    }proceed();
    break;//End of editing TV programmes.
     
    case 2://Return to main menu.
    mainMenu();
    break;
    }
     
    case 3 /Terminate a TV programme
    System.out.println("1. Terminate an existing TV programme");
    System.out.println("2. Return to main menu");
    System.out.print("Please select your option");
    choice = input.nextInt();
     
    switch(choice)
    {
    case 1 : //Terminate a TV programme.
    while(check == false)
    {
    System.out.println("Please enter TV programme's code: ");
    progCode = input.nextLine(); progCode = input.nextLine();//avoid bug.
     
    while((thisLine=BR.readLine())!=null)
    {
    String[] progArray = thisLine.split("--");
    if(progCode.equals(progArray[0]))
    {
    String result = thisLine.replaceAll("--", " ");
    System.out.println("-------Package item informations-------");
    System.out.println("TV programme's code: " + progArray[0]);
    System.out.println("TV programme's title: " + progArray[1]);
    System.out.println("TV programme's description: " + progArray[2]);
    System.out.println("TV programme content origin: " + progArray[3]);
    System.out.println("TV programme's creation date" + progArray[4]);
    System.out.println("TV programme's status: " + progArray[5]);
    System.out.println("TV programme's viewer status" + progArray[6]);
    System.out.println("TV programme's type" + progArray[7]);
    System.out.println("TV programme's notes" + progArray[8]+"\r\n");
    check=true;
     
    System.out.println("Are you sure you would like to terminate this account?");
    do
    {
    System.out.print("Confirm(y/n): ");
    yesno = input.nextLine();
    checks = validation.validateDecision(yesno);
    }while(checks == false);
     
    //char yesnoo = input.nextLine().charAt(0);
    if(checks==true)//not working. bug . help.
    {	BR.reset();
    while((thatLine=BR.readLine())!=null)
    {
    if(!thatLine.equals(thisLine))
    {
    FWtmp.write(thatLine+"\r\n");
    } else
    {
    FWtmp.write(progArray[0]+"--"+progArray[1]+"--"+progArray[2]+"--"+progArray[3]+"--"+progArray[4]
    +"--"+"Terminated"+"--"+progArray[6]+"--"+progArray[7]+"--"+progArray[8]+"\r\n");
    }
    }FWtmp.close();FW.close();BR.close();
    fOld.delete();//not working. return false!
    fNew.renameTo(new File("programmes.txt"));
    lw.write(h+":"+m+":"+s+" "+todayD+" admin successfully terminate tv program \r\ndetailed:"+progArray[0]+"--"+progArray[1]+"--"+progArray[2]+"--"+progArray[3]+"--"+progArray[4]
    +"--"+"Terminated"+"--"+progArray[6]+"--"+progArray[7]+"--"+progArray[8]+"\r\n");
    lw.close();
    System.out.println("TV programme code: "+progArray[0]+"\r\n"+"TV programme name: "+progArray[1]+"\r\n"+
    "This TV programme has been successfully terminated.");
    proceed();
    break; //may not need CHECK.
    }else if(checks==false)
    {
    System.out.println("You have chosen NO to terminate a TV programme. You are now returned to the main menu..");
    mainMenu();
    break;
    }
    }
    }
    }
    default	: System.out.println("Problem in manage package item class..");
    break;
    }
    }
    }
     
    public static void addProgToPack() throws Exception
    {
    Scanner input = new Scanner(System.in);
    BufferedReader BR = new BufferedReader(new FileReader("progNpacks.txt")); String thisLine, thatLine;//BR use.
    FileWriter FWtmp = new FileWriter("progNpackstmp.txt", true);//temporarily store into subpackagetmp.txt
    FileWriter FW = new FileWriter("progNpacks.txt", true);
    FileWriter lw = new FileWriter("log.txt",true);
    BR.mark(7000);//whenever BR.reset() is called, it will return to the wherever you call mark. which is beginning of the file.
    //Other declaration.
    Random rand = new Random();
    boolean check = false;
    boolean checks = false; //add check and checks to avoid complication.
    //Declaring tmp files.
    File fOld = new File("progNpacks.txt");
    File fNew = new File("progNpackstmp.txt");
    //variable declations.
    //Today date function.
    Calendar cal = Calendar.getInstance();
    SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    String todayD = df.format(cal.getTime());
    int h = cal.get(Calendar.HOUR_OF_DAY);
    int m = cal.get(Calendar.MINUTE);
    int s = cal.get(Calendar.SECOND);
    //Prog and Pack variables declaration
    String progCode, progName, packageName, packageCode;
    int choice;
    String yesno;//validate yes or no.
    //WELCOME NOTE.
    System.out.println("You have selected add TV programme to package item. ");
    //Options.
    System.out.println("1. Add TV programme to package item.");
    System.out.println("2. Return to main menu");
    System.out.print("Select your options: ");
    choice = input.nextInt();
     
    switch(choice)
    {
    case 1://Add tv programme to package item.
    System.out.println("Please enter TV programme code: ");//<--Package to be added new programmes.
    progCode = input.nextLine(); progCode = input.nextLine(); //avoid bug.
    //need a function check if it exist! same for all others. eg add customer.
    BufferedReader BRprog = new BufferedReader(new FileReader("programmes.txt")); //bufferedreader programmes.txt
    while((thisLine=BRprog.readLine())!=null)
    {
    String progArray[] = thisLine.split("--");
    if(progCode.equals(progArray[0]))
    {
    System.out.println("TV programme code found. ");
    String result = thisLine.replaceAll("--", " ");
    System.out.println("TV programme result: " + result);
    System.out.println("Which package do you want to add to?");
    System.out.println("Please enter package item code: ");
    packageCode = input.nextLine();
     
    BufferedReader BRpack = new BufferedReader(new FileReader("package.txt"));//bufferreader package.txt
    while((thisLine=BRpack.readLine())!=null)
    {
    String packArray[] = thisLine.split("--");
    if(packageCode.equals(packArray[1]))
    {
    System.out.println("Package item code found. ");
    //write file
    FW.write(packageCode+"--"+packArray[0]+"--"+progCode+"--"+progArray[1]+"\r\n");
    FW.close();
    lw.write(h+":"+m+":"+s+" "+todayD+" admin added a new tv program \r\ndetailed:"+packageCode+"--"+packArray[0]+"--"+progCode+"--"+progArray[1]+"\r\n");
    lw.close();
    System.out.println("A new TV programme has been added to package: "+packageCode+ ", successfully.");
    proceed();//prompt to continue.
    }
    }
    }
    }
    break;//End of creating a new TV programme.
     
    }
     
    }
     
    public static void report() throws Exception
    {
    //System declarations.
    Scanner input = new Scanner(System.in);
    BufferedReader BR = new BufferedReader(new FileReader("customer.txt")); String thisLine;//BR use.
    FileWriter lw = new FileWriter("log.txt",true);
    BR.mark(7000);//whenever BR.reset() is called, it will return to the wherever you call mark. which is beginning of the file.
    //others declaration.
    boolean check = false;
    int counter = 0;
    //Today date function.
    Calendar cal = Calendar.getInstance();
    SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
    String todayD = df.format(cal.getTime());
    int h = cal.get(Calendar.HOUR_OF_DAY);
    int m = cal.get(Calendar.MINUTE);
    int s = cal.get(Calendar.SECOND);
    //WELCOME NOTE.
    System.out.println("You have selected read report. ");
    //Options.
    System.out.println("1. List a customer account and it's service and packages");
    System.out.println("2. List all customer accounts");
    System.out.println("2. Return to main menu");
    System.out.println("Select your options: ");
    int choice;
    choice = input.nextInt();
     
    switch(choice)
    {	case 1 : //search file and compare.
    while(check == false)
    {
    System.out.println("Please enter client's account number: ");
    String accNo = input.nextLine(); accNo = input.nextLine();//avoid bug. test using int (preferably.)
    while((thisLine=BR.readLine())!=null)// make a comparison if it doesn't exist.
    {	String[] custArray = thisLine.split("--");
    if(accNo.equals(custArray[0]))
    {
    check=true;
    System.out.println("-------Customer informations-------");
    System.out.println("Customer's account number: " + custArray[0]);
    System.out.println("Customer's account type: " + custArray[1]);
    System.out.println("Customer's account name: " + custArray[2]);
    System.out.println("Customer's account ID: " + custArray[3]);
    System.out.println("Customer's account address: " + custArray[4]);
    System.out.println("Customer's account contact number: " + custArray[5]);
    System.out.println("Customer's account creation date: " + custArray[6]);
    System.out.println("Customer's status: " + custArray[7] + "\r\n");
     
    BufferedReader BRsc = new BufferedReader(new FileReader("smartcard.txt"));//BR for smartcard.txt
    while((thisLine=BRsc.readLine())!=null)
    {
    String scArray[] = thisLine.split("--");
    if(custArray[0].equals(scArray[0]))
    {
    counter++;//count subs no.
    String result = thisLine.replaceAll("--", " ");
     
    System.out.println("-------Smartcard informations-------");
    System.out.println("Smartcard's subs no : " + counter);
    System.out.println("Smartcard's account number: " + scArray[0]);//smartcard account holder's acc number.
    System.out.println("Smartcard's smartcard number: " + scArray[1]);
    System.out.println("Smartcard's decoder number: " + scArray[2]);
    System.out.println("Smartcard's installation address: " + scArray[3]);
    System.out.println("Smartcard's status: " + scArray[4] + "\r\n");
    System.out.println();
     
    BufferedReader BRspack = new BufferedReader(new FileReader("subpackage.txt"));
    while((thisLine=BRspack.readLine())!=null)
    {
    String spackArray[] = thisLine.split("--");
    if(scArray[0].equals(spackArray[0]))
    {
    System.out.println("-------Package Subscribed Information-------");
    System.out.println("Smartcard's account number: " + spackArray[0]);//smartcard account holder's acc number.
    System.out.println("Subscribed package code: " + spackArray[1]);
    System.out.println("Subscribed package name: " + spackArray[2]);
    System.out.println("Subscription date: " + spackArray[3]);
    System.out.println("Termination date" + spackArray[4]);
    System.out.println("Subscribed package status: " + spackArray[5] + "\r\n");
    }
    }
    }
     
    }
    }
    }
    lw.write(h+":"+m+":"+s+" "+todayD+" admin list all customer and packages:");
    lw.close();
    proceed();
    BR.reset();
    }
    case 2 : //list all customer accounts.
     
    while((thisLine=BR.readLine())!=null)// make a comparison if it doesn't exist.
    {	String[] custArray = thisLine.split("--");
     
    check=true;
    System.out.println("-------Customer informations-------");
    System.out.println("Customer's account number: " + custArray[0]);
    System.out.println("Customer's account type: " + custArray[1]);
    System.out.println("Customer's account name: " + custArray[2]);
    System.out.println("Customer's account ID: " + custArray[3]);
    System.out.println("Customer's account address: " + custArray[4]);
    System.out.println("Customer's account contact number: " + custArray[5]);
    System.out.println("Customer's account creation date: " + custArray[6]);
    System.out.println("Customer's status: " + custArray[7] + "\r\n");
    }
    lw.write(h+":"+m+":"+s+" "+todayD+" admin list all customer account");
    lw.close();
    proceed();
    break;
     
    case 3 : // return to main menu
    mainMenu();
    break;
    default	: System.out.println("Invalid input. Please try again..");
    break;
    }
    }
    }


    This is my customer class
    public abstract class Customer
    {
    //declaring variables.
    protected String accNo, name, ID, address, contact, Atype, cDate, status;
    //constructer.
    public Customer(String accNo, String Atype, String name, String ID, String address, String contact, String cDate, String status)
    {
    this.accNo = accNo;
    this.Atype = Atype;
    this.name = name;
    this.ID = ID; //identify users by their unique ID.
    this.address = address;
    this.contact = contact;
    this.cDate = cDate;
    this.status = status;
    }
    //methods.
    public String getAccNo()
    {
    return accNo;
    }
    public String getName()
    {
    return name;
    }
    public String getID()
    {
    return ID;
    }
    public String getAddress()
    {
    return address;
    }
    public String getContact()
    {
    return contact;
    }
    public String getCDate()
    {
    return cDate;
    }
    public String getStatus()
    {
    return status;
    }
    public void setStatusA()
    {
    status = "Active";
    }
    public void setStatusT()//set terminated
    {
    status = "Terminated";
    }
     
    //abstracts
    //public abstract void printDetail();
    public abstract String getAType();
     
    public String add()
    {
    return "[Book: " + name + ", " + ", " +address + "]";
    }
    }

    This is my individual class
    public class Individual extends Customer
    {
    private double rate; //to be added.
    public Individual(String accNo, String Atype, String name, String ID, String address, String contact, String cDate, String status)
    {
    super( accNo, Atype, name, ID, address, contact, cDate, status);
    }
     
    public String getAType()
    {
    return "Individual";
    }x'
     
    td;h]
     
     
    }

    This is my NGO class
    public class NGO extends Customer
    {
    private double rate; //to be added.
    public NGO(String accNo, String Atype, String name, String ID, String address, String contact,String cDate, String status)
    {
    super( accNo, Atype, name, ID, address, contact, cDate, status);
    }
     
    public String getAType()
    {
    return "NGO";
    }
    }

    This is my government class
    public class Government extends Customer
    {
    private double rate; //to be added.
    public Government(String accNo, String Atype, String name, String ID, String address, String contact , String cDate, String status)
    {
    super( accNo, Atype, name, ID, address, contact, cDate, status);
    }
     
    public String getAType()
    {
    return "Government";
    }
    }
    This is my POrganisation
    public class POrganization extends Customer
    {
    private double rate; //to be added.
    public POrganization(String accNo, String Atype, String name, String ID, String address, String contact, String cDate, String status)
    {
    super( accNo, Atype, name, ID, address, contact, cDate, status);
    }
     
    public String getAType()
    {
    return "POrganization";
    }
     
    }
    Last edited by helloworld922; May 29th, 2011 at 08:41 AM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,610
    Thanks
    45
    Thanked 1,956 Times in 1,930 Posts

    Default Re: Link From A Driver Class To The Subclasses

    Please edit your code and add code tags. See the # icon above the text input box.
    Or see: BB Code List - Java Forums

    Can you explain what your problem is?

Similar Threads

  1. Link Grabber
    By isuru in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 17th, 2011, 03:33 AM
  2. EXAMPLE OF FILTERSTREAMS SUBCLASSES.
    By ordonezc78 in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: March 22nd, 2011, 11:38 PM
  3. Forward to a link from Java
    By makdu in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: November 30th, 2010, 05:45 AM
  4. Can Anyone Check This Link
    By arpitgadle in forum Java Servlet
    Replies: 5
    Last Post: October 7th, 2009, 08:56 AM
  5. How to Hyper-link pages together in Java?
    By don.java1 in forum Java Applets
    Replies: 5
    Last Post: July 21st, 2008, 05:09 AM