Exemplo n.º 1
0
        static void Main(string[] args)
        {
            //set up do...while loop to allow users to restart the process
            string endOrder = null;
            do
            {

                //display initial welcome message
                Console.WriteLine(@"
                ************************************************
                Welcome to the Mega Escritorio custom desk quote
                application! Please follow the prompts below in
                order to recieve your personalized price quote.
                ************************************************");
                //variables to be used
                Desk newDeskQuote = new Desk();
                DeskOrderMethods d = new DeskOrderMethods();

                //get user input
                newDeskQuote.deskWidth = d.GetIntegerInRange("Please enter your desired desk width in inches:", 1, 500);
                newDeskQuote.deskLength = d.GetIntegerInRange("Please enter your desired desk length in inches:", 1, 500);
                newDeskQuote.noOfDrawers = d.GetIntegerInRange("Please enter your desired number of drawers (max 7):", 0, 7);
                newDeskQuote.deskTopType = d.GetSurfaceType("Please select a surface material from the following: "
                    +"Oak, Laminate, Pine, Marble, Walnut, or Metal");
                newDeskQuote.rushOrder = d.GetIntegerOption("Normal production time is 14 days."
                    + " If you would like to rush your order, "
                    + "please enter 3, 5, or 7 to speed up production time for an extra fee."
                    + " Otherwise, enter 0 if you do not wish to rush this order.", 3, 5, 7, 0);

                //calculate surface area of desk
                int deskArea = newDeskQuote.deskWidth * newDeskQuote.deskLength;
                int areaPrice = d.CalcAreaPrice(deskArea);

                //calculate drawer pricing
                int drawerPrice = 50 * newDeskQuote.noOfDrawers;

                //calculate material cost
                int materialPrice = d.CalcMaterialPrice(newDeskQuote.deskTopType);

                //read in rush order pricing file
                int[,] rushOrderPricing = new int[3, 3];
                d.GetRushOrder(rushOrderPricing);

                //calculate rush order pricing if applicable.
                int rushOrderPrice = d.CalcRushOrder(rushOrderPricing, newDeskQuote.rushOrder, deskArea);

                //total up the various costs and display total to user.
                newDeskQuote.priceEstimate = areaPrice + drawerPrice + materialPrice + rushOrderPrice;

                Console.WriteLine("The total cost of a " + newDeskQuote.deskWidth + "x" +
                    newDeskQuote.deskLength + " " + newDeskQuote.deskTopType + " desk with " + newDeskQuote.noOfDrawers
                    + " drawers and a " + newDeskQuote.rushOrder + " day production time is $"
                    + newDeskQuote.priceEstimate);

                //ask user if they would like to save file
                string saveOrder = d.GetStringOption("Would you like to save this order? Y/N?", "Y", "N");
                if (saveOrder == "Y")
                {
                    d.saveOrderInfo(newDeskQuote);
                }
                endOrder = d.GetStringOption("Thank you for using our application. Please select 'E' to exit, or 'N' to start over.", "E", "N");
            } while (endOrder == "N");
        }
Exemplo n.º 2
0
        //save users order info to external file
        public void saveOrderInfo(Desk orderInfo)
        {
            bool printCheck = true;
            string orderName = GetInput("Please enter the name you would like to save your quote under.");
            try
            {
                //organize order info into JSON format

                string deskOrderInfo = JsonConvert.SerializeObject(orderInfo, Formatting.Indented);
                string[] stringArray = new string[1] { deskOrderInfo };

                //write order info to external file
                File.WriteAllLines("DeskQuote_" + orderName + ".txt", stringArray);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                printCheck = false;

            }
            if (printCheck != false)
                Console.WriteLine("Your order has been saved.");
        }