using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CSD03
{
class Program
{
static void Main(string[] args)
{
IEnumerable<ProductDataItem> productDataItems = ProductData.GetData();
IEnumerable<StockDataItem> stockDataItems = StockData.GetData();
// TODO: write LINQ statements and output result.
var query = from p in productDataItems
join s in stockDataItems
on p.ProductID equals s.ProductID
select new
{
id = p.ProductID,
stock = s.Stock,
cost = p.Cost,
amount = s.Stock * p.Cost
};
int c1, c2, c3, c4, c5,c6;
c1 = c2 = c3 = c4 = c5 = c6 = 0;
foreach (var row in query)
{
switch ( GetAmountFlag(row.amount))
{
case 1:
c1++;
break;
case 2:
c2++;
break;
case 3:
c3++;
break;
case 4:
c4++;
break;
case 5:
c5++;
break;
default:
break;
}
}
Console.WriteLine("Amount < 10000:"+c1);
Console.WriteLine("Amount between 10000 and 50000:" + c2);
Console.WriteLine("Amount between 50000 and 150000:" + c3);
Console.WriteLine("Amount between 110000 and 250000:" + c4);
Console.WriteLine("Amount between 250000 and 500000:" + c5);
Console.WriteLine("Amount >= 500000:" + c6);
Console.ReadLine();
}
private static int GetAmountFlag(int Amount)
{
if (Amount < 10000)
return 1;
else if (Amount >= 10000 && Amount < 50000)
return 2;
else if (Amount >= 50000 && Amount < 150000)
return 3;
else if (Amount >= 150000 && Amount < 250000)
return 4;
else if (Amount >= 250000 && Amount < 500000)
return 5;
else
return 6;
}
}
}
留言列表