Machine Exercise 2 generate computer ID, machine id
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Using System. Threading. Tasks;
Namespace MyID
{
Class Computer
{
Private string type;
Public string Type
{
Get {return type ;}
Set {type = value ;}
}
Private string id;
Public string Id
{
Get {return id ;}
Set {id = value ;}
}
Private string buyDate;
Public string BuyDate
{
Get {return buyDate ;}
Set {buyDate = value ;}
}
}
}
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Using System. Threading. Tasks;
Namespace MyID
{
Class Manner
{
Public void setID (Computer [] comps)
{
Random random = new Random ();
Foreach (Computer item in comps ){
Item. Id = item. Type + "-" + random. Next );
}
}
}
}
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Using System. Threading. Tasks;
Namespace MyID
{
Class Program
{
Static void Main (string [] args)
{
Manner myManner = new Manner ();
Computer [] commp Uter = new Computer [3] {
New Computer (),
New Computer (),
New Computer ()
};
Commp Uter [0]. Type = "hpCq-217Tx ";
Commp Uter [0]. BuyDate = "2013-10-5 ";
Commp Uter [1]. Type = "Mc240CH/";
Commp Uter [1]. BuyDate = "2014-11-11 ";
Commp Uter [2]. Type = "SYNW18H/w ";
Commp Uter [2]. BuyDate = "2020-11-22 ";
Console. WriteLine ("************* before setting the computer ID *************");
Console. WriteLine ("computer model \ t computer ID \ t purchase time ");
Foreach (Computer item in commp Uter)
{
Console. WriteLine ("{0} \ t {1} \ t {2}", item. Type, item. Id, item. BuyDate );
}
Console. WriteLine ("\ n ");
MyManner. setID (comatrix Uter );
Console. WriteLine ("************* after setting the computer ID *************");
Console. WriteLine ("computer model \ t computer ID \ t purchase time ");
Foreach (Computer item in commp Uter ){
Console. WriteLine ("{0} \ t {1} \ t {2}", item. Type, item. Id, item. BuyDate );
}
Console. ReadLine ();
}
}
}