Beispiel #1
0
        static double AddRoom(List <RoomStats> roomState)
        {
            DisplayHeader("Adding a room\n");

            RoomStats userRoom1  = new RoomStats();
            double    dimOne     = 0;
            double    dimTwo     = 0;
            double    tempSquare = 0;
            bool      valDim     = false;

            Console.WriteLine("Enter Name of Room: ");
            userRoom1.RoomName = Console.ReadLine().ToUpper();

            do
            {
                Console.WriteLine($"Enter {userRoom1.RoomName}'s first Dimension (FEET):");
                if (!double.TryParse(Console.ReadLine(), out dimOne))
                {
                    Console.WriteLine("Not a number or not a supported input. Try again.");
                    valDim = false;
                }
                else
                {
                    valDim = true;
                }
            } while (!valDim);
            userRoom1.DimensionOne = dimOne;
            valDim = false;
            do
            {
                Console.WriteLine($"Enter {userRoom1.RoomName}'s second Dimension (FEET):");
                if (!double.TryParse(Console.ReadLine(), out dimTwo))
                {
                    Console.WriteLine("Not a number or not a supported input. Try again.");
                    valDim = false;
                }
                else
                {
                    valDim = true;
                }
            } while (!valDim);
            userRoom1.DimensionTwo = dimTwo;

            userRoom1.SquareFootage = userRoom1.DimensionOne * userRoom1.DimensionTwo;

            Console.WriteLine($"Alright, so your first room is named {userRoom1.RoomName}, and it is a {userRoom1.DimensionOne}' x {userRoom1.DimensionTwo}' Room, adding to a total square footage of {userRoom1.SquareFootage} feet squared.");

            Console.WriteLine("Press any key to add room.");
            Console.ReadKey();
            roomState.Add(userRoom1);

            Console.WriteLine("Room Added!");

            tempSquare = userRoom1.SquareFootage;

            DisplayContinueScreeeeeeeeeeeeeen();

            return(tempSquare);
        }
Beispiel #2
0
        static List <RoomStats> ReadListFromFile()
        {
            DisplayHeader("Story Time");

            const char       delineator   = ','; // John Velis
            List <string>    roomState    = new List <string>();
            List <RoomStats> roomStates   = new List <RoomStats>();
            RoomStats        tempUserRoom = new RoomStats();
            string           filePath     = @"data\RoomList.txt";

            try
            {
                roomState = File.ReadAllLines(filePath).ToList();
            }
            catch (Exception) // throw any exception up to the calling method
            {
                Console.WriteLine("That didn't work. Try again.");
            }
            foreach (string roomStat in roomState)
            {
                string[] userRooms = roomStat.Split(delineator);

                tempUserRoom.DimensionOne  = Convert.ToDouble(userRooms[1]);
                tempUserRoom.DimensionTwo  = Convert.ToDouble(userRooms[2]);
                tempUserRoom.RoomName      = userRooms[0];
                tempUserRoom.SquareFootage = Convert.ToDouble(userRooms[3]);

                roomStates.Add(tempUserRoom);
            }

            if (roomStates.Contains(tempUserRoom))
            {
                Console.WriteLine("List Read Successfully!");
            }

            DisplayContinueScreeeeeeeeeeeeeen();
            return(roomStates);
        }