Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Based on this program visual C# Modify project according to the requirements below Modify your existing application so that the final bill includes the gas

Based on this program visual C# Modify project according to the requirements below

Modify your existing application so that the final bill includes the gas tax based on the user's state as follows: If the user enters the state of Michigan, then the tax amount is 0.26 cents per gallon. If a user enters the state Ohio, then the tax amount is 0.28 cents per gallon. For anything else, the tax amount is 0.48 cents per gallon. The final output should be exactly as follows: The price of a gallon of gas in Ypsilanti Michigan, is $x.xx (including 0.26 cents tax per gallon). It costs $x.xx to drive xxx miles. Also, add a checkbox to you form. If the box is checked, then the final amount will be rounded to the nearest dollar (i.e. 0 decimal spaces instead of 2 decimal spaces).

Here is the Modify your existing application Code C# Program

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 GasBillCalculator { public partial class Form1 : Form { public Form1() { InitializeComponent(); }

private void btnExit_Click(object sender, EventArgs e) { //Button click event for Exit Button Application.Exit(); }

private void Form1_Load(object sender, EventArgs e) { //Clear the lables, Error and out put lblErr.Text = ""; lblOutput.Text = ""; }

private void btnCalculate_Click(object sender, EventArgs e) { //Button Click Event for Calculate Button

//Variable declarations string city, state; int distance = 0; double price = 0; //To store price double totalcost = 0; //To store calculated totalcost

//Clear the lables, Error and out put lblErr.Text = ""; lblOutput.Text = "";

city = txtCity.Text; state = txtState.Text;

string d,p; //Store distance and price to string variables to check valid or not d= txtDistance.Text; p = txtPrice.Text; int test; double test1; //To check distance value is valid if (int.TryParse(d, out test) == false) { lblErr.Text = "Invalid Distance";

} //To Check Price is Valid else if (double.TryParse(p, out test1) == false) { lblErr.Text = "Invalid Price"; } else { //Calculate total cost distance = Convert.ToInt32(txtDistance.Text); //convert(txtDistance.Text,); price = Convert.ToDouble(txtPrice.Text); totalcost = (distance / 23.6) * price; totalcost = Math.Round(totalcost, 2); //Round to 2 decimal points

//Display output lblOutput.Text = "The price of a gallon of gas in " + city + " " + state + ", is $" + price + ". It costs $" + Convert.ToString(totalcost) + " to drive " + distance + " miles."; } }

} }

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

Recommended Textbook for

MongoDB Applied Design Patterns Practical Use Cases With The Leading NoSQL Database

Authors: Rick Copeland

1st Edition

1449340040, 978-1449340049

More Books

Students also viewed these Databases questions

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago