Untitled

 avatar
unknown
plain_text
4 years ago
9.5 kB
17
Indexable
package timetable;

public class stack {

    String[][] s = new String[7][6];
    array2d ar = new array2d();
    char[] boxC = new char[6];
    String []box = new String[6];
    instructor in = new instructor();

    int top = -1;
    int i;
   public void push(String x,char y)
   {
       if (top < box.length)
       {
           top++;
           box[top] = x;
           boxC[top] = y;
           temparr();
       }
       else 
           System.out.println("Is Full");
   }
   public void pop(String x,char y)
   {
       if (top != -1)
       {
           box[top] = null;
           boxC[top] = 0;
           top--;
        } 
       else 
           System.out.println("Is Empty");
   }
   public int z;
  public void Display()
   {
       
       instructor []x = new instructor[top];
       for (int i = 0; i <= x.length; i++)
       {
         System.out.println(" ["+ (i+1)+"] "+box[i]+"           "+boxC[i]);

         this.z=i;
       }
       
       
       }
   public String[][] s1 = new String[7][6];

     public void temparr(){
     
           ar.fillarray(s);
        s1 = s;
     }

   }



public class instructor{
    
    String name;
    int id;
    char gender;
   array2d a = new array2d();
   public String[][] s = new String[7][6];    
   public String[][] s1 = new String[7][6];    


    instructor(){};
    instructor(String name,int id,char gender){
    this.name = name;
    this.id = id;
    this.gender = gender;
    CreatTable();

    }
    public String getName(){
    return name;
    }

    public int getId(){
    return id;
    }
    
    public char getGender(){
    return gender;
    }
     public void SetName(String n){
     this.name = n;
    }
    public void SetId(int n){
     this.id = n;
    }
    public void SetGender(char n){
     this.gender = n;
    }
public void DisplayTable()
    {
        System.out.println("                    "+"["+getName()+" Table"+"]"); 
        a.printarray(a.s); 
        a.alterarray(a.s);
        
        System.out.println("                    "+"["+getName()+" Table"+"]"); 
        s = a.s;
        a.printarray(s); 

    }
public void cancle()
    {
        System.out.println("                    "+"["+getName()+" Table"+"]"); 
        a.printarray(a.s); 
        a.alterarraydelete(a.s);
        
        System.out.println("                    "+"["+getName()+" Table"+"]"); 
        s = a.s;
        a.printarray(s); 
    }
    public void DisplayTable(int x)
    {
        System.out.println("\n                    "+"["+getName()+" Table"+"]"); 
        a.printarray(a.s); 
    }
    public void clearit()
    {
        a.fillarray(s1);
    }
     public void CreatTable()
    {
       a.fillarray(a.s);
    }

    
}




public class array2d {
     Scanner sc = new Scanner(System.in);
     
    
     public String[][] s = new String[7][6];    
     
     
     public void alterarray(String[][] table){
     System.out.println("note, if a time is chosen then it has *, else if it's a - then its available ");
     System.out.println("chose the time to alter: ");
     int t= sc.nextInt();
     System.out.println("chose the day to alter: ");
     int d= sc.nextInt();
     for(int a=1;a<=6;a++){
         for(int b=1;b<=5;b++){
     if(t==a&&d==b){
           table[a][b]=" * ";
     }}}
     }
     public void alterarraydelete(String[][] table){
     System.out.println("note, if a time is chosen then it has *, else if it's a - then its available ");
     System.out.println("chose the time to alter: ");
     int t= sc.nextInt();
     System.out.println("chose the day to alter: ");
     int d= sc.nextInt();
     for(int a=1;a<=6;a++){
         for(int b=1;b<=5;b++){
     if(t==a&&d==b){
           table[a][b]=" - ";
     }}}
     }
     
     

     public void fillarray(String[][] table){
  
  for(int row=0 ; row<table.length; row++)
      for(int col=0 ;col<table[0].length; col++)
      {
      table[row][col]=" - ";
      
      table[0][0]="    ";
      
      table[0][1]="Mon 1";
      table[0][2]="Tues 2";
      table[0][3]="Wed 3";
      table[0][4]="Thur 4";
      table[0][5]="Fri 5";

      table[1][0]="7 - 8  [1]";
      table[2][0]="8 - 9  [2]";
      table[3][0]="9 - 10 [3]";
      table[4][0]="3 - 4  [4]";
      table[5][0]="4 - 5  [5]";
      table[6][0]="5 - 6  [6]";

      }
  
  }
     public void printarray(String[][] table)
     {
     for(int row=0 ; row<table.length; row++){
      for(int col=0 ;col<table[row].length; col++)
      {
    System.out.print(table[row][col]+ "        ");
      }
     System.out.println("    ");
     }
     
         }
     
    }





public class ProgrammingProject {




    Scanner W = new Scanner(System.in);
    instructor d = new instructor();
    instructor in = new instructor("ahmed",1,'m');
    instructor in1 = new instructor("karen",2,'f');
    instructor in2 = new instructor("faris",3,'m');
    instructor in3 = new instructor("asim",4,'m');
    instructor in4 = new instructor("raaed",5,'m');
    instructor in5 = new instructor("ayah",6,'f');

    stack st = new stack();
    public void prebook(){
     st.push(in.getName(),in.getGender());
     st.push(in1.getName(),in1.getGender());
     st.push(in2.getName(),in2.getGender());
     st.push(in3.getName(),in3.getGender());
     st.push(in4.getName(),in4.getGender());
     st.push(in5.getName(),in5.getGender());
    }
         int c=0;
    public  void book(){
     System.out.println("insert the instructor you want");
     if(c==0){
     prebook();
     }
     c++;
     st.Display();   
     int i = W.nextInt();
    System.out.println("\t \t - - - - - - - - - - - - - - - - -  ");
    if(i==1){
        in.DisplayTable();
    }else if(i==2){
        in1.DisplayTable();
    }else if(i==3){
        in2.DisplayTable();
    }else if(i==4){
        in3.DisplayTable();
    }else if(i==5){
        in4.DisplayTable();
    }else if(i==6){
        in5.DisplayTable();
    }
    else{
    System.out.println("That Was a Wrong input.");
    }
    System.out.println("insert 0 to get back to Menu, Or 1 to book another Swiming Session, or 9 to get out.");
         int i1 = W.nextInt();
    if(i1==0){
            DisplayMenu();
    }if(i1==9){
           Exit();
    }if(i1==1){
           book();
     System.out.println(" ");
    }}
    public  void Cancel(){
     System.out.println("insert the instructor you want");
    if(c==0){
     prebook();
     }
     c++;
     st.Display();   
     int s = W.nextInt();
    System.out.println("\t \t - - - - - - - - - - - - - - - - -  ");
    if(s==1){
        in.cancle();
    }else if(s==2){
        in1.cancle();
    }else if(s==3){
        in2.cancle();
    }else if(s==4){
        in3.cancle();
    }else if(s==5){
        in4.cancle();
    }else if(s==6){
        in5.cancle();
    }
     else{
    System.out.println("That Was a Wrong input.");
    }
    if(s==0){
    }
    System.out.println("insert 0 to get back to Menu, Or 1 to Cancel another Swiming Session or 9 to get out.");
         int i1 = W.nextInt();
    if(i1==0){
            DisplayMenu();
    }if(i1==9){
           Exit();
                 System.out.println(" ");
    }if(i1==1){
           Cancel();
    }
    }
    public void Displayall(){
            in.DisplayTable(1);
            in1.DisplayTable(1);
            in2.DisplayTable(1);
            in3.DisplayTable(1);
            in4.DisplayTable(1);
            in5.DisplayTable(1);
    System.out.println("insert 0 to get back or 9 to get out.");
 int i1 = W.nextInt();
    if(i1==0){
            DisplayMenu();
    }if(i1==9){
           Exit();
    } 
    }
    public boolean run;
    public static void main(String[] args)
    {
       
     ProgrammingProject r = new ProgrammingProject();
     r.run = true;
     if(r.run == true)
     {
         r.DisplayMenu();
     }

    } 

    public void DisplayMenu()
    {
        System.out.println("__");
        System.out.println("              Main Menu                                  ");
        System.out.println(" [1] Booking a Swimming Lesson");
        System.out.println(" [2] Cancel a Swimming Lesson");
        System.out.println(" [3] Display current schedule of instructors ");
        System.out.println(" [4] Clear All Schedules");
        System.out.println(" [5] Exit");
        System.out.print(" : ");
       int x = W.nextInt();
       if (x == 1)
       {
        
         book();
         int z=1;
         this.c=z;
       }
      
       else if (x == 2)
       {
        Cancel();
       }
       else if (x == 3)
       {
Displayall();
       }
      else  if (x == 4)
       {
       Clear();
       }
       else if (x == 5)
       {
           Exit();
       }
     }
    
    
    public void Clear()
    {
        in.clearit();
        in1.clearit();
        in2.clearit();
        in3.clearit();
        in4.clearit();
        in5.clearit();
            DisplayMenu();
       
    }
    public void Exit()
    {
                 System.out.println("have a fun Swim! :)");
                 System.out.println(" ");
    }

    }
    

Editor is loading...