import java.util.Scanner;
import java.util.Objects;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

class EmployeeDriverSystem
{  
    public static void main(String args[]) throws IOException
    {  
     	//System.out.println("Hello Java");
    	Employee[] a = new Employee[10];
    	int count;
        // If file handling not needed, uncomment the codes from Line 15-24. 
    	a[0] = new PermanentEmployee("Maninder", "Singh", "30312306"); // to be replaced by the university's student
    	a[1] = new PermanentEmployee("Peter", "VAMPLEW", "VAM12345678");
    	a[2] = new PermanentEmployee("Rudi", "SKACEL", "SKA51515151", 56.7);
    	a[3] = new CasualEmployee("Katie","BLACKBURN","BLA41925612");
    	a[4] = new CasualEmployee("Neal","STEPHENSON","STE97527467",12.5);
    	a[5] = new CasualEmployee("Neneh","CHERRY","CHE98765432",9.4);
    	a[6] = new CasualEmployee("Chris","BROOKMYRE","BRO97635198");
    	a[7] = new CasualEmployee("Grace","HOPPER","HOP26554432",3.4);
    	a[8] = new CasualEmployee("Randall","MUNROE","XKCD1234567");
    	a[9] = new CasualEmployee("Kaylee","FRYE","FRY90224718");

        //Needs a file named file.txt in the same folder as the code. If file handling not needed, comment
        // code from Line 28-41.
        /*BufferedReader reader = new BufferedReader(new FileReader("employeedata.txt"));
        for(int i = 0; i < 3; i++)
        {
            String line = reader.readLine();
            String[] parts = line.split(" ");
            a[i] = new PermanentEmployee(parts[0], parts[1], parts[2]);
        }
        for(int i = 3; i < 10; i++)
        {
            String line = reader.readLine();
            String[] parts = line.split(" ");
            a[i] = new CasualEmployee(parts[0], parts[1], parts[2]);
        }
        reader.close();*/
    	Employee[][] b = new Employee [5][4];  
    	int flag = 0;
    	int n,n2,n3,n4;
    	while (true)
    	{
    		if (flag == 0)
    		{
    			System.out.println("1. Display all staff");
    			System.out.println("2. Clear schedule");
    			System.out.println("3. Display schedule");
    			System.out.println("4. Assign shift to casual employee");
    			System.out.println("5. Assign shifts to permanent employee");
    			System.out.println("6. Calculate total weekly wages");
    			System.out.println("7. Exit Program");
    			while (true)
    			{
    				System.out.println("Enter your selection");
    				//n = Integer.parseInt(System.console().readLine());
    				Scanner in = new Scanner(System.in);
					n = in.nextInt();

				//	n = in.nextInt();  
					 
					
				//	n = in.nextInt();
    				if (n <= 0 || n > 7)
    				{	
    					System.out.println("Invalid Selection - must be between 1 and 7.");
                        break;
    				}
    				if (n == 1)
    				{
    					int i = 0;
    					for (i = 0; i < 10; i++)
    					{
    						String x = a[i].toString();
    						System.out.println(x);
    					}
    					break;
    				}	
    				else if (n == 2) 
    				{
    					int i = 0;
    					int j = 0;
    					for (i = 0; i < 10; i++)
    					{
    						a[i].shiftsWorkedThisWeek = 0;
    					}
    					for (i = 0; i < 5; i++ )
    					{
    						for (j = 0; j < 4; j++ )
    						{
    							b[i][j] = null;
    						}
    					}
    					break;
    				}
    				else if (n == 3)
    				{
    					int i,j;
    					for (i = 0; i < 5; i++)
    					{
    						if (i == 0)
    							System.out.print("MON\t");
    						else if (i == 1)
    							System.out.print("TUE\t");
    						else if (i == 2)
    							System.out.print("WED\t");
    						else if (i == 3)
    							System.out.print("THU\t");
    						else if (i == 4)
    							System.out.print("FRI\t");
    						for (j = 0; j < 4; j++)
    						{
    							if (b[i][j] == null)
    							{
    								System.out.print("------------------------\t");
    							}
    							else
    							{
    								System.out.print(b[i][j].toString());
    								System.out.print("\t");
    							}
    						}
    						System.out.print("\n");
    					}
    					break;
    				}
    				else if (n == 4)
    				{
    					while (true)
    					{
    						System.out.println("Which shift do you wish to allocate to a casual employee? (1..4):");
    						n2 = Integer.parseInt(System.console().readLine());
    						if (n2 < 1 || n2 > 4)
    						{
    							System.out.println("Invalid selection - must be between 1 and 4.");
    						}
    						else
    							break;
    					}
    					while (true)
    					{
    						System.out.println("On which day? (1..5):");
    						n3 = Integer.parseInt(System.console().readLine());
    						if (n3 < 1 || n3 > 5)
    						{
    							System.out.println("Invalid selection - must be between 1 and 5.");
    						}
    						else
    							break;
    					}
    					if (b[n3-1][n2-1] != null)
    					{
    						System.out.println("This shift has already been allocated");
    						break;
    					}
    					else
    					{
    						int i;
    						for (i = 0; i < 10; i++)
    						{
    							if (a[i] instanceof CasualEmployee == true)
    							{
    								String v = a[i].toString();
    								System.out.println(v);
    							}
    						}
    						int flag2 = 0;
    						while (true)
    						{
    							System.out.println("Enter ID");
    							Scanner input = new Scanner(System.in);
    							String y = input.nextLine();
    							for (i = 0; i < 10; i++)
    							{
    								if (Objects.equals(y, a[i].ID) == true)
    								{
    									flag2 = 1;
    								}
    								if (flag2 == 1)
    									break;
    							}
    							if (flag2 == 1)
    								break;
    							else
    							{
    								System.out.println("Invalid selection - try again.");
    							}
    						}
    						b[n3-1][n2-1] = a[i];
    						a[i].incrementShiftsWorkedThisWeek();
    					}
    					break;
    				}
    				else if (n == 5)
    				{
    					while (true)
    					{
    						System.out.println("Which shift do you wish to allocate to a permanent employee? (1..4):");
    						n4 = Integer.parseInt(System.console().readLine());
    						if (n4 < 1 || n4 > 4)
    						{
    							System.out.println("Invalid selection - must be between 1 and 4.");
    						}
    						else
    							break;
    					}
    					int flag3 = 0;
    					int i;
    					for (i = 0; i < 5; i++)
    					{
    						if (b[i][n4] != null)
    						{
    							System.out.println("This shift is already allocated\n");
    							flag3 = 1;
    							break;
    						}
    					}
    					if (flag3 == 0)
    					{
    						
    						for (i = 0; i < 10; i++)
    						{
    							if (a[i] instanceof PermanentEmployee == true)
    							{
    								String v = a[i].toString();
    								System.out.println(v);
    							}
    						}
    						int flag4 = 0;
    						while (true)
    						{
    							System.out.println("Enter ID");
    							Scanner input = new Scanner(System.in);
    							String y = input.nextLine();
    							for (i = 0; i < 10; i++)
    							{
    								if (Objects.equals(y, a[i].ID) == true)
    								{
    									flag4 = 1;
    								}
    								if (flag4 == 1)
    									break;
    							}
    							if (flag4 == 1)
    								break;
    							else
    							{
    								System.out.println("Invalid selection - try again.");
    							}
    						}
    						int j;
    						for (j = 0; j < 5; j++)
    						{
    							b[j][n4-1] = a[i];
    						}
    						a[i].shiftsWorkedThisWeek = a[i].shiftsWorkedThisWeek + 5;
    					}
    					break;
    				}
    				else if ( n == 6 )
    				{
    					int i;
    					double total = 0;
    					for ( i = 0; i < 10; i++ )
    					{
    						System.out.print(a[i].toString());
    						System.out.print("     ");
    						double var = a[i].calculateWeeklyPay();
    						System.out.print(var);
    						total = total + var;
    						System.out.print("\n");
    					}
    					System.out.println("-----------------------------------------");
    					System.out.print("TOTAL WAGES FOR THIS WEEK:  ");
    					System.out.println(total);
    					break;
    				} 
    				else if (n == 7)
    				{
    					flag = 1;
    					break;
    				}
    			}
    		}
    		else
    			break;
    	} 
    } 
	public abstract static class Employee
	{
		String firstName;
		String lastName;
		String ID;
		int shiftsWorkedThisWeek;
		Employee(String a, String b, String c)
		{
			firstName = a;
			lastName = b;
			ID = c;
		}
		public String getFirstName()
		{
			return firstName;
		}
		public String getLastName()
		{
			return lastName;
		}
		public String getID()
		{
			return ID;
		}
		public int getShiftsWorkedThisWeek()
		{
			return shiftsWorkedThisWeek;
		}
		public void resetShiftsWorkedThisWeek()
		{
			shiftsWorkedThisWeek = 0;
		}
		public void incrementShiftsWorkedThisWeek()
		{
			shiftsWorkedThisWeek = shiftsWorkedThisWeek + 1;
		}
		public abstract double calculateWeeklyPay();
		public String toString()
		{
			String a1 = "[" + ID + "]";
			String a2 = a1 + " ";
			String a3 = lastName + ",";
			String a4 = a3 + " ";
			String a5 = firstName;
			String a6 = a2 + a4 + a5;
			return a6;
		}
	}

	public static class PermanentEmployee extends Employee
	{
		double weeklyWage;
		PermanentEmployee(String a1, String a2, String a3)
		{
			super(a1,a2,a3);
			weeklyWage = 812.47;
		}
		PermanentEmployee(String a1, String a2, String a3, double a4)
		{
			super(a1,a2,a3);
			weeklyWage = a4;
		}
		public void setWeeklyWage(double a1)
		{
			weeklyWage = a1;
		}
		public double getWeeklyWage()
		{
			return weeklyWage;
		}
		public double calculateWeeklyPay()
		{
			return weeklyWage;
		}
	}

	public static class CasualEmployee extends Employee
	{
		double shiftRate;
		CasualEmployee(String a1, String a2, String a3)
		{
			super(a1,a2,a3);
			shiftRate = 47.5;
		}
		CasualEmployee(String a1, String a2, String a3, double a4)
		{
			super(a1,a2,a3);
			shiftRate = a4;
		}
		public void setShiftRate(double a1)
		{
			shiftRate = a1;
		}
		public double getShiftRate (double a2)
		{
			return shiftRate;
		}
		public double calculateWeeklyPay() 
		{
			double a1 = shiftRate*shiftsWorkedThisWeek;
			return a1;
		}
	}
}


