Thursday, September 19, 2024 9:12:50 PM
> settings

Customize


Authenticate

> Order.cs
/*
 * Bryan
 * Lab 6 Extra Credit
 */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;

namespace bryan_vacationPicker
{
    public class Order
    {
        public string name { get; set; }
        public decimal num_members { get; set; }
        public decimal num_equipment { get; set; }
        public decimal num_instructions { get; set; }
        public int days { get; set; }
        public int lodging_index { get; set; }

        public decimal base_charge { get; set; } = 0m;
        public decimal instruction { get; set; } = 0m;
        public decimal equipment { get; set; } = 0m;
        public decimal lodging { get; set; } = 0m;
        private decimal total { get; set; }
        private decimal discount { get; set; }
        private decimal deposit { get; set; }


        /// <summary>
        /// Override the ToString method
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            calculateTotal();

            return $"------------------------------------------------{Environment.NewLine}" +
                $"{name}{Environment.NewLine}" +
                $"Total party members: {num_members}{Environment.NewLine}" +
                ((num_equipment > 0) ? $"Number of equipment rentals: {num_equipment}{Environment.NewLine}" : "") +
                ((num_instructions > 0) ? $"Number of people needing instructions: {num_instructions}{Environment.NewLine}" : "") +
                ((name == "Devil's Courthouse Adventure Weekend") ? $"Number of advanced climbers: {num_members - num_instructions}{Environment.NewLine}" : "") +
                $"   Base charge: {base_charge * num_members:c}{Environment.NewLine}" +
                ((lodging > 0) ? $"   Lodging: {lodging:c}{Environment.NewLine}" : "") +
                ((num_instructions > 0) ? $"   Instruction Cost: {instruction:c}{Environment.NewLine}" : "") +
                ((num_equipment > 0) ? $"   Equipment Rental Cost: {equipment:c}{Environment.NewLine}" : "") +
                ((discount > 0) ? $"   Discount: -{discount:c}{Environment.NewLine}" : "") +
                $"   Total Charges: {total:c}{Environment.NewLine}" +
                $"   Required Deposit: {deposit:c}{Environment.NewLine}";
        }

        /// <summary>
        /// Creates a list based on the order
        /// </summary>
        /// <returns></returns>
        public List<string> ToList()
        {
            return this.ToString().Split(new[] { Environment.NewLine }, StringSplitOptions.None).ToList();
        }

        /// <summary>
        /// Adds the list to the binding list
        /// </summary>
        /// <param name="list"></param>
        public void AddToBindingList(ref BindingList<string> list)
        {
            foreach (string line in ToList())
                list.Add(line);
        }


        /// <summary>
        /// calculate the total
        /// </summary>
        private void calculateTotal()
        {
            discount = (num_members >= 5) ? (base_charge * num_members) * 0.1m : 0m;
            equipment = 40 * days * num_equipment;
            instruction = 100 * num_instructions;

            if (lodging_index != -1)
                lodging = (lodging_index == 0) ? 65m * days * num_members : 120m * days * num_members;

            total = (base_charge * num_members) + equipment + instruction + lodging - discount;

            deposit = total / 2;
        }
    }
}
All opinions represented herein are my own
- © 2024 itsthedevman
- build 3c15a1b