static void Main(string[] args) { //Golf course directory and json read string currentDirectory = Directory.GetCurrentDirectory(); DirectoryInfo directory = new DirectoryInfo(currentDirectory); var fileName = Path.Combine(directory.FullName, "Courses.json"); // menu start and user input questions int result = 0; while (result != 4) { Console.WriteLine("What would you like to do? Then Hit Enter" + "\n - 1 look at available course list" + "\n - 2 add another course" + "\n - 3 delete a course" + "\n - 4 exit"); if (int.TryParse(Console.ReadLine(), out result)) { // Golf course list if (result == 1) { List <GolfCourse> golfCourses = GetCourses(fileName); ViewCourses(golfCourses); } // Add a new course user input functions else if (result == 2) { GolfCourse course = new GolfCourse(); List <GolfCourse> golfCourses = GetCourses(fileName); Console.WriteLine("Golf Course Name?"); string name = Console.ReadLine(); Console.WriteLine("Course Par?"); int par = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Course Rating?"); double rating = Convert.ToDouble(Console.ReadLine()); Console.WriteLine("Course Slope?"); double slope = Convert.ToDouble(Console.ReadLine()); Console.WriteLine("Course Distance?"); int distance = Convert.ToInt32(Console.ReadLine()); course.Name = name; course.Par = par; course.Rating = rating; course.Slope = slope; course.Distance = distance; AddCourse(course, golfCourses, fileName); } // golf course delete function else if (result == 3) { Console.WriteLine("Golf Course Name?"); string name = Console.ReadLine(); DeleteCourse(name, fileName); } //exit out of program else if (result == 4) { Console.WriteLine("Head to the 19th green"); } Console.WriteLine(); } } }
// add course method for .2 public static void AddCourse(GolfCourse course, List <GolfCourse> golfCourses, string fileName) { golfCourses.Add(course); Save(golfCourses, fileName); }