Advertisement
4rl3fd

JavaMedsNew

May 24th, 2023 (edited)
703
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 29.46 KB | None | 0 0
  1. import java.util.Scanner; // For Inputs
  2. import java.io.File;  // For File Creation
  3. import java.util.Random;
  4.  
  5. import java.text.SimpleDateFormat;  
  6. import java.util.Date;
  7. import java.io.FileWriter;  
  8.  
  9. import java.io.FileNotFoundException;  //  to handle file errors
  10.  
  11.  
  12. // update 2.0 Changelog
  13. // -Created a system to record usage history(it works!)
  14. // -Used magic to make Java edit txt files(it works!)
  15. //  /=================\
  16. //  |    Ze~  _/\_\|/ |
  17. //  |       ~(n_n()|  |
  18. //  |      []D-\\--|  |
  19. //  \================/
  20.  
  21.  
  22.  
  23. public class Main
  24. {
  25.     public static String LastName, FirstName, MiddleName= ""; // Name Info. Middle Name is Optional
  26.         public static boolean HasMiddleName = false;
  27.        
  28.          
  29.        
  30.         public static String Alphabet[] = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
  31.         public static String Numbers[] = {"0","1","2","3","4","5","6","7","8","9"};
  32.         public static String UserID; // Format = LLNL-NNN
  33.        
  34.         public static String DOB, ContactNo, Address; // general info
  35.         public static String sex;
  36.         public static String S_Format[] = {"Male", "M", "Female", "F", "Other", "O", "N/A", "Not Applicable", "NA", "N"};
  37.        
  38.         public static String userinput;
  39.        
  40.         public static String invalidfiles[] = {"HISTORY.txt", "Main.java"};
  41.         public static boolean admin = false;
  42.        
  43.         public static String username = "PayongEmployee", password = "P4Y0NG";
  44.        
  45.         public static String histo[] = {"","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""};
  46.         public static int nlog = 0;
  47.        
  48.         public static String Conditions[] = {"","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""};
  49.         public static String Medications[] = {"","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""};
  50.         public static int NOC =0; // number of conditions
  51.         public static int NOM =0; // number of Medications
  52.         public static String Allergies[] = {"","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""};
  53.         public static int NOA = 0; //number of Allergies
  54.        
  55.         public static String BT[] ={"O+", "O-", "A+", "A-", "AB+", "AB-", "B+", "B-"};
  56.         public static boolean legit = false; //to see if the user's bloodtype is equal to any the above
  57.         public static String BloodType= "";
  58.        
  59.         public static String AdditionalInfo= "";
  60.        
  61.         public static String CompanyName = "PAYONG CORPORATION", Branch = "LAS PIÑAS-MUNTINLUPA PHILIPPINES BRANCH";
  62.        
  63.         public static void DisDir(){
  64.             File currentDirectory = new File(".");
  65.         File[] files = currentDirectory.listFiles();
  66.  
  67.         if (files != null) {
  68.             for (File file : files) {
  69.                 if (file.isFile()) {
  70.                     System.out.println(file.getName());
  71.                 }
  72.             }
  73.         }
  74.         SimpleDateFormat newformat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");  
  75.          Date nodates = new Date();
  76.         String cdate = newformat.format(nodates);
  77.         histo[nlog] = cdate+": Displayed Directory";
  78.         nlog++;
  79.         }
  80.        
  81.                                  
  82.         public static String finame = "";
  83.         public static void Update() throws Exception{ // updates any file selected by the user.
  84.             boolean k = false;
  85.             boolean m = false;
  86.             boolean s = false;
  87.            
  88.             Scanner ir = new Scanner (System.in);
  89.            
  90.             do {
  91.                
  92.            
  93.             String DiLines[] = {"","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""};    
  94.                
  95.                 for(int i=0; i!=10; i++) {
  96.                    
  97.                        
  98.                 System.out.print("Please enter the name of the file you wish to edit(.txt required): ");
  99.            
  100.             userinput = ir.nextLine();
  101.             finame = "";
  102.             finame = userinput;
  103.             File myReader = new File(userinput);
  104.             Scanner rfil = new Scanner(myReader);
  105.             int lcount =0;
  106.             String selected = "";
  107.             while (rfil.hasNextLine()) {
  108.         String data = rfil.nextLine();
  109.         System.out.println(lcount + "|" + data);
  110.         DiLines[lcount] = data;
  111.         lcount++;
  112.         }
  113.         break;
  114.  
  115.             }
  116.                
  117.             do {
  118.             File tempfile = new File("temp.txt");
  119.             int snum =0;
  120.             System.out.println("Please enter the number of the line you wish to edit: ");
  121.             int usinp = ir.nextInt();
  122.            
  123.             for(int i=0; i< DiLines.length; i++){
  124.                 if(i == usinp) {
  125.                     System.out.println("\nPlease make your modifications: ");
  126.                     System.out.println(DiLines[usinp]);
  127.                     // NOTE: Creeate an input that can modify the string
  128.                    
  129.                     boolean editing = true;
  130.                     String A = DiLines[usinp];
  131.                    
  132.                    
  133.                     while (editing) {
  134.             System.out.println("Enter ']' to backspace, '*' to finish\n(p.s. Please make sure that you are finished editing before exiting)");
  135.             System.out.print(A);
  136.             String input = ir.nextLine();
  137.            
  138.             if (input.equals("]")) {
  139.                 if (A.length() > 0) {
  140.                     A = A.substring(0, A.length() - 1);
  141.                    
  142.                 }
  143.             } else if (input.equals("*")) {
  144.                 editing = false;
  145.             } else {
  146.                 A += input;
  147.             }
  148.             System.out.print("\033[H\033[2J");
  149.         System.out.flush();
  150.         }
  151.         System.out.println(A);
  152.                    DiLines[usinp] = "";
  153.                    DiLines[usinp] = A;
  154.                    
  155.                     break;
  156.                 }
  157.                 System.out.print("\033[H\033[2J");
  158.                 System.out.flush();
  159.             }
  160.            
  161.             File dfil = new File(finame);
  162.             dfil.delete();
  163.            
  164.            
  165.             FileWriter wright = new FileWriter(finame);
  166.             for(int i=0; i < DiLines.length; i++) {
  167.                 wright.write(DiLines[i] + "\n");
  168.             }
  169.             SimpleDateFormat newformat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");  
  170.          Date nodates = new Date();
  171.             String cdate = newformat.format(nodates);
  172.         histo[nlog] = cdate+": Edited " + finame;
  173.         nlog++;
  174.             System.out.println("Would you like to edit the same file? (Y = Yes/N = No/ R = Return to Main Menu)");
  175.             do{
  176.                
  177.             wright.close();
  178.             userinput = "";
  179.             userinput = ir.nextLine();
  180.             if(userinput.equalsIgnoreCase("Y") || userinput.equalsIgnoreCase("YES")) {
  181.                 m = false;
  182.                 s = true;
  183.             } else if(userinput.equalsIgnoreCase("N") || userinput.equalsIgnoreCase("NO")) {
  184.                 m = true;
  185.                 s = true;
  186.             } else if(userinput.equalsIgnoreCase("R") || userinput.equalsIgnoreCase("RETURN")) {
  187.                 return;
  188.             } else {
  189.                 s = false;
  190.             }
  191.            
  192.             }while(s == false);
  193.            
  194.             }while(m == false);
  195.             SimpleDateFormat newformat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");  
  196.          Date nodates = new Date();
  197.             String cdate = newformat.format(nodates);
  198.         histo[nlog] = cdate+": Edited " + finame;
  199.         nlog++;
  200.            
  201.             }while( k == false);
  202.         }
  203.        
  204.         public static void showhist ()throws Exception // shows the usage history of the program
  205.         {
  206.             Scanner ir = new Scanner (System.in);
  207.             boolean chk = false;
  208.             System.out.println("Would you like to view this application's FULL(1) usage history, or the RECENT(2) usage history?\nOr would you like to RETURN(3) to the Main Menu?");;
  209.             userinput = "";
  210.             userinput = ir.nextLine();
  211.             if(userinput.equalsIgnoreCase("1") || userinput.equalsIgnoreCase("FULL")){
  212.                 System.out.print("\033[H\033[2J");
  213.         System.out.flush();
  214.                
  215.                 System.out.println("Now Displaying the Full Use History: \n");
  216.                
  217.             File myReader = new File("HISTORY.txt");
  218.                
  219.             Scanner rfil = new Scanner(myReader);
  220.                
  221.             while (rfil.hasNextLine()) {
  222.         String data = rfil.nextLine();
  223.         System.out.println(data);
  224.         }
  225.         rfil.close();
  226.             } else if(userinput.equalsIgnoreCase("2") || userinput.equalsIgnoreCase("RECENT")){
  227.                 System.out.print("\033[H\033[2J");
  228.         System.out.flush();
  229.                 System.out.println("Now Displaying the Recent Use History: \n");
  230.                 for(int i=0; i!=nlog; i++){
  231.                     System.out.println(histo[i]);
  232.                 }
  233.                
  234.             } else if(userinput.equalsIgnoreCase("3") || userinput.equalsIgnoreCase("RETURN")){
  235.                 System.out.print("\033[H\033[2J");
  236.         System.out.flush();
  237.                 return;
  238.             }
  239.         }
  240.        
  241.         public static void GetData()throws Exception{ // acquires the initial data from the user
  242.             Scanner ir = new Scanner (System.in);
  243.         System.out.print("\033[H\033[2J");
  244.         System.out.flush();
  245.         System.out.println("==============================");
  246.         System.out.println("====|Registration Process|====");
  247.         System.out.println("==============================");
  248.         System.out.print("\nPlease Enter Your Last Name: ");
  249.         LastName = ir.nextLine ();
  250.         System.out.print("\nPlease Enter Your First Name: ");
  251.         FirstName = ir.nextLine ();
  252.         System.out.print("\nWould You Like to Enter Your Middle Name? ");
  253.         userinput = ir.nextLine ();
  254.         if(userinput.equalsIgnoreCase("Y") || userinput.equalsIgnoreCase("YES")) {
  255.             System.out.print("\nPlease Enter Your Middle Name: ");
  256.             MiddleName = ir.nextLine ();
  257.         }
  258.         System.out.print("\n\nPlease Enter Your Date of Birth(MM/DD/YYYY): ");
  259.         DOB = ir.nextLine ();
  260.         boolean hasfoundsex = false;
  261.         do{
  262.             System.out.print("\nPlease Enter Your Sex: ");
  263.         sex = ir.nextLine();
  264.             for(int i=0; i!= S_Format.length; i++){
  265.             if(sex.equalsIgnoreCase(S_Format[i])) {
  266.                 sex = S_Format[i];
  267.                 hasfoundsex = true;
  268.                 }
  269.             }
  270.             if(hasfoundsex == false){
  271.                 System.out.println("INVALID INPUT PLEASE TRY AGAIN");
  272.                 sex = "";
  273.             }
  274.         }while(hasfoundsex == false);
  275.        
  276.         System.out.print("\nPlease Enter Your Contact No.: +63 ");
  277.         ContactNo = ir.nextLine ();
  278.         System.out.print("\nPlease Enter Your Home Address: ");
  279.         Address = ir.nextLine ();
  280.         System.out.print("\n");
  281.         System.out.print("Please Enter Any Known Condition(type DONE when finished): ");
  282.         while(!"DONE".equalsIgnoreCase(userinput)){
  283.             userinput ="";
  284.             userinput = ir.nextLine ();
  285.             Conditions[NOC] = userinput;
  286.             NOC++;
  287.         }
  288.         NOC--;
  289.         userinput ="";
  290.         System.out.print("\nPlease Enter Prescribed Medications(type DONE when finished): ");
  291.         while(!"DONE".equalsIgnoreCase(userinput)){
  292.             userinput ="";
  293.             userinput = ir.nextLine ();
  294.             Medications[NOM] = userinput;
  295.             NOM++;
  296.         }
  297.         NOM--;
  298.         System.out.print("\nPlease Enter Your Allergies(type DONE when finished): ");
  299.         userinput ="";
  300.         while(!"DONE".equalsIgnoreCase(userinput)){
  301.             userinput ="";
  302.             userinput = ir.nextLine ();
  303.             Allergies[NOA] = userinput;
  304.             NOA++;
  305.         }
  306.         NOA--;
  307.         userinput ="";
  308.         while(legit == false){
  309.             System.out.print("\nPlease Enter Your Blood Type: ");
  310.             BloodType = ir.nextLine ();
  311.            
  312.             for(int i=0; i!= BT.length; i++){
  313.                 if(BloodType.equalsIgnoreCase(BT[i])){
  314.                     legit = true;
  315.                 }
  316.             }
  317.             if(legit == false){
  318.                 System.out.println("\nPlease Enter A Valid Blood Type");
  319.             }
  320.            
  321.         }
  322.        
  323.         userinput = "";
  324.         System.out.print("\nDo You Have Any Additional Information? ");
  325.         userinput = ir.nextLine();
  326.         if(userinput.equalsIgnoreCase("YES") || userinput.equalsIgnoreCase("Y")){
  327.             AdditionalInfo = ir.nextLine();
  328.         }
  329.         }
  330.        
  331.         public static void display()throws Exception{ // displays the data after receiving it
  332.             SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");  
  333.         Date date = new Date();  
  334.             Random rand = new Random ();
  335.             UserID = Alphabet[rand.nextInt(Alphabet.length)] + Alphabet[rand.nextInt(Alphabet.length)] + Numbers[rand.nextInt(Numbers.length)] + Alphabet[rand.nextInt(Alphabet.length)] + "-" + Numbers[rand.nextInt(Numbers.length)] +Numbers[rand.nextInt(Numbers.length)] + Numbers[rand.nextInt(Numbers.length)];
  336.             System.out.print("\033[H\033[2J");
  337.         System.out.flush();
  338.         System.out.println("\nDisplaying Information...");
  339.         System.out.print("\n\nNAME: " + LastName + ", " + FirstName);
  340.         if(!"".equalsIgnoreCase(MiddleName)){
  341.             System.out.print(" " + MiddleName);
  342.         }
  343.         System.out.println("\nUSER IDENTIFICATION: "+ UserID);
  344.         System.out.println("\nDATE OF BIRTH(MM/DD/YYYY): " + DOB);
  345.         System.out.println("\nSEX: " + sex);
  346.         System.out.println("CONTACT NUMBER: (+63)" + ContactNo);
  347.         System.out.println("HOME ADDRESS: " + Address);
  348.         System.out.println("DATE REGISTERED: "+ formatter.format(date));
  349.         System.out.println("BLOOD TYPE: "+ BloodType);
  350.         System.out.println("========================================");
  351.        
  352.         if(NOC > 0){
  353.             System.out.println("KNOWN CONDTIONS: ");
  354.         for(int i=0; i!=NOC; i++){
  355.             System.out.println((i+1) + "|| " + Conditions[i]);
  356.         }
  357.         }
  358.        
  359.         if(NOA > 0){
  360.             System.out.println("KNOWN ALLERGIES: ");
  361.         for(int i=0; i!=NOA; i++){
  362.             System.out.println((i+1) + "|| " + Allergies[i]);
  363.         }
  364.         }
  365.        
  366.         if(NOM > 0){
  367.             System.out.println("PRESCRIBED MEDICATIONS: ");
  368.         for(int i=0; i!=NOM; i++){
  369.             System.out.println((i+1) + "|| " + Medications[i]);
  370.         }
  371.         }
  372.        
  373.         if(!"".equalsIgnoreCase(AdditionalInfo)){
  374.             System.out.println("ADDITIONAL INFORMATION:\n"+ AdditionalInfo);
  375.         }
  376.         }
  377.        
  378.         public static String toString(char[] a)
  379.     { // converts a char array into a string
  380.         String string = new String(a);
  381.  
  382.         return string;
  383.     }
  384.        
  385.         public static void writehistory() throws Exception{ // writes the current usage history into HISTORY.txt. This is only called once the program is about to close to avoid any repeats
  386.             FileWriter whis = new FileWriter("HISTORY.txt",true);
  387.             for(int i =0; i < nlog; i++) {
  388.                 whis.write(histo[i] + "\n");
  389.             }
  390.             whis.close();
  391.         }
  392.        
  393.         public static void Search() throws Exception { // receives input from the user and searches for files in the active directory for any files containing all those letters
  394.             String inpt = "";
  395.             boolean firstbool = false;
  396.             boolean secbool = false;
  397.             Scanner ir = new Scanner (System.in);
  398.             File currentDirectory = new File(".");
  399.         File[] files = currentDirectory.listFiles();
  400.         String AllFiles[] = {"","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""};
  401.         int sk =0;
  402.         int flength =0;
  403.         if (files != null) {
  404.             for (File file : files) {
  405.                 if (file.isFile()) {
  406.                     AllFiles[sk] = file.getName();
  407.                     sk++;
  408.                     flength++;
  409.                 }
  410.             }
  411.         }
  412.         for(int i=0; i!=AllFiles.length; i++){
  413.             System.out.println(AllFiles[i]);
  414.         }
  415.         do
  416.         {
  417.             System.out.print("\033[H\033[2J");
  418.         System.out.flush();
  419.         inpt = "";
  420.         firstbool = false;
  421.         secbool = false;
  422.        
  423.         System.out.print("Please Enter a Keyword for the file you wish to find: ");
  424.         char [] KW = ir.next().toCharArray();
  425.         String Refined [] = {"","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""};
  426.         System.out.print("\nSearch Results for '");
  427.         sk =0;
  428.         for(int i=0; i!=KW.length; i++) {
  429.             System.out.print(KW[i]);
  430.         }
  431.         System.out.println("':\n");
  432.         for(int i = 0; i< flength; i++) {
  433.             char hc = AllFiles[i].charAt(i);
  434.             for(int j =0; j != KW.length; j++) {
  435.                 if(KW[j] == hc) {
  436.                     Refined[sk] = AllFiles[i];
  437.                     System.out.println(AllFiles[i]);
  438.                     sk++;
  439.                 }
  440.             }
  441.         }
  442.        
  443.         String sterm = toString(KW);
  444.  
  445.         SimpleDateFormat newformat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");  
  446.          Date nodates = new Date();
  447.         String cdate = newformat.format(nodates);
  448.         histo[nlog] = cdate+": Searched for '" + sterm + "'";
  449.         nlog++;
  450.        
  451.         inpt = "";
  452.         System.out.println("Would you like to search for another term?(Y/N)");
  453.         do
  454.         {
  455.             inpt = ir.nextLine();
  456.             if(inpt.equalsIgnoreCase("Y") || inpt.equalsIgnoreCase("YES")) {
  457.                 firstbool = true;
  458.             } else if(inpt.equalsIgnoreCase("N") || inpt.equalsIgnoreCase("NO")) {
  459.                 firstbool = true;
  460.                 secbool = true;
  461.             } else {
  462.                 System.out.println("Please Answer with a YES or a NO");
  463.             }
  464.         } while(firstbool == false);
  465.         } while (secbool == false);
  466.         }
  467.        
  468.         public static void WToFile()throws Exception{ // writes the given data provided by the user into a .txt file
  469.             SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");  
  470.         Date date = new Date();  
  471.             File myObj = new File(LastName + UserID + ".txt");
  472.         FileWriter myWriter = new FileWriter(LastName + UserID + ".txt");
  473.        
  474.         myWriter.write("<<<<< " + CompanyName + " MEDICAL ID REGISTRATION SYSTEM >>>>>");
  475.         myWriter.write("\n      " + Branch);
  476.        
  477.         myWriter.write("\n\nNAME: " + LastName + ", " + FirstName);
  478.         if(!"".equalsIgnoreCase(MiddleName)){
  479.             myWriter.write(" " + MiddleName);
  480.         }
  481.         myWriter.write("\nUSER IDENTIFICATION: "+ UserID);
  482.         myWriter.write("\nDATE OF BIRTH(MM/DD/YYYY): " + DOB);
  483.         myWriter.write("\nSEX: " + sex);
  484.         myWriter.write("\nCONTACT NUMBER: (+63)" + ContactNo);
  485.         myWriter.write("\nHOME ADDRESS: " + Address);
  486.         myWriter.write("\nDATE REGISTERED: "+ formatter.format(date));
  487.         myWriter.write("\nBLOOD TYPE: "+ BloodType);
  488.         myWriter.write("\n========================================");
  489.        
  490.         if(NOC > 0){
  491.             myWriter.write("\nKNOWN CONDTIONS: ");
  492.         for(int i=0; i!=NOC; i++){
  493.             myWriter.write("\n"+ (i+1) + "|| " + Conditions[i]);
  494.         }
  495.         }
  496.        
  497.         if(NOA > 0){
  498.             myWriter.write("\nKNOWN ALLERGIES: ");
  499.         for(int i=0; i!=NOA; i++){
  500.             myWriter.write("\n"+ (i+1) + "|| " + Allergies[i]);
  501.         }
  502.         }
  503.        
  504.         if(NOM > 0){
  505.             myWriter.write("\nPRESCRIBED MEDICATIONS: ");
  506.         for(int i=0; i!=NOM; i++){
  507.             myWriter.write("\n"+ (i+1) + "|| " + Medications[i]);
  508.         }
  509.         }
  510.        
  511.         if(!"".equalsIgnoreCase(AdditionalInfo)){
  512.             myWriter.write("\nADDITIONAL INFORMATION:\n"+ AdditionalInfo);
  513.         }
  514.        
  515.         myWriter.close();
  516.         SimpleDateFormat newformat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");  
  517.          Date nodates = new Date();
  518.         String cdate = newformat.format(nodates);
  519.         histo[nlog] = cdate+": Created " + LastName + UserID + ".txt";
  520.         nlog++;
  521.         }
  522.        
  523.         public static void reset(){ // resets all used values to prevent any overflow or errors
  524.              LastName="";
  525.              FirstName="";
  526.              MiddleName= "";
  527.          HasMiddleName = false;
  528.          UserID = "";
  529.          String DOB ="", ContactNo="", Address="";
  530.         userinput="";
  531.        
  532.         for(int i=0; i!= Conditions.length; i++){
  533.             Conditions[i] = "";
  534.             Medications[i] = "";
  535.             Allergies[i] = "";
  536.         }
  537.          NOC =0;
  538.          NOM =0;
  539.          NOA = 0;
  540.          legit = false;
  541.          BloodType= "";
  542.        
  543.          AdditionalInfo= "";
  544.         }
  545.        
  546.         public static void DelFil() throws Exception { // deletes any file selected by the user
  547.         boolean isv = true;
  548.             Scanner ir = new Scanner (System.in);
  549.             userinput = "";
  550.             for(int i=0; i!=10; i++) {
  551.                 do{
  552.                    
  553.                 System.out.print("Please enter the name of the file you wish to delete(.txt required): ");
  554.             userinput = ir.nextLine();
  555.             for(int j=0; j!= invalidfiles.length; j++){
  556.                 if(userinput.equalsIgnoreCase(invalidfiles[i])){
  557.                     System.out.println("Error. Cannot delete " + userinput + ". It is a necessary file!");
  558.                     isv = false;
  559.                 }
  560.             }
  561.                 } while(isv == false);
  562.             File myObj = new File(userinput);
  563.             if(myObj.delete()) {
  564.                 System.out.println("Deleted the file: " + userinput);
  565.                 break;
  566.             } else {
  567.                 System.out.println("Error! Failed to delete file!\nMake sure you typed its name correctly and you included the '.txt' extension");
  568.             }
  569.             }
  570.            
  571.             SimpleDateFormat newformat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");  
  572.          Date nodates = new Date();
  573.         String cdate = newformat.format(nodates);
  574.         histo[nlog] = cdate+": Deleted " + userinput;
  575.         nlog++;
  576.         }
  577.        
  578.         public static void ReadFile() throws Exception { // reads any file selected by the user
  579.             Scanner ir = new Scanner (System.in);
  580.             try {
  581.                 for(int i=0; i!=10; i++) {
  582.                 System.out.print("Please enter the name of the file you wish to read(.txt required): ");
  583.             userinput = ir.nextLine();
  584.             File myReader = new File(userinput);
  585.             Scanner rfil = new Scanner(myReader);
  586.             while (rfil.hasNextLine()) {
  587.         String data = rfil.nextLine();
  588.         System.out.println(data);
  589.         }
  590.         rfil.close();
  591.         break;
  592.             }
  593.                
  594.             }catch (FileNotFoundException e){
  595.                 System.out.println("An error occurred. Please make sure you typed the file name correctly");
  596.       e.printStackTrace();
  597.             }
  598.            
  599.        
  600.         SimpleDateFormat newformat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");  
  601.          Date nodates = new Date();
  602.         String cdate = newformat.format(nodates);
  603.         histo[nlog] = cdate+": Read " + userinput;
  604.         nlog++;
  605.         }
  606.        
  607.         public static void verifyhist(){ // verifies if HISTORY.txt exists. If not, then it creates one.
  608.             File findhist = new File("HISTORY.txt");
  609.             if(!findhist.exists()){
  610.                 File MOB = new File ("HISTORY.txt");
  611.             }
  612.         }
  613.        
  614.     public static void main(String[] args) throws Exception {
  615.         verifyhist();
  616.         Scanner ir = new Scanner (System.in);
  617.         SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");  
  618.         Date date = new Date();  
  619.         Random rand = new Random ();
  620.         boolean isclosed = false;
  621.         boolean isdone = false;
  622.         boolean pword = false;
  623.         String pinput, uinput;
  624.        
  625.         System.out.println("        =============================================================");
  626.         System.out.println("        ||    " + CompanyName + " MEDICAL ID REGISTRATION SYSTEM    ||");
  627.         System.out.println("        =============================================================");
  628.         System.out.println("        .-^-..-^-..-^-..-^-..-^-..-^-.|.-^-..-^-..-^-..-^-..-^-..-^-.");
  629.         System.out.println("          j    j    j    j    j    j  |  j    j    j    j    j    j");
  630.         do{
  631.         System.out.print("Please Enter the username: ");
  632.         uinput = ir.nextLine();
  633.         System.out.print("\nPlease Enter the password: ");
  634.         pinput = ir.nextLine();
  635.        
  636.         if(pinput.equals(password) && uinput.equals(username)){
  637.             pword = true;
  638.         } else {
  639.             System.out.println("Incorrect Username or Password, please try again\n");
  640.         }
  641.         userinput = "";
  642.         uinput = "";
  643.         pinput = "";
  644.         }while(pword == false);
  645.         System.out.print("\033[H\033[2J");
  646.         System.out.flush();
  647.         do{
  648.             System.out.println("        <<<<< " + CompanyName + " MEDICAL ID REGISTRATION SYSTEM >>>>>");
  649.         System.out.println("                  " + Branch);
  650.         System.out.println("\n                    What would you like to do?");
  651.             System.out.println("\n1> REGISTER a new account             2> READ an existing account\n3> DELETE an existing account         4> DISPLAY all accounts\n5> SEARCH for accounts                6> ABOUT this Application\n7> View use HISTORY                   8> EDIT a file\n9> EXIT the program");
  652.             isclosed = false;
  653.             isdone = false;
  654.             reset();
  655.             userinput = "";
  656.             userinput = ir.nextLine();
  657.             if(userinput.equalsIgnoreCase("1") ||userinput.equalsIgnoreCase("REGISTER") ){
  658.                 GetData();
  659.                 display();
  660.                 WToFile();
  661.                 System.out.println("\nFILE SUCCESFULLY SAVED!");
  662.                 userinput = "";
  663.                 do {
  664.                     System.out.print("\nWould You Like to Create Another Account(YES/NO)? ");
  665.             userinput = ir.nextLine();
  666.             if(userinput.equalsIgnoreCase("NO") || userinput.equalsIgnoreCase("N")){
  667.             isdone = true;
  668.         } else if(userinput.equalsIgnoreCase("YES") || userinput.equalsIgnoreCase("Y")){
  669.             System.out.print("\033[H\033[2J");
  670.         System.out.flush();
  671.         GetData();
  672.                 display();
  673.                 WToFile();
  674.             isdone = true;
  675.         } else {
  676.             System.out.println("\nINVALID INPUT, PLEASE TRY AGAIN");
  677.         }
  678.         } while (isdone == false);
  679.             } else if(userinput.equalsIgnoreCase("2") ||userinput.equalsIgnoreCase("READ")){
  680.                     ReadFile();
  681.             } else if(userinput.equalsIgnoreCase("3") ||userinput.equalsIgnoreCase("DELETE")) {
  682.                 DelFil();
  683.             } else if(userinput.equalsIgnoreCase("4") ||userinput.equalsIgnoreCase("DISPLAY")){
  684.                 DisDir();
  685.                 System.out.println("\n\n");
  686.             }else if(userinput.equalsIgnoreCase("9") ||userinput.equalsIgnoreCase("EXIT")) {
  687.                 for(int i=0; i!= 999; i++) {
  688.                     userinput = "";
  689.                 System.out.println("ARE YOU SURE?");
  690.                     userinput= ir.nextLine();
  691.                     if(userinput.equalsIgnoreCase("NO") || userinput.equalsIgnoreCase("N")){
  692.             break;
  693.         } else if(userinput.equalsIgnoreCase("YES") || userinput.equalsIgnoreCase("Y")){
  694.             writehistory();
  695.             isclosed = true;
  696.             break;
  697.         }else {
  698.             System.out.println("\nINVALID INPUT, PLEASE TRY AGAIN");
  699.         }
  700.                 }
  701.             } else if(userinput.equalsIgnoreCase("6") || userinput.equalsIgnoreCase("ABOUT")) {
  702.                 System.out.print("\033[H\033[2J");
  703.                 System.out.flush();
  704.                 System.out.println("The Payong Corporation Medical Identification Registration System (PaCoMIRS for short) is");
  705.                 System.out.println("a Java Application designed for use by Payong Corporation Employees in official Payong");
  706.                 System.out.println("Corporation branch firms to register new members or update the accounts of existing members.");
  707.                 System.out.println("\nenter any input to return to menu");
  708.                 userinput = "";
  709.                 userinput = ir.nextLine();
  710.                 System.out.print("\033[H\033[2J");
  711.                 System.out.flush();
  712.             }else if (userinput.equalsIgnoreCase("5") ||userinput.equalsIgnoreCase("SEARCH")) {
  713.                 System.out.print("\033[H\033[2J");
  714.         System.out.flush();
  715.                 Search();
  716.             } else if(userinput.equalsIgnoreCase("7") ||userinput.equalsIgnoreCase("HISTORY")) {
  717.                 System.out.print("\033[H\033[2J");
  718.         System.out.flush();
  719.                 showhist();
  720.             }else if(userinput.equalsIgnoreCase("8") ||userinput.equalsIgnoreCase("EDIT")) {
  721.                 System.out.print("\033[H\033[2J");
  722.         System.out.flush();
  723.                 Update();
  724.             }
  725.             else {
  726.                 System.out.println("\nINVALID INPUT, PLEASE TRY AGAIN");
  727.                 System.out.print("\033[H\033[2J");
  728.         System.out.flush();
  729.             }
  730.         }while (isclosed == false );
  731.         System.out.print("\033[H\033[2J");
  732.         System.out.flush();
  733.     }
  734. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement