Question: c# ... complete the following code by overriding the following methods: The three methods you will need to override are: -string From() This method returns

c# ... complete the following code by overriding the following methods:

The three methods you will need to override are:

-string From()

This method returns a string indicating the unit this converter converts from. For example, the MetresToCentimetres class will return "Metres".

-string To()

This method returns a string indicating the unit this converter converts to. For example, the MetresToCentimetres class will return "Centimetres".

-float Convert(float value)

This method converts 'value' to whatever this converter converts things to and returns the result. For example:

Converter converter = new MetresToCentimeters(); Console.WriteLine("1 metre in centimetres is {0}", converter.Convert(1)); 

will print "1 metre in centimetres is 100".

The public classes you have to write for this exercise are:

-MetresToCentimetres (centimetres = 100 * metres)

-CelsiusToFahrenheit (fahrenheit = celsius * 9 / 5 + 32)

-MilesToKilometres (kilometres = miles * 1.609344)

-DegreesToRadians (radians = degrees * Math.PI / 180)

given the code...

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace Converters { public abstract class Converter { public abstract string From();

public abstract string To();

public abstract float Convert(float value); }

// Write your converter classes here // ... class Program { static void Main(string[] args) { bool running = true; bool inputValid; int menuOption; float fromValue;

List converters = new List();

// Uncomment these to test out new classes as you implement them //converters.Add(new MetresToCentimetres()); //converters.Add(new CelsiusToFahrenheit()); //converters.Add(new MilesToKilometres()); //converters.Add(new DegreesToRadians());

while (running) { Console.WriteLine(" Conversion Menu"); Console.WriteLine("-------------------"); Console.WriteLine(); for (int i = 0; i < converters.Count; i++) { Console.WriteLine("{0}. {1} to {2}", i + 1, converters[i].From(), converters[i].To()); }

Console.WriteLine();

do { Console.Write("Choose a converter (or type 0 to exit): "); inputValid = int.TryParse(Console.ReadLine(), out menuOption); if (!inputValid || menuOption < 0 || menuOption > converters.Count) { inputValid = false; Console.WriteLine("Invalid option."); } } while (!inputValid);

if (menuOption == 0) { running = false; } else { Converter currentConverter = converters[menuOption - 1]; Console.WriteLine("Converting from {0} to {1} ", currentConverter.From(), currentConverter.To()); do { Console.Write("Enter input ({0}): ", currentConverter.From());

inputValid = float.TryParse(Console.ReadLine(), out fromValue); if (!inputValid) { Console.WriteLine("Invalid value."); } } while (!inputValid);

float result = currentConverter.Convert(fromValue); Console.WriteLine("Result ({0}): {1}", currentConverter.To(), result); }

} } } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!