Thursday, September 30, 2010

First assignment Morning class

Here is the program planner

What is the main purpose of your program?
To calculate miles per gallon and cost per mile
What is the output for your program?
miles per gallon
Cost per mile

What is the input needed to get that output?
total miles (beginning and ending miles
price per gallon
total gallons

What steps are required to convert the input into the output (algorithm)?
Miles per gallon = total miles / total gallons
cost per mile= price per gallon/miles per gallon

How will you test that the output is correct?
Test it against data where you know answer

Here is the WPF form xaml:

<:Window x:Class="GasCalculator.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" Background="#FF8F8FE3">
<Grid>
<Label Content="Total Miles" Height="38" HorizontalAlignment="Left" Margin="21,25,0,0" Name="label1" VerticalAlignment="Top" Width="144" FontSize="18" />
<TextBox Height="23" HorizontalAlignment="Right" Margin="0,33,212,0" Name="txtTotalMiles" VerticalAlignment="Top" Width="120" />
<Label Content="Price Per Gallon" FontSize="18" Height="38" HorizontalAlignment="Left" Margin="21,79,0,0" Name="label2" VerticalAlignment="Top" Width="144" />
<TextBox Height="23" HorizontalAlignment="Right" Margin="0,87,212,0" Name="txtPricePerGallon" VerticalAlignment="Top" Width="120" />
<Label Content="Total Gallons" FontSize="18" Height="38" HorizontalAlignment="Left" Margin="21,123,0,0" Name="label3" VerticalAlignment="Top" Width="144" />
<TextBox Height="23" HorizontalAlignment="Right" Margin="0,0,212,157" Name="txtTotalGallons" VerticalAlignment="Bottom" Width="120" />
<Button Content="Calculate" Height="29" HorizontalAlignment="Left" Margin="35,189,0,0" Name="btnCalculate" VerticalAlignment="Top" Width="75" Click="btnCalculate_Click" />
<Label Content="Label" Height="38" HorizontalAlignment="Left" Margin="162,191,0,0" Name="lblMilesPerGallon" VerticalAlignment="Top" Width="264" FontSize="18" />
<Label Content="Label" Height="33" HorizontalAlignment="Left" Margin="162,235,0,0" Name="lblCostPerMile" VerticalAlignment="Top" Width="245" FontSize="18" />
</Grid>
</Window>

Here is the c# code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace GasCalculator
{
///
/// Steve Conger
/// Assignment 1
/// 9/30/2010
/// This program calculate miles per gallon
/// and price per mile
///

public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}

private void btnCalculate_Click(object sender, RoutedEventArgs e)
{
//get input
double totalMiles= double.Parse(txtTotalMiles.Text);
double pricePerGallon = double.Parse(txtPricePerGallon.Text);
double totalGallons = double.Parse(txtTotalGallons.Text);

//transform input to output
double milesPerGallon = totalMiles / totalGallons;
double pricePerMile = pricePerGallon / milesPerGallon;

//output the results
lblMilesPerGallon.Content = "The miles per gallon is " + milesPerGallon.ToString();
lblCostPerMile.Content = "The cost per mile is " + pricePerMile.ToString("c");

}


}
}

No comments:

Post a Comment