public static void DisplayData() { //Read Data first Marina.ReadData(); for (int i = 0; i < Marina.Boats.Count; i++)//adds index number for the boat entries { Boat boat = Marina.Boats[i]; Console.WriteLine("Entry:" + i + "\nOwner Name: {0}\nBoat Name: {1}\nBoat Type: {2}\nBoat Length: {3} m\nBoat Draft: {4} m\nPeriod of stay in months: {5}\nPrice of the booking: {6} £\nBooking end date: {7}\n==================", boat.OwnerName, boat.BoatName, boat.BoatType, boat.BoatLength, boat.BoatDraft, boat.MonthInput, boat.TotalPrice, boat.ExactDate); } }
public static void NextMainMenu()//Display Method - Next Menu { int input; int.TryParse(Console.ReadLine(), out input);//Convert input to int switch (input) { case 1: Console.Clear(); Console.WriteLine("New booking"); Console.WriteLine("=================="); Boat.NewBoatEntry(); Console.WriteLine("Press enter to return to the main menu."); Console.ReadLine(); Console.Clear(); break; case 2: Console.Clear(); Console.WriteLine("View bookings"); Console.WriteLine("The total marina space left is {0} m.", Marina.TotalMarinaSpaceCheck()); Console.WriteLine("=================="); DisplayActions.DisplayData(); Console.WriteLine("Press enter to return to the main menu."); Console.ReadLine(); Console.Clear(); break; case 3: Console.Clear(); Console.WriteLine("Delete bookings"); Console.WriteLine("=================="); DisplayActions.DisplayData(); DisplayActions.RemoveBoat(input); Console.WriteLine("Press enter to return to the main menu."); Console.ReadLine(); Console.Clear(); break; case 4: Environment.Exit(0); break; default: Console.WriteLine("Please select a number from 1 to 4"); Console.ReadLine(); Console.WriteLine("Press any key to continue"); Console.Clear(); break; } return;//return the method }
public static int MarinaSpaceCheck()//method which counts the boats stored in the file and summs up the boat lengths. { //Read Data from file first Marina.ReadData(); int sum = 0; for (int i = 0; i < Marina.Boats.Count; i++)//counts the boats in the list { Boat boat = Marina.Boats[i]; sum = sum + boat.BoatLength;//sums up the boat lengths } return(sum); }
static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.Yellow; while (true) { Marina.ReadData(); Marina.MarinaSpaceCheck(); MainMenu.MainMenuDisplay(); MainMenu.NextMainMenu(); Marina.MarinaSpaceCheck(); } }
public static void RemoveBoat(int index) { Marina.ReadData(); Console.WriteLine("Please select the entry number coresponding to the booking you wish to delete."); string removeIndex = Console.ReadLine(); bool checkIndex; int removeBoatIndex; checkIndex = int.TryParse(removeIndex, out removeBoatIndex); if (checkIndex == true) { if (removeBoatIndex >= 0 && removeBoatIndex < Marina.Boats.Count) { var removedBoat = Marina.Boats[removeBoatIndex]; Marina.Boats.RemoveAt(removeBoatIndex); //removes the boat based on the assinged index Marina.WriteData(); //Update data after deleting entry for (int i = removeBoatIndex; i < Marina.Boats.Count; i++) //counting the boats after the deleted boat to get the boat name and move them to the holding bay { Boat boat = Marina.Boats[i]; Console.WriteLine("Boat {0}, has been moved to the holding bay to make way for boat {1}.", boat.BoatName, removedBoat.BoatName); Thread.Sleep(2000);//(Forum For Electronics, 2018) } Console.WriteLine("Boat {0} is now moving toward the entrance.", removedBoat.BoatName); Thread.Sleep(2000); Console.WriteLine("Boat {0} leaving the marina.", removedBoat.BoatName); Thread.Sleep(1000); Console.WriteLine("Booking has been deleted. Boat {0} left the marina.", removedBoat.BoatName); for (int i = removeBoatIndex; i < Marina.Boats.Count; i++) { Boat boat = Marina.Boats[i]; Console.WriteLine("Boat {0}, has been moved back in the marina.", boat.BoatName); Thread.Sleep(2000); } } else { Console.WriteLine("The value you have entered does not match any index number. Please try again."); } } else { Console.WriteLine("The value you have entered does not match any index number. Please try again."); } return; }
public static void NewBoatEntry()//Assignning input to the variables and variable validation { Console.WriteLine("Please enter the name of the owner."); while (true) { ownerName = Console.ReadLine(); if (string.IsNullOrEmpty(ownerName)) { Console.WriteLine("Please enter your name."); continue; } else { break; } } Console.WriteLine("Please enter the name of the boat."); while (true) { boatName = Console.ReadLine(); if (string.IsNullOrEmpty(boatName)) { Console.WriteLine("Please enter the name of the boat."); continue; } else { break; } } Console.WriteLine("Please enter the boat type. (motor, narrow or sailing)"); while (true) { boatType = Console.ReadLine(); if (boatType == "motor") { break; } else if (boatType == "sailing") { break; } else if (boatType == "narrow") { break; } else { Console.WriteLine("The boat type can be only: motor, narrow or sailing. Please try again."); continue; } } bool checkLength; int boatLengthInt = 0; while (true) { Console.WriteLine("Please enter the length of the boat."); boatLength = Console.ReadLine(); checkLength = int.TryParse(boatLength, out boatLengthInt); int verifySpace = Marina.TotalMarinaSpaceCheck();//Checking the marina space against the new boat length entry if (checkLength && boatLengthInt > 15) { Console.WriteLine("The boat lenght cannot exced 15 meters."); continue; } else if (checkLength && boatLengthInt < 1) { Console.WriteLine("The boat lenght cannot be 0 meters or less."); continue; } else if (!checkLength) { Console.WriteLine("Please enter a valid value."); continue; } else if (verifySpace < boatLengthInt) { Console.WriteLine("There is no more space in the marina."); Console.ReadKey(); Console.Clear(); return; } else { break; } } Console.WriteLine("Please enter the draft of the boat."); while (true) { boatDraft = Console.ReadLine(); bool checkDraft; double boatDraftInt; checkDraft = double.TryParse(boatDraft, out boatDraftInt); if (checkDraft && boatDraftInt > 5) { Console.WriteLine("The boat draft cannot exced 5 meters."); continue; } else if (checkDraft && boatDraftInt < 1) { Console.WriteLine("The boat draft cannot be 0 meters."); continue; } else if (!checkDraft) { Console.WriteLine("Please enter a valid value."); continue; } else { break; } } Console.WriteLine("Please enter the duration of your stay in months."); while (true) { monthInput = Console.ReadLine(); bool checkMonthInput; int monthInputInt; checkMonthInput = int.TryParse(monthInput, out monthInputInt); if (!checkMonthInput) { Console.WriteLine("Please enter a valid value."); continue; } else { Console.WriteLine("The price for the stay is: {0} £", StayPrice(monthInputInt, boatLengthInt)); Console.WriteLine("Your booking ends on {0}", DateTimeEnd(monthInputInt)); break; } } Console.WriteLine("Press the return key to accept or enter -1 to reject"); string lastinput = Console.ReadLine(); bool checkLastInput; int lastInputInt; checkLastInput = int.TryParse(lastinput, out lastInputInt); while (true) { if (lastInputInt != -1) { //creating the boat object Boat boat = new Boat(ownerName, boatName, int.Parse(boatLength), double.Parse(boatDraft), boatType, int.Parse(monthInput), StayPrice(int.Parse(Boat.monthInput), int.Parse(Boat.boatLength)), DateTimeEnd(int.Parse(Boat.monthInput))); Marina.AddBoat(boat);//Add new boat to list break; } else { Environment.Exit(0); break; } } }