โดยจะมี class AirCondition เพื่อเป็นต้นแบบของวัตถุ
เมื่อรับค่าเสร็จก็จะแสดงค่า BTU ของ air แต่ละตัวผ่าน method getBTU()
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
List<AirCondition> air = new List<AirCondition>();
int n = 1, width, high, length, var;
while (n <= 10)
{
Console.WriteLine("Enter properties of air{0}/10 :", n);
Console.WriteLine("Enter width : ");
string s_width = Console.ReadLine();
Console.WriteLine("Enter high : ");
string s_high = Console.ReadLine();
Console.WriteLine("Enter length : ");
string s_length = Console.ReadLine();
Console.WriteLine("Enter var : ");
string s_var = Console.ReadLine();
if (int.TryParse(s_width, out width) && int.TryParse(s_high, out high) && int.TryParse(s_length, out length) && int.TryParse(s_var, out var))
{
AirCondition temp = new AirCondition(width, high, length, var);
air.Add(temp);
n++;
}
else
{
Console.WriteLine("Please enter again!!");
}
}
n = 1;
foreach (AirCondition ob in air)
{
Console.WriteLine("BTU of air{0}/10 : {1}", n, ob.getBTU());
n++;
}
Console.WriteLine("Press any key to stop...");
Console.ReadKey();
/*AirCondition air = new AirCondition(5,3,5,400);
double value = air.getBTU();
Console.WriteLine("BTU : {0}", value);
Console.WriteLine("Press any key to stop...");
Console.ReadKey();
*/
}
}
class AirCondition
{
public int width;
public int high;
public int length;
public int var;
public AirCondition()
{
width = 0;
high = 0;
length = 0;
var = 0;
}
public AirCondition(int width,int high, int length, int var)
{
this.width = width;
this.high = high;
this.length = length;
this.var = var;
}
public double getBTU()
{
return (width * high * length * var) / 3;
}
}
}
--------------------------------------------------
ไม่มีความคิดเห็น:
แสดงความคิดเห็น