Answer to Question #251607 in C# for Israel

Question #251607

Create a program that allows bags to be purchased. There are six different types: full decorative, beaded, needlepoint design, fringed beaded and plain. Create a ListBox object for the different styles. After the user makes a selection, display a message indicating which selection was made. Include an option to clear selections. Include a control that allows the user to enter the quantity desired. Include a set of radio buttons that contain shipping options of overnight, three day and standard. The price for each bag is as follows: full decorative R50; beaded – R45; needlepoint design – R40, fringed beaded – R30 and plain – R20. The shipping charges are based on the total purchase. The following percentages are used: Overnight – 10%, three day – 7% and standard – 5%. Display in a message box the shipping charge along with the selection, quantity and total cost.


1
Expert's answer
2021-10-15T11:58:26-0400
namespace BagsProject
{
    partial class frmBags
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.lstStyles = new System.Windows.Forms.ListBox();
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.txtSelectedStyle = new System.Windows.Forms.TextBox();
            this.label3 = new System.Windows.Forms.Label();
            this.txtQuantityDesired = new System.Windows.Forms.TextBox();
            this.rbOvernight = new System.Windows.Forms.RadioButton();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.rbStandard = new System.Windows.Forms.RadioButton();
            this.rbThreeDay = new System.Windows.Forms.RadioButton();
            this.btnClear = new System.Windows.Forms.Button();
            this.btnCalculate = new System.Windows.Forms.Button();
            this.btnExit = new System.Windows.Forms.Button();
            this.groupBox1.SuspendLayout();
            this.SuspendLayout();
            // 
            // lstStyles
            // 
            this.lstStyles.FormattingEnabled = true;
            this.lstStyles.Items.AddRange(new object[] {
            "Full decorative (R50)",
            "Beaded (R45)",
            "Needlepoint design (R40)",
            "Fringed beaded (R30)",
            "Plain (R20)"});
            this.lstStyles.Location = new System.Drawing.Point(9, 35);
            this.lstStyles.Name = "lstStyles";
            this.lstStyles.Size = new System.Drawing.Size(135, 95);
            this.lstStyles.TabIndex = 0;
            this.lstStyles.SelectedIndexChanged += new System.EventHandler(this.lstStyles_SelectedIndexChanged);
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(6, 19);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(61, 13);
            this.label1.TabIndex = 1;
            this.label1.Text = "Select style";
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(150, 29);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(76, 13);
            this.label2.TabIndex = 1;
            this.label2.Text = "Selected style:";
            // 
            // txtSelectedStyle
            // 
            this.txtSelectedStyle.Location = new System.Drawing.Point(232, 26);
            this.txtSelectedStyle.Name = "txtSelectedStyle";
            this.txtSelectedStyle.ReadOnly = true;
            this.txtSelectedStyle.Size = new System.Drawing.Size(206, 20);
            this.txtSelectedStyle.TabIndex = 2;
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(150, 55);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(130, 13);
            this.label3.TabIndex = 1;
            this.label3.Text = "Enter the quantity desired:";
            // 
            // txtQuantityDesired
            // 
            this.txtQuantityDesired.Location = new System.Drawing.Point(286, 52);
            this.txtQuantityDesired.Name = "txtQuantityDesired";
            this.txtQuantityDesired.Size = new System.Drawing.Size(152, 20);
            this.txtQuantityDesired.TabIndex = 2;
            // 
            // rbOvernight
            // 
            this.rbOvernight.AutoSize = true;
            this.rbOvernight.Location = new System.Drawing.Point(191, 23);
            this.rbOvernight.Name = "rbOvernight";
            this.rbOvernight.Size = new System.Drawing.Size(94, 17);
            this.rbOvernight.TabIndex = 3;
            this.rbOvernight.Text = "Overnight 10%";
            this.rbOvernight.UseVisualStyleBackColor = true;
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.rbStandard);
            this.groupBox1.Controls.Add(this.rbThreeDay);
            this.groupBox1.Controls.Add(this.rbOvernight);
            this.groupBox1.Location = new System.Drawing.Point(153, 80);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(287, 50);
            this.groupBox1.TabIndex = 4;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "Select shipping options:";
            // 
            // rbStandard
            // 
            this.rbStandard.AutoSize = true;
            this.rbStandard.Checked = true;
            this.rbStandard.Location = new System.Drawing.Point(8, 23);
            this.rbStandard.Name = "rbStandard";
            this.rbStandard.Size = new System.Drawing.Size(88, 17);
            this.rbStandard.TabIndex = 3;
            this.rbStandard.TabStop = true;
            this.rbStandard.Text = "Standard  5%";
            this.rbStandard.UseVisualStyleBackColor = true;
            // 
            // rbThreeDay
            // 
            this.rbThreeDay.AutoSize = true;
            this.rbThreeDay.Location = new System.Drawing.Point(98, 23);
            this.rbThreeDay.Name = "rbThreeDay";
            this.rbThreeDay.Size = new System.Drawing.Size(90, 17);
            this.rbThreeDay.TabIndex = 3;
            this.rbThreeDay.Text = "Three day 7%";
            this.rbThreeDay.UseVisualStyleBackColor = true;
            // 
            // btnClear
            // 
            this.btnClear.Location = new System.Drawing.Point(201, 150);
            this.btnClear.Name = "btnClear";
            this.btnClear.Size = new System.Drawing.Size(75, 23);
            this.btnClear.TabIndex = 5;
            this.btnClear.Text = "Clear";
            this.btnClear.UseVisualStyleBackColor = true;
            this.btnClear.Click += new System.EventHandler(this.btnClear_Click);
            // 
            // btnCalculate
            // 
            this.btnCalculate.Location = new System.Drawing.Point(282, 150);
            this.btnCalculate.Name = "btnCalculate";
            this.btnCalculate.Size = new System.Drawing.Size(75, 23);
            this.btnCalculate.TabIndex = 5;
            this.btnCalculate.Text = "Calculate";
            this.btnCalculate.UseVisualStyleBackColor = true;
            this.btnCalculate.Click += new System.EventHandler(this.btnCalculate_Click);
            // 
            // btnExit
            // 
            this.btnExit.Location = new System.Drawing.Point(363, 150);
            this.btnExit.Name = "btnExit";
            this.btnExit.Size = new System.Drawing.Size(75, 23);
            this.btnExit.TabIndex = 5;
            this.btnExit.Text = "Exit";
            this.btnExit.UseVisualStyleBackColor = true;
            this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
            // 
            // frmBags
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(450, 183);
            this.Controls.Add(this.btnExit);
            this.Controls.Add(this.btnCalculate);
            this.Controls.Add(this.btnClear);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.txtQuantityDesired);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.txtSelectedStyle);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.lstStyles);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "frmBags";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Bags Project";
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.ListBox lstStyles;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.TextBox txtSelectedStyle;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.TextBox txtQuantityDesired;
        private System.Windows.Forms.RadioButton rbOvernight;
        private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.RadioButton rbStandard;
        private System.Windows.Forms.RadioButton rbThreeDay;
        private System.Windows.Forms.Button btnClear;
        private System.Windows.Forms.Button btnCalculate;
        private System.Windows.Forms.Button btnExit;
    }
}




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace BagsProject
{
    public partial class frmBags : Form
    {
        private double[] bagPrices = { 50,45,40,30,20};


        private const double STANDARD = 0.05;
        private const double THREE_DAY = 0.07;
        private const double OVERNIGHT = 0.10;
        
        


        public frmBags()
        {
            InitializeComponent();
        }


        private void btnClear_Click(object sender, EventArgs e)
        {
            txtSelectedStyle.Text = "";
            txtQuantityDesired.Text = "";
            rbStandard.Checked = true;
        }


        private void btnCalculate_Click(object sender, EventArgs e)
        {
            if (lstStyles.SelectedIndex==-1) {
                MessageBox.Show("Select one bag style from the list.");
                return;
            }
          
            int quantity;
            if (!int.TryParse(txtQuantityDesired.Text, out quantity)) {
                MessageBox.Show("Enter quantity as numeric value.");
                return;
            }
            double subTotalCost = bagPrices[lstStyles.SelectedIndex] * quantity;
            double shippingCharge = subTotalCost * STANDARD;
            if (rbThreeDay.Checked) {
                shippingCharge = subTotalCost * THREE_DAY;
            }
            if (rbOvernight.Checked)
            {
                shippingCharge = subTotalCost * OVERNIGHT;
            }
            double totalCost = subTotalCost + shippingCharge;
            //Display in a message box the shipping charge along with the selection, quantity and total cost.
            MessageBox.Show("Subtotal cost: " + subTotalCost.ToString("C") + Environment.NewLine +
                "Quantity: " + quantity.ToString() + Environment.NewLine +
                "Shipping charge: " + shippingCharge.ToString("C") + Environment.NewLine+
                "Total cost: " + totalCost.ToString("C") + Environment.NewLine );
        }


        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }


        private void lstStyles_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lstStyles.SelectedIndex != -1)
            {
                txtSelectedStyle.Text = lstStyles.SelectedItem.ToString();
            }
        }
    }
}





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS