Exemplo n.º 1
0
        static void Main(string[] args)
        {
            CurrencyTypes Type;
            int am = 0;
            int i = 0;
            Money [] money = new Money[2];
            Money result = new Money();

            do
            {
                Console.WriteLine(@"Chose the money type:
1. UAH;
2. USD;
3. EU;");
                int num = int.Parse(Console.ReadLine());
                for (Type = CurrencyTypes.UAH; Type <= CurrencyTypes.EU; Type++)
                {
                    if ((int)Type == num)
                    {
                       // type = Convert.ToString(Type);
                        Console.WriteLine("Enter Amount: ");
                        am = int.Parse(Console.ReadLine());
                        money[i] = new Money(am, Type);
                        i++;
                    }
                }
            } while (i < 2);

            int number = 0;           
            do
            {
                Console.WriteLine(@"Enter money operations:
1. Add 2 objects of Money;
2. Add 1st object of Money and double;
3. Decrease 2nd object of Money by 1; 
4. Increase 1st object of Money;
5. Compare 2 objects of Money;
6. Compare 2nd object of Money and string;
7. Convert 1st object of Money to string; 
8. Check CurrencyType of every object;
9. Exit;");

                number = int.Parse(Console.ReadLine());
                switch(number)
                {
                    case 1:
                        if (money[0].CurrencyType == money[1].CurrencyType)
                        {
                            result = money[0] + money[1];
                            Console.WriteLine("Result: "+ result.Amount + " " + money[0].CurrencyType);
                        }
                        else Console.WriteLine("Error. Impossible to add " + money[0].CurrencyType + " and " + money[1].CurrencyType);
                        break;
                    case 2:
                        Console.WriteLine("Enter the number: ");
                        double d = double.Parse(Console.ReadLine());
                        result.Amount = d + money[0].Amount;
                        Console.WriteLine("Result: " + result.Amount + " " + money[0].CurrencyType);
                        break;
                    case 3:
                        for (int j = 0; j < money[1].Amount; j++ )
                        {
                            result.Amount = money[1].Amount--;
                            Console.WriteLine("Step "+ j + " Result: " + result.Amount + " " + money[1].CurrencyType);
                            if (j == 2) break;
                        }                            
                        break;
                    case 4:
                        Console.WriteLine("Enter the number: ");
                        int k = int.Parse(Console.ReadLine());
                        result.Amount = money[0].Amount * k;
                        Console.WriteLine("Result: " + result.Amount + " " + money[0].CurrencyType);                       
                        break;
                    case 5:
                        if (money[0].CurrencyType == money[1].CurrencyType)
                        {
                            if (money[0].Amount < money[1].Amount) Console.WriteLine(money[0].Amount + " " + money[0].CurrencyType + " < " + money[1].Amount + " " + money[1].CurrencyType);
                            else Console.WriteLine(money[0].Amount + " " + money[0].CurrencyType + " > " + money[1].Amount + " " + money[1].CurrencyType);
                        }
                        else Console.WriteLine("Error.  Compare 2 objects of Money");
                            break;
                    case 6:
                            Console.WriteLine("Enter the string: ");
                            string str = Console.ReadLine();
                            string compare1 = money[0];
                            string compare2 = money[1];
                            if(string.Compare(str, compare1)>0) Console.WriteLine(money[0].Amount + " < " + str);
                            else Console.WriteLine(money[0].Amount + " > " + str);
                            if(string.Compare(str, compare2)>0) Console.WriteLine(money[1].Amount+" < "+str);
                            else Console.WriteLine(money[1].Amount + " > " + str);                           
                            break;
                    case 7:
                            string con_1obj = money[0];
                            Console.WriteLine(con_1obj);                                                  
                        break;

                    case 8:
                        for (int jj = 0; jj < money.Length; jj++ )
                            {
                                 if (money[jj]) Console.WriteLine(money[jj].CurrencyType + "True");
                                 else Console.WriteLine("False");
                            }
                        break;
                   
                }  
                 
            } while (number != 9);             
           
        }
Exemplo n.º 2
0
 public static Money operator * (Money ob, int k)
 {
     Money res_decrease = new Money();
     res_decrease.Amount = k * ob.Amount;                   
     return res_decrease;
 }
Exemplo n.º 3
0
               //public static double operator +(double d, Money ob)
               //{                 
               //    double d2 = d + ob.Amount;
               //    return d2;

               //}
               public static Money operator-- (Money ob)
               {
                   Money res_decrease = new Money();
                   res_decrease.Amount = ob.Amount - 1;
                   return res_decrease;
               }
Exemplo n.º 4
0
 public static double operator +(Money ob, double d)
 {
     Money res1_add = new Money();
     res1_add.Amount = ob.Amount + d;
     return res1_add.Amount;
 }
Exemplo n.º 5
0
 public static Money operator + (Money ob1, Money ob2)
 {
         Money res_add = new Money();
         res_add.Amount = ob1.Amount + ob2.Amount;
         return res_add;                                  
 }
Exemplo n.º 6
0
 public bool chektype(Money ob1, Money ob2)
 {                   
     if (ob1.CurrencyType == ob2.CurrencyType ) return true;
     else return false;
 }