In: Computer Science
C#
A car dealer wants an application that calculates the cost of a car.
The GUI application should link the “BuildYourCar.accdb” database and display all the data in four different “ListBox” based on the category. Each “ListBox” should display all the items in that category. The user can only choose one item from each “ListBox” to add an item to a car. As each item is selected, the application displays the item in a separate “ListBox” to display. If user wants to remove an item, the user can click the item in the display “ListBox” to remove it. When the item is selected, the cost of that item will be added to the subtotal. When the item is removed, the cost of that item will be subtracted.
The program should include Subtotal, Tax, and Total fields in the GUI. Also, the user can click the “Clear” Button to restore the Subtotal, Tax, and Total to $0.00.
Use the BuildYourCar.accdb database
Output:
Code will be like:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CarDealershipForm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//load items to the listbox from the database.
double price = 0;
string listBox1Item = listBox1.SelectedItem.ToString();
string listBox2Item = listBox2.SelectedItem.ToString();
string listBox3Item = listBox3.SelectedItem.ToString();
string listBox4Item = listBox4.SelectedItem.ToString();
//using the differnet items setup an ifelse statement to
avaluate price and display
// it in the subtotal box.
if(listBox1Item=="Item 1 from listbox")
{
//Increment the price value accordingly
}
if (listBox1Item == "Item 2 from listbox")
{
//Increment the price value accordingly
}
if (listBox1Item == "Item 3 from listbox")
{
//Increment the price value accordingly
}
if (listBox2Item == "Item 1 from listbox")
{
//Increment the price value accordingly
}
if (listBox2Item == "Item 2 from listbox")
{
//Increment the price value accordingly
}
if (listBox3Item == "Item 3 from listbox")
{
//Increment the price value accordingly
}
// continue for all listboxes.
}
}
}
Designer:
namespace CarDealershipForm
{
partial class Form1
{
/// <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.listBox1 = new System.Windows.Forms.ListBox();
this.listBox2 = new System.Windows.Forms.ListBox();
this.listBox3 = new System.Windows.Forms.ListBox();
this.listBox4 = new System.Windows.Forms.ListBox();
this.listBox5 = new System.Windows.Forms.ListBox();
this.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// listBox1
//
this.listBox1.FormattingEnabled = true;
this.listBox1.Location = new System.Drawing.Point(31, 33);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(120, 95);
this.listBox1.TabIndex = 0;
//
// listBox2
//
this.listBox2.FormattingEnabled = true;
this.listBox2.Location = new System.Drawing.Point(199, 33);
this.listBox2.Name = "listBox2";
this.listBox2.Size = new System.Drawing.Size(120, 95);
this.listBox2.TabIndex = 1;
//
// listBox3
//
this.listBox3.FormattingEnabled = true;
this.listBox3.Location = new System.Drawing.Point(337, 33);
this.listBox3.Name = "listBox3";
this.listBox3.Size = new System.Drawing.Size(120, 95);
this.listBox3.TabIndex = 3;
//
// listBox4
//
this.listBox4.FormattingEnabled = true;
this.listBox4.Location = new System.Drawing.Point(489, 33);
this.listBox4.Name = "listBox4";
this.listBox4.Size = new System.Drawing.Size(120, 95);
this.listBox4.TabIndex = 2;
//
// listBox5
//
this.listBox5.FormattingEnabled = true;
this.listBox5.Location = new System.Drawing.Point(246, 225);
this.listBox5.Name = "listBox5";
this.listBox5.Size = new System.Drawing.Size(120, 95);
this.listBox5.TabIndex = 5;
//
// button1
//
this.button1.Location = new System.Drawing.Point(264, 164);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 6;
this.button1.Text = "Add";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new
System.EventHandler(this.button1_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(222, 368);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 20);
this.textBox1.TabIndex = 7;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(116, 375);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(31, 13);
this.label1.TabIndex = 8;
this.label1.Text = "Total";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(635, 424);
this.Controls.Add(this.label1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button1);
this.Controls.Add(this.listBox5);
this.Controls.Add(this.listBox3);
this.Controls.Add(this.listBox4);
this.Controls.Add(this.listBox2);
this.Controls.Add(this.listBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.ListBox listBox2;
private System.Windows.Forms.ListBox listBox3;
private System.Windows.Forms.ListBox listBox4;
private System.Windows.Forms.ListBox listBox5;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label1;
}
}
Please rate it if the above solution helps you in any way or if you have any concerns comment it, I will help you through again.