Advertisement
Guest User

clockwork2

a guest
Aug 16th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 13.98 KB | None | 0 0
  1. package Phase3;
  2. import javax.swing.JOptionPane;
  3. import java.io.*;
  4. import java.util.*;
  5. import java.text.*;
  6. public class Phase3 {
  7.     //START CLASS 1
  8.         //START MAIN METHOD
  9.         public static void main(String[] args)
  10.         {
  11.         moonymca YMCAinfo = new moonymca();
  12.         YMCAinfo.start_system();
  13.         int selection;
  14.         selection = YMCAinfo.menu();
  15.         while(selection !=4)
  16.         {//WHILE LOOP START
  17.             if(selection==1)
  18.                 YMCAinfo.Modify_member();
  19.             else
  20.                 if(selection==2)
  21.                     YMCAinfo.Modify_registration();
  22.                 else
  23.                     if(selection==3)
  24.                         YMCAinfo.Report(selection, null, args, args, args, null, args, selection, null, args, args, selection, null, null);
  25.             selection = YMCAinfo.menu();
  26.         }//WHILE LOOP END
  27.         YMCAinfo.Exit_ymca_program();  
  28.         System.exit(0);
  29.         }//END MAIN METHOD
  30. }//END CLASS 1
  31.  
  32. class moonymca
  33. {
  34.             int[] imember_code=new int[100];
  35.             String[] imember_type=new String[100];
  36.             String[] ifirst_name=new String[100];
  37.             String[] ilast_name=new String[100];
  38.             int[] iage=new int[100];
  39.             String[] igender=new String[100];
  40.             int count1=-1;
  41.            
  42.            
  43.             int[] iclass_code=new int[100];
  44.             String[] iclass_name=new String[100];
  45.             String[] ibeginning_date=new String[100];
  46.             int count2=-1;
  47.            
  48.            
  49.             int[] iregister_member_code=new int[100];
  50.             int[] iregister_class_code=new int[100];
  51.             int count3=-1;
  52.                
  53. void start_system()
  54. {
  55.               count1=Begin_read_member(count1,imember_code,imember_type,ifirst_name,ilast_name,iage,igender);//run only once at beginning before loop, will define code to read in member info
  56.               count2=Begin_read_class(count2,iclass_code,iclass_name,ibeginning_date);//run only once at beginning before loop, will define code to read in class info
  57.               count3=Begin_read_register(count3,iregister_member_code,iregister_class_code);//run only once at beginning before loop, will define code to read in register info
  58.              
  59.                   int selection;
  60.                   selection=menu();
  61.                  
  62.                   while(selection!=4)
  63.                   {
  64.                   if (selection == 1)//Add/Modify Member Information
  65.                   {
  66.                       Modify_member();//functionality added later to add, delete, change basic member info
  67.                   }
  68.                   else if (selection == 2)//Add/Modify Registrations
  69.                   {
  70.                       Modify_registration();//functionality added later to add class registration info
  71.                   }
  72.                   else if (selection == 3)//Report Section
  73.                   {
  74.                       Report(count1,imember_code,imember_type,ifirst_name,ilast_name,iage,igender,
  75.                             count2,iclass_code,iclass_name,ibeginning_date,
  76.                             count3,iregister_member_code,iregister_class_code);
  77.                   }
  78.                   selection =menu();
  79.                   }//WHILE LOOP
  80.                  
  81.                   Exit_ymca_program();//run only once at end after loop, will write all data back to various files
  82.                  
  83.                   System.exit(0);//Do i move this to the first class at the end?
  84.         }
  85.  
  86.        
  87.         //START MENU
  88. int menu()
  89.                 {
  90.                   String mnumber;
  91.                   int number;
  92.                   String output = "Moon Area YMCA" + " \n " + " \n " +
  93.                       "1. Add/Modify Member Information" + " \n " +
  94.                       "2. Add/Modify Registrations" + " \n " +
  95.                       "3. Report Section" + " \n" + " \n " +
  96.                       "4. Exit the System" + " \n" +
  97.                       "Please make your selection  >";
  98.                        mnumber = JOptionPane.showInputDialog(null, output, " ",
  99.                                JOptionPane.QUESTION_MESSAGE);
  100.                        number=Integer.parseInt(mnumber);
  101.                        return number;
  102.                 } //END MENU
  103.  
  104.                
  105.             //Modify_member Start
  106. int Modify_member(int count4,int[]imember_code,String[]imember_type,
  107.         String[]ifirst_name,String[]ilast_name,int[]iage,String[]igender)
  108.                 {
  109.       String mnumber,output;
  110.       int number;
  111.       String output = "Member Modification Menu" + " \n " + " \n " +
  112.           "1. Add Member" + " \n " +
  113.           "2. Delete Member" + " \n " +
  114.           "3. Modify Member Information" + " \n" + " \n " +
  115.           "4. Exit Modification Menu" + " \n" + " \n " +    
  116.           "Please make your selection  >";
  117.            mnumber = JOptionPane.showInputDialog(null, output, " ",
  118.                    JOptionPane.QUESTION_MESSAGE);
  119.            number=Integer.parseInt(mnumber);
  120.            return number;
  121.            
  122.              while(number!=4)
  123.              {
  124.                  int i;
  125.                 if(number==1)//Add member info and store it in arrays
  126.                             //count4,imember_code,imember_type,ifirst_name,ilast_name,iage,igender
  127.                  {
  128.                      String output1="";
  129.                      
  130.                      output1= "Enter Member Code";//RANDOMIZE?
  131.                      imember_code[count4]=JOptionPane.showInputDialog(null,output1," ",JOptionPane.QUESTION_MESSAGE);
  132.                      
  133.                      output1= "Enter Member Type (single, couple, or family)";
  134.                      imember_type[count4]=JOptionPane.showInputDialog(null,output1," ",JOptionPane.QUESTION_MESSAGE);
  135.                      
  136.                      output1= "Enter First Name";
  137.                      ifirst_name[count4]=JOptionPane.showInputDialog(null,output1," ",JOptionPane.QUESTION_MESSAGE);
  138.                      
  139.                      output1= "Enter Last Name";
  140.                      ilast_name[count4]=JOptionPane.showInputDialog(null,output1," ",JOptionPane.QUESTION_MESSAGE);
  141.                      
  142.                      output1= "Enter Age";
  143.                      iage[count4]=JOptionPane.showInputDialog(null,output1," ",JOptionPane.QUESTION_MESSAGE);
  144.                      
  145.                      output1= "Gender (Male or Female)";
  146.                      igender[count4]=JOptionPane.showInputDialog(null,output1," ",JOptionPane.QUESTION_MESSAGE);
  147.                      Object[] genderint;
  148.                      genderint[i]=Integer.parseInt(igender);
  149.                  }
  150.                    
  151.      
  152.                  else
  153.                      if(number==2)//Delete member info by searching for Member id
  154.                                 //search arrays and delete member
  155.                      {
  156.                          System.out.println("    Basic Class Info ");
  157.                          System.out.println("    =============");
  158.                          for(i=0;i<=count2;++i)
  159.                          {
  160.                                     System.out.println(iclass_code[i]+"  "+iclass_name[i]+"  "+ibeginning_date[i]);
  161.                          }
  162.                      }
  163.                  
  164.  
  165.                      else
  166.                          if(number==3)//Modify member info -
  167.                              //prompt user for the member code
  168.                              //search arrays for member code
  169.                              //prompt for a new member type
  170.                              //read in the new member type and store it in the proper array
  171.                          {
  172.                              System.out.println("       Basic Registration Info");
  173.                              System.out.println("       ===============");
  174.                              for(i=0;i<=count3;++i)
  175.                              {
  176.                                  System.out.println(iregister_member_code[i]+"  "+iregister_class_code[i]);
  177.  
  178.                              }   
  179.                          }
  180.                  
  181.                  output = "Member Modification Menu" + " \n " + " \n " +
  182.                           "1. Add Member" + " \n " +
  183.                           "2. Delete Member" + " \n " +
  184.                           "3. Modify Member Information" + " \n" + " \n " +
  185.                           "4. Exit Modification Menu" + " \n" + " \n " +    
  186.                           "Please make your selection  >";
  187.                            mnumber = JOptionPane.showInputDialog(null, output, " ",
  188.                                    JOptionPane.QUESTION_MESSAGE);
  189.                            number=Integer.parseInt(mnumber);
  190.              }//end of while loop  
  191.            
  192.            
  193.            
  194.                 }//Modify_member End
  195.            
  196.                
  197.             //Modify_registration Start
  198. void Modify_registration()
  199.                 {
  200.                 System.out.println("Modify_registration Method Executed"); 
  201.                 }//Modify_registration End
  202.                
  203.                
  204.             //Report Start
  205. void Report(int count1,int[]imember_code,String[]imember_type,String[]ifirst_name,String[]ilast_name,int[]iage,String[]igender,
  206.                         int count2,int[]iclass_code,String[]iclass_name,String[]ibeginning_date,
  207.                         int count3,int[]iregister_member_code,int[]iregister_class_code)
  208.                 {
  209.  
  210.     int selection,i;
  211.     String value;
  212.     String output="Moon Area YMCA"+"\n"+
  213.             "=================="+"\n"+
  214.             "1. Basic Member Information"+"\n"+
  215.             "2. Basic Class Information"+"\n"+
  216.             "3. Basic Registration Information"+"\n"+
  217.             "4. Report 4"+"\n"+
  218.             "5. Report 5"+"\n"+
  219.             "6. Report 6"+"\n"+
  220.             "7. Report 7"+"\n"+
  221.             "8. Report 8"+"\n"+
  222.             "9. Report 9"+"\n"+
  223.             "10. Exit Report Menu"+"\n"+
  224.             "Please make your selection > ";
  225.            
  226.              value =JOptionPane.showInputDialog(null,
  227.                         output,"Input Data",JOptionPane.QUESTION_MESSAGE);
  228.              selection=Integer.parseInt(value);
  229.              while(selection!=10)
  230.              {
  231.                  if(selection==1)
  232.                  {
  233.                      System.out.println("    Basic Member Info ");
  234.                      System.out.println("    =============");
  235.                      for(i=0;i<=count1;++i)
  236.                      {
  237.                                 System.out.println(imember_code[i]+"  "+imember_type[i]+"  "+ifirst_name[i]+"  "+
  238.                                        ilast_name[i]+"  "+iage[i]+"  "+igender[i]);
  239.                      }
  240.                  }
  241.                    
  242.      
  243.                  else
  244.                      if(selection==2)
  245.                      {
  246.                          System.out.println("    Basic Class Info ");
  247.                          System.out.println("    =============");
  248.                          for(i=0;i<=count2;++i)
  249.                          {
  250.                                     System.out.println(iclass_code[i]+"  "+iclass_name[i]+"  "+ibeginning_date[i]);
  251.                          }
  252.                      }
  253.                  
  254.  
  255.                      else
  256.                          if(selection==3)
  257.                          {
  258.                              System.out.println("       Basic Registration Info");
  259.                              System.out.println("       ===============");
  260.                              for(i=0;i<=count3;++i)
  261.                              {
  262.                                  System.out.println(iregister_member_code[i]+"  "+iregister_class_code[i]);
  263.  
  264.                              }   
  265.                          }
  266.                  
  267.                  output="Moon Area YMCA"+"\n"+
  268.                             "=================="+"\n"+
  269.                             "1. Basic Member Information"+"\n"+
  270.                             "2. Basic Class Information"+"\n"+
  271.                             "3. Basic Registration Information"+"\n"+
  272.                             "4. Report 4"+"\n"+
  273.                             "5. Report 5"+"\n"+
  274.                             "6. Report 6"+"\n"+
  275.                             "7. Report 7"+"\n"+
  276.                             "8. Report 8"+"\n"+
  277.                             "9. Report 9"+"\n"+
  278.                             "10. Exit Report Menu"+"\n"+
  279.                             "Please make your selection > ";
  280.                            
  281.                              value =JOptionPane.showInputDialog(null,
  282.                                         output,"Input Data",JOptionPane.QUESTION_MESSAGE);   
  283.                              selection=Integer.parseInt(value);
  284.              }//end of while loop  
  285.                 }//Report End
  286.                
  287.                
  288.             //Begin_read_member Start
  289. int Begin_read_member(int count1,int[]imember_code,String[]imember_type,
  290.                         String[]ifirst_name,String[]ilast_name,int[]iage,String[]igender)
  291.                 {
  292.                     String newLine;
  293.                     try
  294.                     {
  295.                        BufferedReader member_file = new BufferedReader(new FileReader("member.dat"));
  296.                        //read lines in file until there are no more lines in the file to read
  297.                        while ((newLine = member_file.readLine()) != null)
  298.                          {
  299.                            //there is a "#" between each data item in each line
  300.                             StringTokenizer delimiter = new StringTokenizer(newLine,"#");
  301.                             count1=count1+1;
  302.                             imember_code[count1] =Integer.parseInt(delimiter.nextToken());
  303.                             imember_type[count1] =delimiter.nextToken();
  304.                             ifirst_name[count1] =delimiter.nextToken();
  305.                             ilast_name[count1] =delimiter.nextToken();
  306.                             iage[count1] =Integer.parseInt(delimiter.nextToken());
  307.                             igender[count1] =delimiter.nextToken();
  308.                           }//while loop
  309.                          member_file.close();
  310.                       }//end try
  311.                       catch (IOException error)
  312.                     {
  313.                     //there was an error on the file writing
  314.                     System.out.println("Error on file read " + error);
  315.                     }//error on read
  316.                     return count1;
  317.                 }//Begin_read_member End
  318.                
  319.                
  320.             //Begin_read_class Start
  321. int Begin_read_class(int count2,int[]iclass_code,String[]iclass_name,
  322.                         String[]ibeginning_date)
  323.                 {
  324.                     String newLine;
  325.                     try
  326.                     {
  327.                        BufferedReader class_file = new BufferedReader(new FileReader("class.dat"));
  328.                        //read lines in file until there are no more lines in the file to read
  329.                        while ((newLine = class_file.readLine()) != null)
  330.                          {
  331.                            //there is a "#" between each data item in each line
  332.                             StringTokenizer delimiter = new StringTokenizer(newLine,"#");
  333.                             count2=count2+1;
  334.                             iclass_code[count2] =Integer.parseInt(delimiter.nextToken());
  335.                             iclass_name[count2] =delimiter.nextToken();
  336.                             ibeginning_date[count2] =delimiter.nextToken();
  337.                           }//while loop
  338.                          class_file.close();
  339.                       }//end try
  340.                       catch (IOException error)
  341.                     {
  342.                     //there was an error on the file writing
  343.                     System.out.println("Error on file read " + error);
  344.                     }//error on read
  345.                     return count2; 
  346.                 }//Begin_read_class End
  347.                
  348.                
  349.             //Begin_read_register Start
  350. int Begin_read_register(int count3,int[]iregister_member_code,int[]iregister_class_code)
  351.                 {
  352.                     String newLine;
  353.                     try
  354.                     {
  355.                        BufferedReader register_file = new BufferedReader(new FileReader("register.dat"));
  356.                        //read lines in file until there are no more lines in the file to read
  357.                        while ((newLine = register_file.readLine()) != null)
  358.                          {
  359.                            //there is a "#" between each data item in each line
  360.                             StringTokenizer delimiter = new StringTokenizer(newLine,"#");
  361.                             count3=count3+1;
  362.                             iregister_member_code[count3] =Integer.parseInt(delimiter.nextToken());
  363.                             iregister_class_code[count3] =Integer.parseInt(delimiter.nextToken());
  364.                           }//while loop
  365.                          register_file.close();
  366.                       }//end try
  367.                       catch (IOException error)
  368.                     {
  369.                     //there was an error on the file writing
  370.                     System.out.println("Error on file read " + error);
  371.                     }//error on read
  372.                     return count3;             
  373.                 }//Begin_read_register End
  374.                
  375.                
  376.             //Exit_ymca_program Start
  377. void Exit_ymca_program()
  378.                 {
  379.                 System.out.println("Exit_ymca_program Method Executed");   
  380.                 }//Exit_ymca_program End
  381.                
  382.  
  383. }//END moonymca CLASS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement