Thursday, September 19, 2024 9:05:22 PM
> settings

Customize


Authenticate

> Form1.cs
/*
 * Bryan
 * Carpet Calculator
 * Calculate the price of carpet depending on berber or pile selected
 */

using System;
using System.Windows.Forms;

namespace bryan_carpetCalculator
{
    public partial class Main_Form : Form
    {
        /// <summary>
        /// Define Constants
        /// </summary>
        const int SQ_FT_PER_SQ_YARD = 9;
        const int INCHES_PER_FOOT = 12;
        const string BEST_CARPET = "Berber";
        const string ECONOMY_CARPET = "Pile";

        /// <summary>
        /// Initialize Variables
        /// </summary>
        int roomLengthFeet = 12,
            roomLengthInches = 2,
            roomWidthFeet = 14,
            roomWidthInches = 7;

        double roomLength,
            roomWidth,
            carpetPrice,
            numOfSquareFeet,
            numOfSquareYards,
            totalCost;

        /// <summary>
        /// Main entry point for our form
        /// </summary>
        public Main_Form()
        {
            // Needed!
            InitializeComponent();

            // Assign the values ahead of time
            roomLength = roomLengthFeet + roomLengthInches / INCHES_PER_FOOT;
            roomWidth = roomWidthFeet + roomWidthInches / INCHES_PER_FOOT;
        }

        /// <summary>
        /// Determine the square feet of the room
        /// </summary>
        /// <returns></returns>
        public double DetermineSquareFeet()
        {
            numOfSquareFeet = roomLength * roomWidth;
            return numOfSquareFeet;
        }

        /// <summary>
        /// Determine the square yards from the square feet.
        /// </summary>
        /// <returns></returns>
        public double DetermineSquareYards()
        {
            numOfSquareYards = DetermineSquareFeet() / SQ_FT_PER_SQ_YARD;
            return numOfSquareYards;
        }

        /// <summary>
        /// Determines total price from the yards and price
        /// </summary>
        /// <returns></returns>
        public double DeterminePrice()
        {
            totalCost = DetermineSquareYards() * carpetPrice;
            return totalCost;
        }

        /// <summary>
        /// Event handler for Radio Button Berber. Changes the price text and carpet price
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void rb_Berber_CheckedChanged(object sender, EventArgs e)
        {
            tb_PricePerSYard.Text = "$27.95";
            carpetPrice = 27.95;
        }

        /// <summary>
        /// Event handler for Radio Button Pile. Changes the price text and carpet price
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void rb_Pile_CheckedChanged(object sender, EventArgs e)
        {
            tb_PricePerSYard.Text = "$15.95";
            carpetPrice = 15.95;
        }

        /// <summary>
        /// Event handler for calculate button. Formats the price into currency
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Calculate_Click(object sender, EventArgs e)
        {
            tb_TotalPrice.Text = string.Format("{0:c}", DeterminePrice());
        }

        /// <summary>
        /// Event handler for the reset button.... It resets stuff.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Reset_Click(object sender, EventArgs e)
        {
            rb_Pile.Checked = false;
            rb_Berber.Checked = false;
            tb_PricePerSYard.Text = "";
            tb_TotalPrice.Text = "";
        }

        /// <summary>
        /// Because the exit button at the top right of the window wasn't enough, we made our own.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Exit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}
All opinions represented herein are my own
- © 2024 itsthedevman
- build 3c15a1b