Computer Science hw31st
Homework 31: 15points + 5 points for output
Based on the following class diagram create a class called Distance in your ConsoleApplication. Program Class will be with the Main() method which will be the starting point. Your output should be displayed as following. Fill in the blanks before you compile and run the program.
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
___________ d = new ______________();
__________________("Enter any distance in meters");
d._____________ = __________________(Console.ReadLine());
Console.WriteLine(d.__________________);
Console.WriteLine();
d.Quit();
Console.Read();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Distance
{
private double distanceInMeters;
public Distance()
{
}
public double meters
{
get
{
return __________________;
}
set
{
____________________ = value;
}
}
public double ConvertToKilometers()
{
double kilometers = ____________________ * 0.01;
return _______________;
}
public double ConvertToInches()
{
double inches = ________________________ * 39.37;
return ____________;
}
public double ConvertToFeet()
{
double feet = _______________________ * 3.281;
return ___________;
}
public void Quit()
{
Console.WriteLine("Please press Enter to quit");
}
public override string ToString()
{
Console.WriteLine("{0} meters is also: ", _____________________);
Console.WriteLine();
return
ConvertToKilometers().ToString("f2") + " Kilometers: " + "\t" + ConvertToInches().ToString("f2") + " Inches: " + "\t" + ConvertToFeet().ToString("f2") + " feet";
}
}
}
COSC 1436: C# Page 1