Wednesday, September 29, 2010

Assignment 1

Here is the xaml code
<Window x:Class="Assignment1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="436" Width="479">
<Grid Background="CornflowerBlue">
<Label Height="28" HorizontalAlignment="Left" Margin="25,40,0,0" Name="label1" VerticalAlignment="Top" Width="132">Enter Beginning Miles</Label>
<TextBox Height="22" Margin="183,40,153,0" Name="txtBeginningMiles" VerticalAlignment="Top" />
<Label Height="28" HorizontalAlignment="Left" Margin="38,88,0,0" Name="label2" VerticalAlignment="Top" Width="120">Enter Ending Miles</Label>
<TextBox Height="23" Margin="185,88,153,0" Name="txtEndingMiles" VerticalAlignment="Top" />
<Label Height="28" HorizontalAlignment="Left" Margin="38,135,0,0" Name="label3" VerticalAlignment="Top" Width="120">Cost Per Gallon</Label>
<TextBox Height="23" Margin="185,135,153,0" Name="txtCostPerGallon" VerticalAlignment="Top" />
<Label HorizontalAlignment="Left" Margin="38,181,0,189" Name="label4" Width="120">Number of Gallons</Label>
<TextBox Margin="185,181,153,194" Name="txtGallons" />
<Button Height="23" HorizontalAlignment="Left" Margin="49,0,0,135" Name="button1" VerticalAlignment="Bottom" Width="75" Click="button1_Click">Calc</Button>
<Label Height="28" HorizontalAlignment="Left" Margin="49,0,0,88" Name="label5" VerticalAlignment="Bottom" Width="120">Miles Per Gallon</Label>
<Label Height="28" Margin="196,0,142,88" Name="lblMilesPerGallon" VerticalAlignment="Bottom">Label</Label>
<Label Height="28" HorizontalAlignment="Left" Margin="49,0,0,50" Name="label6" VerticalAlignment="Bottom" Width="120">Cost per Mile</Label>
<Label Height="28" Margin="0,0,142,50" Name="lblCostPerMile" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="119">Label</Label>
</Grid>
</Window>

Here is the C Sharp code
using System;
using System.Collections.Generic;
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 Assignment1
{
///
/// Steve Conger
/// 9/29/2010
/// Assignment 1
///

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

private void button1_Click(object sender, RoutedEventArgs e)
{
//get the input
double beginningMiles;
beginningMiles = double.Parse(txtBeginningMiles.Text);
double endingMiles = double.Parse(txtEndingMiles.Text);
double costPerGallon = double.Parse(txtCostPerGallon.Text);
double gallonsPurchased = double.Parse(txtGallons.Text);

//converting input to output
double totalMiles = endingMiles - beginningMiles;
double milesPerGallon = totalMiles / gallonsPurchased;
double costPerMile = costPerGallon / milesPerGallon;

//output
lblMilesPerGallon.Content = milesPerGallon.ToString();
lblCostPerMile.Content = costPerMile.ToString("c");
}
}
}

No comments:

Post a Comment