hello I cannot seem to figure this problem out. Anyone know how to use listboxes
ID: 3675122 • Letter: H
Question
hello I cannot seem to figure this problem out. Anyone know how to use listboxes with a radiobutton?
The ABC Shipping Company charges the Rates listed in the following table:
Weight of the package (in kilograms) Shipping rate per mile in California Shipping rate per mile other states
2 kg or less $2.0 $2.5
Over2 kg but not more than 6 kg $3.0 $3.5
Over 6 Kg but not more than 10 kg $3.5 $4.0
Over 10 Kg but not more than 30 Kg $4.0 $4.5
Over 30 kg $5.0 $5.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
Explanation / Answer
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 Assignment_4
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
listBox1.Items.Add("2kg or less");
listBox1.Items.Add("Between 2kg & 6kg");
listBox1.Items.Add("Between 7kg & 10kg");
listBox1.Items.Add("Between 11kg & 30kg");
listBox1.Items.Add("Over 30kg");
}
private void button1_Click(object sender, EventArgs e)
{
double rate, distance, charge, state, cali, other;
distance = double.Parse(textBox1.Text);
if (radioButton1.Checked)
state = cali;
else
state = other;
if (listBox1.SelectedIndex == 0)
rate = 2.0;
else if (listBox1.SelectedIndex == 1)
rate = 3.0;
else if (listBox1.SelectedIndex == 2)
rate = 3.5;
else if (listBox1.SelectedIndex == 3)
rate = 4.0;
else if (listBox1.SelectedIndex == 4)
rate = 5.0;
}
private void textBox1_Validating(object sender, CancelEventArgs e)
{
double distance;
distance = double.Parse(textBox1.Text);
if (distance < 5 || distance > 3000)
{
MessageBox.Show("Miles must be more than 5 or less than 3,000");
e.Cancel = true;
}
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.