From b547e6bfd4ee53c853f912808a217f16da940fc3 Mon Sep 17 00:00:00 2001 From: vedanthvdev <61700595+vedanthvdev@users.noreply.github.com> Date: Thu, 30 Jul 2020 12:47:52 +0100 Subject: [PATCH 1/6] Adjusted the output statement --- ElevatorAlgorithm/Program.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ElevatorAlgorithm/Program.cs b/ElevatorAlgorithm/Program.cs index fcc1222..0720e80 100644 --- a/ElevatorAlgorithm/Program.cs +++ b/ElevatorAlgorithm/Program.cs @@ -221,7 +221,7 @@ static void Main(string[] args) change = elevator[k]; z = k + 1; elevator[k].setIsIdle(1); - Console.WriteLine("Elevator " + z + " is selected and idle is set to " + elevator[k].getIsIdle()); + Console.WriteLine("\nElevator " + z + " is selected\n"); goto LoopEnd; } @@ -317,7 +317,7 @@ static void Main(string[] args) { elevator[k] = change; elevator[k].setIsIdle(-1); - Console.WriteLine("Elevator " + z + " has ended its action and idle is set to " + elevator[k].getIsIdle()); + Console.WriteLine("\nElevator " + z + " has ended its action and is idle now \n"); break; } From 10134e82a97ebfce9df2f2d2f9e19ac5898af04a Mon Sep 17 00:00:00 2001 From: vedanthvdev <61700595+vedanthvdev@users.noreply.github.com> Date: Thu, 30 Jul 2020 12:56:41 +0100 Subject: [PATCH 2/6] Created Seperate Class for elevator --- ElevatorAlgorithm/Class1.cs | 10 --- ElevatorAlgorithm/Elevator.cs | 144 ++++++++++++++++++++++++++++++++++ ElevatorAlgorithm/Program.cs | 134 +------------------------------ 3 files changed, 145 insertions(+), 143 deletions(-) delete mode 100644 ElevatorAlgorithm/Class1.cs create mode 100644 ElevatorAlgorithm/Elevator.cs diff --git a/ElevatorAlgorithm/Class1.cs b/ElevatorAlgorithm/Class1.cs deleted file mode 100644 index 89bbe27..0000000 --- a/ElevatorAlgorithm/Class1.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace ElevatorAlgorithm -{ - class Class1 - { - } -} diff --git a/ElevatorAlgorithm/Elevator.cs b/ElevatorAlgorithm/Elevator.cs new file mode 100644 index 0000000..e0098a7 --- /dev/null +++ b/ElevatorAlgorithm/Elevator.cs @@ -0,0 +1,144 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ElevatorAlgorithm + +{ + public class Elevator : ElevatorInterface + { + private int minFloor; + private int maxFloor; + private int maxCapacity; + private int currentFloor; + private int people; + private int sum; + private int isIdle; + + + public int getSum() + { + return sum; + } + + public void setSum(int sum) + { + this.sum += sum; + } + + public int getPeople() + { + return people; + } + + public int setPeople(int people, int z) + { + this.people += people; + Console.Out.WriteLine("\nNUMBER OF PEOPLE ON ELEVATOR " + z + " NOW...>" + getSum() + "\n"); + Console.Out.WriteLine("***************MOVING TO NEXT FLOOR***************\n"); + return people; + } + + public Elevator(int minFloor, int maxFloor, int maxCapacity) + { + this.minFloor = minFloor; + this.maxFloor = maxFloor; + this.maxCapacity = maxCapacity; + + currentFloor = minFloor; + } + + public int getMinFloor() + { + return minFloor; + } + + public int getMaxFloor() + { + return maxFloor; + } + + public int getMaxCapacity() + { + return maxCapacity; + } + + public int getCurrentFloor() + { + return currentFloor; + } + + public void moveNext(int floor, int z) + { + + while (floor != currentFloor) + { + if (currentFloor < floor) + { + moveUp(z); + } + else if (currentFloor > floor) + { + moveDown(z); + } + } + + if (currentFloor == floor) + { + Console.Out.WriteLine("\nELEVATOR " + z + " HAS ARRIVED AT FLOOR----> " + currentFloor); + + } + } + + public void moveUp(int z) + { + + currentFloor++; + Console.Out.WriteLine("Elevator " + z + " moved up one level to : " + currentFloor + " And carrying " + + getPeople() + " people"); + + } + + public void moveDown(int z) + { + + currentFloor--; + Console.Out.WriteLine("Elevator " + z + " moved down one level to : " + currentFloor + " And carrying " + + getPeople() + " people"); + + + } + + public int getIsIdle() + { + return isIdle; + } + + public int setIsIdle(int a) + { + this.isIdle += a; + return isIdle; + } + } + + + public interface ElevatorInterface + { + int getMinFloor(); + int getMaxFloor(); + int getMaxCapacity(); + int getCurrentFloor(); + int getPeople(); + int setPeople(int people, int z); + int getSum(); + void setSum(int sum); + void moveUp(int z); + void moveDown(int z); + void moveNext(int floor, int z); + int getIsIdle(); + int setIsIdle(int a); + + } + + +} diff --git a/ElevatorAlgorithm/Program.cs b/ElevatorAlgorithm/Program.cs index 0720e80..cc8df17 100644 --- a/ElevatorAlgorithm/Program.cs +++ b/ElevatorAlgorithm/Program.cs @@ -1,142 +1,10 @@ using System; using System.ComponentModel.Design; +using System.Threading; namespace ElevatorAlgorithm { - public interface ElevatorInterface - { - int getMinFloor(); - int getMaxFloor(); - int getMaxCapacity(); - int getCurrentFloor(); - int getPeople(); - int setPeople(int people, int z); - int getSum(); - void setSum(int sum); - void moveUp(int z); - void moveDown(int z); - void moveNext(int floor, int z); - int getIsIdle(); - int setIsIdle(int a); - - } - - public class Elevator : ElevatorInterface - { - private int minFloor; - private int maxFloor; - private int maxCapacity; - private int currentFloor; - private int people; - private int sum; - private int isIdle; - - public int getSum() - { - return sum; - } - - public void setSum(int sum) - { - this.sum += sum; - } - - public int getPeople() - { - return people; - } - - public int setPeople(int people, int z) - { - this.people += people; - Console.Out.WriteLine("\nNUMBER OF PEOPLE ON ELEVATOR " + z + " NOW...>" + getSum() + "\n"); - Console.Out.WriteLine("***************MOVING TO NEXT FLOOR***************\n"); - return people; - } - - public Elevator(int minFloor, int maxFloor, int maxCapacity) - { - this.minFloor = minFloor; - this.maxFloor = maxFloor; - this.maxCapacity = maxCapacity; - - currentFloor = minFloor; - } - - public int getMinFloor() - { - return minFloor; - } - - public int getMaxFloor() - { - return maxFloor; - } - - public int getMaxCapacity() - { - return maxCapacity; - } - - public int getCurrentFloor() - { - return currentFloor; - } - - public void moveNext(int floor, int z) - { - - while (floor != currentFloor) - { - if (currentFloor < floor) - { - moveUp(z); - } - else if (currentFloor > floor) - { - moveDown(z); - } - } - - if (currentFloor == floor) - { - Console.Out.WriteLine("\nELEVATOR " + z + " HAS ARRIVED AT FLOOR----> " + currentFloor); - - } - } - - public void moveUp(int z) - { - - currentFloor++; - Console.Out.WriteLine("Elevator " + z + " moved up one level to : " + currentFloor + " And carrying " - + getPeople() + " people"); - - } - - public void moveDown(int z) - { - - currentFloor--; - Console.Out.WriteLine("Elevator " + z + " moved down one level to : " + currentFloor + " And carrying " - + getPeople() + " people"); - - - } - - public int getIsIdle() - { - return isIdle; - } - - public int setIsIdle(int a) - { - this.isIdle += a; - return isIdle; - } - } - class Program { static void Main(string[] args) From d036c33be60549a2dced0ff22efc043334331435 Mon Sep 17 00:00:00 2001 From: vedanthvdev <61700595+vedanthvdev@users.noreply.github.com> Date: Thu, 30 Jul 2020 13:09:31 +0100 Subject: [PATCH 3/6] Comments --- .../{Program.cs => StartMain.cs} | 44 +++++++++++-------- 1 file changed, 26 insertions(+), 18 deletions(-) rename ElevatorAlgorithm/{Program.cs => StartMain.cs} (79%) diff --git a/ElevatorAlgorithm/Program.cs b/ElevatorAlgorithm/StartMain.cs similarity index 79% rename from ElevatorAlgorithm/Program.cs rename to ElevatorAlgorithm/StartMain.cs index cc8df17..452c652 100644 --- a/ElevatorAlgorithm/Program.cs +++ b/ElevatorAlgorithm/StartMain.cs @@ -5,29 +5,33 @@ namespace ElevatorAlgorithm { -class Program +class StartMain { static void Main(string[] args) { - int numOfElevators = 4; // Setting Number of Elevators in Building + int numOfElevators = 4; int minFloor = 0; int maxFloor = 10; int maxCapacity = 5; Elevator[] elevator = new Elevator[numOfElevators]; + // Assigning Lowest Floor + //Highest Floor + //Maximun Capacity for (int i = 0; i < numOfElevators; i++) - { // Assigning MinFloors, MaxFloors and MaxCapacity + { elevator[i] = new Elevator(minFloor, maxFloor, maxCapacity); } - Elevator change = null; // Temporary Object + //Temporary Elevator Object + Elevator change = null; while (true) { - // Elevators Status + //Every Elevator Status for (int j = 0; j < elevator.Length; j++) { Console.Out.WriteLine("\nElevator " + (j + 1) + " is at Floor----> " + elevator[j].getCurrentFloor() @@ -38,7 +42,8 @@ static void Main(string[] args) Console.Out.WriteLine("\nHow many floors are being called "); - int numFloors = Int32.Parse(Console.ReadLine()); // Checking if the user wants Multiple floors call + // Checking if the user wants Multiple floors call + int numFloors = Int32.Parse(Console.ReadLine()); int[] floor = new int[numFloors]; int[] people = new int[numFloors]; @@ -47,7 +52,7 @@ static void Main(string[] args) for (int i = 0; i < numFloors; i++) { - // Selecting the floor where people are waiting + //User selection of desired floor where people are waiting while (true) { Console.Out.WriteLine("Please enter the NEXT FLOOR NUMBER where people are waiting..(" @@ -66,7 +71,7 @@ static void Main(string[] args) } - // Choosing the BEST ELEVATOR for that location + // Optimizing the BEST ELEVATOR for that location selected by the user int[] unsorted = new int[elevator.Length]; int[] sorted = new int[elevator.Length]; @@ -80,13 +85,13 @@ static void Main(string[] args) for (int j = 0; j < sorted.Length; j++) { - for (int k = 0; k < elevator.Length; k++) + for (int k = 0; k < unsorted.Length; k++) { { if (elevator[k].getIsIdle() == 0 && sorted[j] == unsorted[k]) { - change = elevator[k]; + change = elevator[k]; //Selecting the desired elevator into temp z = k + 1; elevator[k].setIsIdle(1); Console.WriteLine("\nElevator " + z + " is selected\n"); @@ -97,8 +102,8 @@ static void Main(string[] args) } } LoopEnd: - //sfs - // Acknowledging the number of people waiting for the elevator on selected floor + + // Registering the User input of amount of users waiting for on desired floor while (true) { Console.Out.WriteLine("Enter the NUMBER OF PEOPLE waiting at level " + floor[i] + "----->MAXIMUM " @@ -126,13 +131,16 @@ static void Main(string[] args) } - change.moveNext(floor[i], z); // Moving to the selected floor - change.setPeople(people[i], z); // Defining the number of people present on the elevator + // Moving to the selected floor Step by Step + change.moveNext(floor[i], z); - // checking if the elevator still has people on it - while (change.getSum() != 0) + // Setting the number of people on the elevator and the elevator selected + change.setPeople(people[i], z); + + //Keeps looping until the people on the elevator is 0 + while (change.getSum() != 0) { - // selecting the floor to Unload + // selecting the floor where people want to get down while (true) { Console.Out.WriteLine("Please enter your DESTINATION FLOOR(" + elevator[1].getMinFloor() + " to " @@ -150,7 +158,7 @@ static void Main(string[] args) } } - // Unloading the elevator + // Registering the number of people getting down at that floor while (true) { Console.Out.WriteLine("Enter the NUMBER OF PEOPLE getting down at " + floor[i]); From 575761756e1edb9c5d1330031ad5ff0141138694 Mon Sep 17 00:00:00 2001 From: vedanthvdev <61700595+vedanthvdev@users.noreply.github.com> Date: Thu, 30 Jul 2020 14:24:24 +0100 Subject: [PATCH 4/6] Set the default variable to be taken from an external text file --- ElevatorAlgorithm/StartMain.cs | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/ElevatorAlgorithm/StartMain.cs b/ElevatorAlgorithm/StartMain.cs index 452c652..2d5b75d 100644 --- a/ElevatorAlgorithm/StartMain.cs +++ b/ElevatorAlgorithm/StartMain.cs @@ -1,6 +1,10 @@ using System; using System.ComponentModel.Design; using System.Threading; +using System.IO; +using System.Collections.Generic; +using System.Linq; +using Microsoft.VisualBasic.CompilerServices; namespace ElevatorAlgorithm { @@ -9,19 +13,33 @@ class StartMain { static void Main(string[] args) { + //Assigning all default values like minFloor,maxFloor,maxCapacity and number of elevators from a text file + List termsList = new List(); - int numOfElevators = 4; - int minFloor = 0; - int maxFloor = 10; - int maxCapacity = 5; - Elevator[] elevator = new Elevator[numOfElevators]; + String filepath = @"C:\Users\Chint\Desktop\Admin.txt"; + List lines = File.ReadAllLines(filepath).ToList(); + + foreach(var line in lines){ + + string[] entries = line.Split('='); + + termsList.Add(Int32.Parse(entries[1])); + + } + + //numOfElevators = termsList[0]; + //minFloor = termsList[1]; + //maxFloor = termsList[2]; + //maxCapacity = termsList[3]; + + Elevator[] elevator = new Elevator[termsList[0]]; // Assigning Lowest Floor //Highest Floor //Maximun Capacity - for (int i = 0; i < numOfElevators; i++) + for (int i = 0; i < termsList[0]; i++) { - elevator[i] = new Elevator(minFloor, maxFloor, maxCapacity); + elevator[i] = new Elevator(termsList[1], termsList[2], termsList[3]); } From b47779f356e222d9779effd6d0ed480143eb23df Mon Sep 17 00:00:00 2001 From: vedanthvdev <61700595+vedanthvdev@users.noreply.github.com> Date: Thu, 30 Jul 2020 16:14:45 +0100 Subject: [PATCH 5/6] Color coding the Consoleout messages --- ElevatorAlgorithm/Elevator.cs | 9 +++++++-- ElevatorAlgorithm/StartMain.cs | 24 ++++++++++++++++++++---- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/ElevatorAlgorithm/Elevator.cs b/ElevatorAlgorithm/Elevator.cs index e0098a7..efacfad 100644 --- a/ElevatorAlgorithm/Elevator.cs +++ b/ElevatorAlgorithm/Elevator.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Text; +using System.Threading; namespace ElevatorAlgorithm @@ -94,8 +95,11 @@ public void moveUp(int z) { currentFloor++; + Console.ForegroundColor = ConsoleColor.DarkBlue; Console.Out.WriteLine("Elevator " + z + " moved up one level to : " + currentFloor + " And carrying " + getPeople() + " people"); + Console.ForegroundColor = ConsoleColor.White; + Thread.Sleep(500); } @@ -103,10 +107,11 @@ public void moveDown(int z) { currentFloor--; + Console.ForegroundColor = ConsoleColor.DarkGreen; Console.Out.WriteLine("Elevator " + z + " moved down one level to : " + currentFloor + " And carrying " + getPeople() + " people"); - - + Console.ForegroundColor = ConsoleColor.White; + Thread.Sleep(500); } public int getIsIdle() diff --git a/ElevatorAlgorithm/StartMain.cs b/ElevatorAlgorithm/StartMain.cs index 2d5b75d..b8ab158 100644 --- a/ElevatorAlgorithm/StartMain.cs +++ b/ElevatorAlgorithm/StartMain.cs @@ -26,7 +26,7 @@ static void Main(string[] args) termsList.Add(Int32.Parse(entries[1])); } - + //numOfElevators = termsList[0]; //minFloor = termsList[1]; //maxFloor = termsList[2]; @@ -52,8 +52,10 @@ static void Main(string[] args) //Every Elevator Status for (int j = 0; j < elevator.Length; j++) { + Console.ForegroundColor = ConsoleColor.Cyan; Console.Out.WriteLine("\nElevator " + (j + 1) + " is at Floor----> " + elevator[j].getCurrentFloor() + "\t Number of people on it.....>" + elevator[j].getSum()); + Console.ForegroundColor = ConsoleColor.White; } Console.Out.WriteLine("----------------++++++++-----------------"); @@ -80,7 +82,9 @@ static void Main(string[] args) if (floor[i] < elevator[1].getMinFloor() || floor[i] > elevator[1].getMaxFloor()) { - Console.Out.WriteLine("Enter valid floor"); + Console.ForegroundColor = ConsoleColor.DarkRed; //Color Coding for Error Message + Console.Out.WriteLine("FLOOR NUMBER INVALID"); + Console.ForegroundColor = ConsoleColor.White; } else { @@ -112,7 +116,9 @@ static void Main(string[] args) change = elevator[k]; //Selecting the desired elevator into temp z = k + 1; elevator[k].setIsIdle(1); + Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("\nElevator " + z + " is selected\n"); + Console.ForegroundColor = ConsoleColor.White; goto LoopEnd; } @@ -137,13 +143,17 @@ static void Main(string[] args) else if (change.getSum() <= 0) { change.setSum(-people[i]); + Console.ForegroundColor = ConsoleColor.DarkRed; Console.Out.WriteLine("PLEASE ENTER A POSITIVE INTEGER"); + Console.ForegroundColor = ConsoleColor.White; } else { change.setSum(-people[i]); - Console.Out.WriteLine("SORRY WEIGHT LIMIT OF ELEVATOR " + z + " EXEEDED...\n" + Console.ForegroundColor = ConsoleColor.DarkRed; + Console.Out.WriteLine("SORRY WEIGHT LIMIT OF ELEVATOR " + z + " EXEEDED...\nOnly " + (change.getMaxCapacity() - change.getSum()) + " CAN COME ON THIS FLOOR "); + Console.ForegroundColor = ConsoleColor.White; } @@ -168,7 +178,9 @@ static void Main(string[] args) if (floor[i] < elevator[1].getMinFloor() || floor[i] > elevator[1].getMaxFloor()) { - Console.Out.WriteLine("Enter valid floor"); + Console.ForegroundColor = ConsoleColor.DarkRed; + Console.Out.WriteLine("FLOOR NUMBER INVALID"); + Console.ForegroundColor = ConsoleColor.White; } else { @@ -184,12 +196,16 @@ static void Main(string[] args) people[i] = Int32.Parse(Console.ReadLine()); if (change.getSum() < people[i]) { + Console.ForegroundColor = ConsoleColor.DarkRed; Console.Out.WriteLine( "Sorry there are only " + change.getSum() + " people left on elevator " + z); + Console.ForegroundColor = ConsoleColor.White; } else if (people[i] < 0) { + Console.ForegroundColor = ConsoleColor.DarkRed; Console.Out.WriteLine("Please enter a positive integer..."); + Console.ForegroundColor = ConsoleColor.White; } else { From 2d3eed00dc8136e51b1f774b0e2fed3fc77ecc55 Mon Sep 17 00:00:00 2001 From: vedanthvdev <61700595+vedanthvdev@users.noreply.github.com> Date: Thu, 30 Jul 2020 17:13:29 +0100 Subject: [PATCH 6/6] comments --- ElevatorAlgorithm/StartMain.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/ElevatorAlgorithm/StartMain.cs b/ElevatorAlgorithm/StartMain.cs index b8ab158..003ca6c 100644 --- a/ElevatorAlgorithm/StartMain.cs +++ b/ElevatorAlgorithm/StartMain.cs @@ -1,6 +1,4 @@ using System; -using System.ComponentModel.Design; -using System.Threading; using System.IO; using System.Collections.Generic; using System.Linq;