C#oop chapter two on the machine 2

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace chapter02
{ class Menu { public static void Main(string[] args) { //Initialize the object Computer[] com = new Computer[3]; Computer com1 = new Computer(); com1.Type = "hpCQ-217TX"; com1.BuyDate = "2013-10-5"; com[0] = com1; Computer com2 = new Computer(); com2.Type = "Mc240CH/A"; com2.BuyDate = "2013-10-5"; com [1] = com2; Computer com3 = new Computer(); com3.Type = "SYNW18H/W"; com3.BuyDate = "2013-10-5"; com[2] = com3; Console.WriteLine(" Set up computer ID before ***"); Console.WriteLine("computer model\tcomputer ID\tpurchase time");




















for (int i = 0; i < com.Length; i++)
{
Console.WriteLine("{0}\t\t\t{1}",com[i].Type,com[i].BuyDate);
}

        Console.WriteLine("加上计算机id后");
        Ran rr = new Ran();
        rr.getid(com);

        Console.WriteLine("***************设置计算机ID后******************");
        Console.WriteLine("计算机型号\t计算机ID\t购买时间");
        for (int i = 0; i < com.Length ; i++)
        {
            Console.WriteLine("{0}\t{2}\t\t{1}", com[i].Type, com[i].BuyDate,com[i].ID);
        }
    }
}

}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace chapter02
{
public class Ran
{
public void getid(Computer[] com)
{
Random rand = new Random();

        for (int i = 0; i < com.Length; i++)
        {
            com[i].ID = com[i].Type + "-" + rand.Next(1000, 9999);
            int a = rand.Next(1000,10000);
        }
    }
}

}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace chapter02
{ public class Computer { public string Type;//Model public string ID;//id public string BuyDate;//Purchase date




}

}

Guess you like

Origin blog.csdn.net/Ccccccccyq/article/details/113001818