The ABC Shipping Company charges the Rates listed in the following table:
Weight of the package Rate per mile in California Rate per mile other states
2 kg or less $2.5 $3.5
Over2 kg but not more than 6 kg $3.5 $5.0
Over 6 Kg but not more than 10 kg $4.5 $6.0
Over 10 Kg but not more than 30 Kg $5.0 $7.5
Over 30 kg $6.0 $8.5
Create an application that contains two radio buttons to select California or other states, a listbox for the user to select the package’s weight class, a textbox to enter the distance it is to be shipped, and a button to calculate and display the charges on a label control when it is clicked.
Input validation: Do not accept distances of less than 5 miles or more than 3000 miles
/* Please read all the comments and see the output screen */
/* Form1.cs */
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 Shipping_Distance_charge
{
public partial class Form1 : Form
{
//Store the charge for the other state and california in
array
double [] california = { 2.5, 3.5, 4.5, 5.0, 6.0 };
double [] other = { 3.5, 5.0, 6.0, 7.5, 8.5 };
//This is distance to be read from textbox
int distance;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs
e)
{
//First check textbox for reading distance is valid number or
not
if (isNumber(textBox1.Text))
{
//Validated the input value for less than 5 and greater than
300.
//If invalid , return
if (distance < 5 || distance > 300)
{
MessageBox.Show("Invalid Range of distance!");
return;
}
else
{
// Check if any of radio button is selected or not
if (!(radioButton1.Checked || radioButton2.Checked))
{
MessageBox.Show("Please choose any of California or Other
state");
return;
}
//Else now, check list box item is selected or not. If not return
with giving message to choose listbox item
if (listBox1.SelectedIndex == -1)
{
MessageBox.Show("Please select an item from listbox!");
return;
}
//If every input and selection is ok, calculate the
actual charge,
// based on the radiobutton selection and listbox item
// Now we are using here the array of charge for california and
other state
double charge = distance * (radioButton1.Checked ?
california[listBox1.SelectedIndex] :
other[listBox1.SelectedIndex]);
label2.Text = "Total Charge " + charge.ToString();
}
}
else
{
//If Distance input is invalid, we can't do the calculation. So
show the error messsage
MessageBox.Show("Invalid Distance Input");
return;
}
}
bool isNumber(string data)
{
return int.TryParse(data, out distance);
}
}
}
/* This is form1.design.cs */
/* form1.designer.cs*/
namespace Shipping_Distance_charge
{
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.label1 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.radioButton1 = new System.Windows.Forms.RadioButton();
this.radioButton2 = new System.Windows.Forms.RadioButton();
this.listBox1 = new System.Windows.Forms.ListBox();
this.label2 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(69, 82);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(77, 13);
this.label1.TabIndex = 0;
this.label1.Text = "Enter Distance";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(164, 79);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 20);
this.textBox1.TabIndex = 1;
//
// radioButton1
//
this.radioButton1.AutoSize = true;
this.radioButton1.Location = new System.Drawing.Point(72,
121);
this.radioButton1.Name = "radioButton1";
this.radioButton1.Size = new System.Drawing.Size(66, 17);
this.radioButton1.TabIndex = 2;
this.radioButton1.TabStop = true;
this.radioButton1.Text = "Calfornia";
this.radioButton1.UseVisualStyleBackColor = true;
//
// radioButton2
//
this.radioButton2.AutoSize = true;
this.radioButton2.Location = new System.Drawing.Point(183,
121);
this.radioButton2.Name = "radioButton2";
this.radioButton2.Size = new System.Drawing.Size(79, 17);
this.radioButton2.TabIndex = 3;
this.radioButton2.TabStop = true;
this.radioButton2.Text = "Other State";
this.radioButton2.UseVisualStyleBackColor = true;
//
// listBox1
//
this.listBox1.FormattingEnabled = true;
this.listBox1.Items.AddRange(new object[] {
"Less than or equals to 2KG",
"More than 2KG and less than 6KG",
"More than 6KG and less than 10KG",
"More than 10KG and less than 30KG",
"More than 30KG"});
this.listBox1.Location = new System.Drawing.Point(72, 167);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(192, 95);
this.listBox1.TabIndex = 4;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(78, 288);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(68, 13);
this.label2.TabIndex = 5;
this.label2.Text = "Total Charge";
//
// button1
//
this.button1.Font = new System.Drawing.Font("Microsoft Sans Serif",
14.25F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.button1.Location = new System.Drawing.Point(81, 319);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(181, 39);
this.button1.TabIndex = 6;
this.button1.Text = "Calculate";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new
System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.button1);
this.Controls.Add(this.label2);
this.Controls.Add(this.listBox1);
this.Controls.Add(this.radioButton2);
this.Controls.Add(this.radioButton1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.RadioButton radioButton1;
private System.Windows.Forms.RadioButton radioButton2;
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button button1;
}
}
/* OUTPUT SCREEN*/
/* First Screen*/
/* Validation and input given screen */
Lhe ABC Shipping Company charges the Rates listed in the following table: Weight of the package R...
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; using System.IO; namespace FileWriter { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnCreate_Click(object sender, EventArgs e) { try { //write code that assigns the value in the textbox to an Integer variable if // write code that validates whether or not the data entered in the textbox is greater than or equal to 1 *...