Use C# to create a class called moneyConverter that converts US dollar to other
ID: 671730 • Letter: U
Question
Use C# to create a class called moneyConverter that converts US dollar to other currencies. This class has one instance variable: amount in US dollar (type decimal). Provide a property with get and set accessors for this instance variable. If the value passed to the set accessor is negative, the value of the instance variable should be left unchanged. Your class should have a constructor that initializes the instance variable. In addition, provide two methods: ToEuro, which converts the amount from US dollar to Euro, ToPound, which converts the amount from US dollar to British Pound. The conversion rate for Euro is 0.74 (i.e. 1 US dollar = 0.74 Euro), while the conversion rate for Pound is 0.63 (i.e. 1 US dollar = 0.63 Pound). Write a test application named moneyConverterTest that demonstrates class moneyConverter’s capabilities. In this test application, ask the user to enter amount in US dollar. Use it to create a moneyConverter object. Use the ToEuro method and the ToPound methods to calculate the equivalent amount in Euro and Pound. Display these values.
Explanation / Answer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace money_ConverterTest
{
public class moneyConverter
{
private int amount;
public int cons
{
get
{
return amount;
}
set
{
if(value>0)
amount = value;
}
}
public moneyConverter()
{
amount = 0;
}
public void ToEuro()
{
double eu;
eu = 0.74 * amount;
Console.WriteLine("Euro =" + eu);
}
public void ToPound()
{
double po;
po = 0.63 * amount;
Console.WriteLine("Pound =" + po);
}
}
class Program
{
static void Main(string[] args)
{
moneyConverter o = new moneyConverter();
Console.WriteLine("Enter amount in Dollar");
o.cons = Convert.ToInt32 ( Console.ReadLine());
o.ToEuro();
o.ToPound();
Console.ReadKey();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.