Advertisement
PetyoKamenov

Untitled

Jun 18th, 2014
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.24 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8.  
  9.  
  10. namespace MarketPlace
  11. {
  12.     public class Program
  13.     {
  14.         public class myReverserClass : IComparer
  15.         {
  16.  
  17.  
  18.             int IComparer.Compare(Object mProduct, Object mPrice)
  19.             {
  20.                 return ((new CaseInsensitiveComparer()).Compare(mProduct, mPrice));
  21.             }
  22.  
  23.             static void Main(string[] args)
  24.             {
  25.  
  26.                 Console.Write("How many product you will buy : ");
  27.                 int n = int.Parse(Console.ReadLine());
  28.                 string[] mProduct = new string[n];
  29.                 double[] mPrice = new double[n];
  30.                 for (int i = 0; i < mProduct.Length; i++)
  31.                 {
  32.                     Console.Write("Enter your product :");
  33.                     mProduct[i] = Console.ReadLine();
  34.                 }
  35.                 for (int j = 0; j < mPrice.Length; j++)
  36.                 {
  37.                     Console.Write("Enter your price :");
  38.                     mPrice[j] = double.Parse(Console.ReadLine());
  39.                 }
  40.                 Console.WriteLine("1 for Product sort Or 2 for price sort :");
  41.                 int choice = int.Parse(Console.ReadLine());
  42.                 switch (choice)
  43.                 {
  44.                     case 1:
  45.                         Array.Sort(mProduct);
  46.                         Console.WriteLine("Product sort :");
  47.                         PrintProductsAndPrices(mProduct, mPrice);
  48.  
  49.                         break;
  50.                     case 2:
  51.                         Array.Sort(mPrice);
  52.                         Console.WriteLine("Price sort:");
  53.                         PrintProductsAndPrices(mProduct, mPrice);
  54.  
  55.                         break;
  56.                         Console.WriteLine();
  57.                 }
  58.  
  59.             }
  60.  
  61.             private static void PrintProductsAndPrices(string[] mProduct, double[] mPrice)
  62.             {
  63.  
  64.                 for (int i = 0; i < mProduct.Length; i++)
  65.                 {
  66.                     Console.WriteLine("   {0,-10}: {1}", mProduct[i], mPrice[i]);
  67.                 }
  68.                 Console.WriteLine();
  69.             }
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement