Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This assignment is done in C# using Visual Studio Environment. This is what I have so far. This is a distance calculator made witht the

This assignment is done in C# using Visual Studio Environment. This is what I have so far. This is a distance calculator made witht the microsoft visual studio using C# language. An example has been provided at the bottom of the question. Below is an example of what the form needs to look 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 _3333_MedlockB_Lab04 { public partial class Form1 : Form { public Form1() { InitializeComponent();

} int count = 0; double totalDistance = 0; double totalHours = 0;

private void calculateButton_Click(object sender, EventArgs e) { double vehicleSpeed = 0.0; int hours = 0; double distance = 0.0;

//Vehicle speed entered by the user if (double.TryParse(vehicleSpeedTextBox.Text, out vehicleSpeed)) ;

{ if (vehicleSpeed > 0 && vehicleSpeed < 180) ;

//Checking the hours

if (int.TryParse(hoursTraveledTextBox.Text, out hours)) ; { //If valid hours are entered distance = vehicleSpeed * hours; totalDistance = totalDistance + distance; totalHours = totalHours + hours; count++; distanceCalculatorListBox.Items.Add(vehicleSpeed + "\t\t" + hours + "\t)" + distance.ToString("0.00"));

//display details after each entry totalDistanceTextBox.Text = totalDistance.ToString("0.00"); totalHoursTraveledTextBox.Text = totalHours.ToString(); totalTripsTextBox.Text = count.ToString(); averageDistanceTextBox.Text = (totalDistance / count).ToString("0.00");

} //Message to display Please enter the positive value else MessageBox.Show("Speed must be between 1 and 50");

//Set the focus to the vehicle speed text box Control vehicleSpeedTextBox.Focus();

} //Message to display Please enter the integer value else MessageBox.Show("Speed must be between 1 and 180");

//Set the focus to the vehicle speed text box Control vehicleSpeedTextBox.Focus(); }

private void clearButton_Click(object sender, EventArgs e) { //set focus for vehicle speed text box vehicleSpeedTextBox.Clear(); hoursTraveledTextBox.Clear(); }

private void exitButton_Click(object sender, EventArgs e) { //close the application this.Close(); } } }

This lab covers material from Chapter 5 as well as concepts from previous chapters. The purpose of this lab is to demonstrate the use of the appropriate repetition structure as well as to prevent data conversion exceptions using the TryParse method and implement appropriate accuracy validation. Accumulators, counters, and averages are also implemented. 1. Complete Programming Problem #1, Distance Calculator, on page 339 of the textbook.

The ADDITIONAL REQUIREMENTS described below MUST also be implemented:

  • Assume the value of Vehicle Speed in MPH may store whole or floating-point numbers (non-monetary).
  • Assume the value of Hours Traveled can only store whole numbers.
  • Prevent data conversion exception for the Vehicle Speed in MPH text box by using the appropriate TryParse method. If the data entered is invalid display an appropriate error message to the user, set the focus back to the text box causing the error, and either clear the text box or select all the data entered into it so that it can be replaced.
  • Validate the input for the Vehicle Speed in MPH to make sure the data entered is greater than zero and does not exceed 180. If not, display an appropriate error message to the user, set the focus back to the text box causing the error, and either clear the text box or select all the data entered into it so that it can be replaced.
  • Prevent data conversion exception for the Hours Traveled text box by using the appropriate TryParse method. If the data entered is invalid display an appropriate error message to the user, set the focus back to the text box causing the error, and either clear the text box or select all the data entered into it so that it can be replaced.
  • Validate the input for Hours Traveled to make sure the data entered is greater than zero and not more than 50. If not, display an appropriate error message to the user, set the focus back to the text box causing the error, and either clear the text box or select all the data entered into it so that it can be replaced.
  • Implement the following fields:
    • Total Distance which accumulates the distance for each entry (i.e., as shown in the ListBox control)
    • Total Hours Traveled which accumulates the hours traveled for each entry (i.e., as entered in the Hours Traveled TextBox control)
    • Total Trips which counts each entry (i.e., incremented each time the user clicks the Calculate Button control)
  • Display appropriate output to the ListBox control as shown in the sample input-output document attached.
  • Display Total Distance as a number with two-decimal places.
  • Display Total Hours Traveled and Total Trips as a number with no decimal places.
  • Calculate and display the Average Distance which is the Total Distance divided by the Total Trips (recall, average distance is not an accumulator or counter) formatted as a number with two-decimal places.

The program MUST include standard features of a Windows application including:

  • Change the default Text property of the form to something descriptive
  • Appropriate naming conventions for all controls (i.e., buttons, labels, text boxes, list). The standard naming convention is descriptive name including control type using camelCase notation. For example: hoursTraveledTextBox, distanceListBox, totalHoursTraveledLabel, exitButton. The exception is controls not referenced in the code-behind of Form1. For example, Label controls used for descriptive purposes only or PictureBox controls used for aesthetic purposes only.
  • Calculate, Clear, and Exit buttons with appropriate name and keyboard access key
  • AcceptButton and CancelButton properties should be appropriately assigned to the Calculate button and Clear button, respectively
  • Ensure tab order for form is logical
  • When Clear button is clicked the controls outside of the Summary GroupBox control should be cleared (i.e. using the Clear method or assigning an empty string) and the focus set back to the first TextBox control for entering data. The controls inside the Summary GroupBox control should NOT be cleared (i.e., using the Clear method or assigning an empty string). Do NOT reset the values of the fields to zero.
  • Appropriate naming conventions and data type declarations for variables and fields.
  • Remove all unused event handlers from the program code.

2. Name your project using the naming convention provided in the syllabus: CourseNumber_LastNameFirstInitial_LabXX (e.g., 3333_SharpJ_Lab04)

3. Include the appropriate identification information per the course syllabus using comment statements at the top of your project code (see p. 102, 2.8 Comments, Blank Lines, and Indentation): Name, 9-Digit ID, Due Date, Date Submitted, and Brief Description of Program.

4. You will need to zip/compress the project folder using an appropriate zip/compression utility such as the one found in the Windows or WinZip, etc. Please DO NOT submit .rar (archive) files.

5. Attach and submit the zipped/compressed project folder file under the Lab 04 link under Assessments in the Chapter 5 Module.

6. See Revised Form based on Additional Requirements below. A PDF document with sample input-output is attached:

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions