public Bay[] Test() { ArrayList LList = ListOfLoads.getLL(); Bay[] BL = ListOfBays.getBL(); if (LList == null) { Console.WriteLine("List is empty"); } for (int i = 1; i < LList.Count; i++) { Load prevLoad = (Load)LList[0]; String prevLoadBayName = prevLoad.Bay;; for (int g = i; g < LList.Count; g++) { Load curLoad = ((Load)LList[g]); if (!(prevLoadBayName).Equals((curLoad).Bay) && (curLoad.Added = false)) { int h = 0; while (!(BL[h].Name).Equals(prevLoadBayName)) { h++; } Bay curBay = (Bay)BL[h]; curBay.loadsInBAy.Add(curLoad); curLoad.Added = true; } } } return(BL); }
private void Swap(int a, int b, Bay[] List1) { Bay temp = List1[a]; List1[a] = List1[b]; List1[b] = temp; }
public void displayBays() { if (ListOfBays == null) { Console.WriteLine("list of bays is empty"); return; } for (int i = 0; i < ListOfBays.Length; i++) { Bay curbay = ListOfBays[i]; curbay.displayBay(curbay); } }
private void PopulateBays() { StreamReader Text = new StreamReader("BayArea.txt"); int i = 0; while (!Text.EndOfStream) { string Item = Text.ReadLine(); string[] data = Item.Split(','); string Name = data[0]; double Capacity = double.Parse(data[1]); ListOfBays[i] = new Bay(Name, Capacity); i++; } Text.Close(); }
public void RemoveLoad() { for (int i = 0; i < ListOfBays.Count(); i++) { Bay curbay = ListOfBays[i]; Console.WriteLine("{0}: {1}", i + 1, curbay.Name); } Console.WriteLine("Select the number of the bay from which you want to remove a load"); int Num = int.Parse(Console.ReadLine()); Bay CB = ListOfBays[Num - 1]; Console.WriteLine(""); Console.WriteLine("Bay {0} contains loads ", CB.Name); ArrayList LIB = CB.loadsInBAy; if (LIB.Count == 0) { Console.WriteLine("Bay {0} has no loads", CB.Name); } else { for (int i = 0; i < LIB.Count; i++) { String LoadName = (String)LIB[i]; Console.WriteLine("{0}: {1} ", i + 1, LoadName); } } Console.WriteLine("Select a number that corresponds to the load that you want to remove"); int NumofLoad = int.Parse(Console.ReadLine()); String curLoad = (String)CB.loadsInBAy[NumofLoad - 1]; CB.loadsInBAy.RemoveAt(NumofLoad - 1); Console.WriteLine("{0} has been sucessfully removed", curLoad); Console.ReadLine(); }
static void Main(string[] args) { Docks Dock = new Docks(); int choice; do { Console.Clear(); Console.WriteLine("INDICATE WHICH FUNCTIONALITY YOU WISH TO TEST"); Console.WriteLine("1. Display list of Bays"); Console.WriteLine("2. Enter Load Information"); Console.WriteLine("3. Display Load Information"); Console.WriteLine("4. Display sorted List of Bays"); Console.WriteLine("5. Allocate and Display the Loads"); Console.WriteLine("6. Remove A Load from a bay"); Console.WriteLine("9. TERMINATE PROCESSING"); choice = int.Parse(Console.ReadLine()); switch (choice) { case 1: Dock.DisplayBays(); Console.WriteLine("Press enter to continue................"); Console.ReadLine(); break; case 2: // At this point we have a list of loads stored in an arraylist. Now its time to allocate the loads Dock.LoadInformation(); Console.WriteLine("Press enter to continue................"); Console.ReadLine(); break; case 3: //Displays Loads Dock.DisplayLoads(); Console.WriteLine("Press enter to continue................"); Console.ReadLine(); break; case 4: // At this point the List of bays is sorted in ascending order Console.WriteLine("Sorted List of Bays"); Dock.DisplaySorted(); Console.WriteLine("Press enter to continue................"); Console.ReadLine(); break; case 5: //Display with Allocated Bays Dock.AllocateTry(); Console.WriteLine("Sorted List of Loads"); Console.WriteLine("Press enter to continue................"); Console.ReadLine(); break; case 6: //Removes loads from a bay Bay[] BL = Dock.Test(); for (int i = 0; i < BL.Count(); i++) { Bay curbay = (Bay)BL[i]; if (curbay.loadsInBAy.Count > 0) { curbay.DisplayLoadsofABay(); } } Console.WriteLine("Press Enter to remove a load"); Console.ReadLine(); Dock.RevoveLoadFromBay(); break; case 9: break; default: Console.WriteLine("Incorrect selection - press enter to continue"); Console.ReadLine(); break; } }while (choice != 9); Console.WriteLine("Processing terminated - press enter to continue"); Console.ReadLine(); }
public void AllocateLoads() { double sum = 0; int lastPoint = 0; if (60 > ListOfLoads.Count()) // theres more Bays than loads // Bays size is 60 { int i = 0; int p = 0; Bay curBay = ListOfBays.CurrentBay(i); Load curLoad = ListOfLoads.CurrentLoad(p); while (curLoad.weight > 0) // This allows the weight of a single load to continuosly decrease until the whole load has been allocated to a bay { while (curBay.AvailableCapacity > 0) // if there is space in bay { while (curLoad.weight > 0) { sum += curLoad.weight; if (curBay.AvailableCapacity >= curLoad.weight) // there is enough space in bay to accomadate a whole load { Console.WriteLine("Allocate {0} loads from {1} to Bay {2}", curLoad.weight, curLoad.Name, curBay.Name); curBay.subtractcapacity(curLoad.weight); curLoad.SubTractLoad(curLoad.weight); curLoad.Bay = curLoad.Bay + " " + curBay.Name; if (curLoad.weight == 0) { i++; } if (i == ListOfLoads.Count()) { Console.WriteLine("total loads is: {0}", sum); Console.WriteLine("End of List Loads"); lastPoint = i; break; } curLoad = ListOfLoads.CurrentLoad(i); } else // if there is not enough space in bay { double diff = curLoad.weight - curBay.AvailableCapacity; Console.WriteLine("Allocate {0} loads from {1} to Bay {2}", curBay.AvailableCapacity, curLoad.Name, curBay.Name); //sum += curLoad.weight; curLoad.SubTractLoad(curBay.AvailableCapacity); curBay.subtractcapacity(curBay.AvailableCapacity); curLoad.Bay = curLoad.Bay + " " + curBay.Name; if (curBay.AvailableCapacity == 0) { p++; }// availabe capacity of bay is 0 if (p == 60) { Console.WriteLine("No more bays left, we need more spcae/bays"); Console.WriteLine("the remaining loads is"); //displayremainingLoads(LoadArrList, i); break; } curBay = ListOfBays.CurrentBay(p); } } break; } break; } } else // There is more (or just enough) Loads than Bays { int p = 0; for (int i = 0; i < 60; i++) { Bay curBay = ListOfBays.CurrentBay(i); Load curLoad = ListOfLoads.CurrentLoad(p); p++; //while (curLoad.weight > 0) // This allows the weight of a single load to continuosly decrease until the whole load has been allocated to a bay //{ if (curBay.AvailableCapacity > 0) // if there is enough space in bay { if (curBay.AvailableCapacity >= curLoad.weight) { Console.WriteLine("Allocate {0} loads from {1} to {2}", curLoad.weight, curLoad.Name, curBay.Name); curBay.subtractcapacity(curLoad.weight); curLoad.Bay = curLoad.Bay + " " + curBay.Name; } } else // if there is not enough space in bay { double diff = curLoad.weight - curBay.AvailableCapacity; Console.WriteLine("Allocate {0} loads from {2} to {1}", diff, curBay.Name, curLoad.Name); curLoad.SubTractLoad(diff); curLoad.Bay = curLoad.Bay + " " + curBay.Name; } //} if (i == 60) { Console.WriteLine("End of bays, now for repeat"); i = 0; break; } } } }
public void displayBay(Bay cur) { Console.WriteLine("{0}, MaxCapacity: {1}, AvailableCapacity: {2}", cur.Name, cur.MaxCapacity, AvailableCapacity); }