[Examination] C# - Chương trình quản lý đội thi TechWiz toàn cầu Apptech Ấn Độ - C#
Trong cuộc thi Techwiz toàn cầu do Aptech Ấn Độ tổ chức. Có rất nhiều các đội ở các trung tâm Aptech trên toàn cầu cùng tham gia. Bạn được yêu cầu viết chương trình quản lý thông tin đội chơi và thông tin dự án của từng đội.
Yêu cầu:
1) Tạo lớp đối tượng Project gồm các trường thông tin: string name (tên đề tài), string projectType: Nhóm dự án (group chỉ nhận 3 giá trị là Development & Design Website, Website Developer, Application Developer) - 1 điểm
2) Tạo lớp đối tượng Group gồm các thuộc tính: string name (tên nhóm), string center: tên trung tâm aptech, project (kiểu dữ liệu là Project) - 1 điểm
Viết getter/setter cho tất cả các thuộc tính của lớp đối tượng - 1 điểm
Viết hàm Input, Display của đối tượng trên - 2 điểm
Tạo class Program có chưa 1 method Main. Yêu cầu khai báo mảng List<Group> groupList. Yêu cầu nhập vào ngẫu nhiên N nhóm (N có giá trị từ 2 tới 10) - 5 điểm
Tạo 1 delegate như sau
delegate void ShowInfor();
Khai báo 1 đối tượng delegate ShowInfor -> Thực hiện quản lý tất cả các phương thức Display() của tất cả các đối tượng Project trong đối tượng này. Yêu cầu gọi thực thi delegate vừa được tạo ra. - 5 điểm
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)
![Hieu Ngo [community,C2009G]](https://www.gravatar.com/avatar/cee2973101b9cf9580ef561ff3eeecf0.jpg?s=80&d=mm&r=g)
Hieu Ngo
2021-10-28 04:10:24
#Group.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace TechWiz
{
class Group
{
public string Name { get; set; }
public string Center { get; set; }
public Project project { get; set; }
public Group()
{
project = new Project();
}
public Group(string name, string center, Project project)
{
Name = name;
Center = center;
this.project = project;
}
public void Input()
{
Console.WriteLine("Enter name:");
Name = Console.ReadLine();
Console.WriteLine("Enter Center:");
Center = Console.ReadLine();
project.Input();
}
public void Display()
{
Console.WriteLine("Name: {0}, Center: {1}", Name, Center);
project.Diplay();
}
}
}
#Program.cs
using System;
using System.Collections.Generic;
namespace TechWiz
{
class Program
{
delegate void ShowInfor();
public static List<Group> groupList = new List<Group>();
static void Main(string[] args)
{
int n;
do
{
Console.WriteLine("Enter N >=2 && n< 10");
n = int.Parse(Console.ReadLine());
if(n>=2 && n <= 10)
{
for (int i = 0; i < n; i++)
{
Group group = new Group();
group.Input();
groupList.Add(group);
}
} else
{
Console.WriteLine("Error");
}
} while (n < 2 || n > 10);
ShowInfor showInfor = null;
foreach (Group group in groupList)
{
showInfor += group.Display;
}
showInfor();
}
}
}
#Project.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace TechWiz
{
class Project
{
public string Name { get; set; }
public string ProjectType { get; set; }
public Project() { }
public Project(string name, string projectType)
{
Name = name;
ProjectType = projectType;
}
public void Input()
{
Console.WriteLine("Enter Name:");
Name = Console.ReadLine();
Console.WriteLine("Chon loai de tai: ");
string[] options = { "Development & Design Website",
"Website Developer", "Application Developer" };
for (int i = 1; i <= options.Length; i++)
{
Console.WriteLine("{0}. {1}", i, options[i - 1]);
}
Console.WriteLine("Chon: ");
int choose = int.Parse(Console.ReadLine());
if (choose < 1 || choose > options.Length)
{
choose = options.Length;
}
ProjectType = options[choose - 1];
}
public void Diplay()
{
Console.WriteLine("Name: {0}, Project Type: {1}", Name, ProjectType);
}
}
}
![Nguyễn Hùng Anh [community,C2009G]](https://www.gravatar.com/avatar/32d1c530d2d2c1f3cd46282949f78ebf.jpg?s=80&d=mm&r=g)
Nguyễn Hùng Anh
2021-10-28 04:08:50
#Group.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace Bt2312
{
class Group
{
public string Name { get; set; }
public string Center { get; set; }
public Project Project { get; set; }
public Group()
{
Project = new Project();
}
public Group(string name, string center, Project project)
{
Name = name;
Center = center;
Project = project;
}
public void Input()
{
Console.WriteLine("Enter group name: ");
Name = Console.ReadLine();
Console.WriteLine("Enter Aptech center: ");
Center = Console.ReadLine();
Console.WriteLine("Enter project name: ");
Project.Name = Console.ReadLine();
Console.WriteLine("Enter project type: ");
Project.ProjectType = Console.ReadLine();
}
public void Display()
{
Console.WriteLine("=============================");
Console.WriteLine("Group name: {0}, center: {1}, project name: {2}, type: {3}"
, Name, Center, Project.Name, Project.ProjectType);
}
}
}
#Program.cs
using System;
using System.Collections.Generic;
namespace Bt2312
{
delegate void ShowInfor();
class Program
{
static List<Group> groupList;
static void Main(string[] args)
{
groupList = new List<Group>();
Console.WriteLine("Enter N groups to add: ");
int N = int.Parse(Console.ReadLine());
if (N >= 2 && N <= 10)
{
for (int i = 0; i < N; i++)
{
Group group = new Group();
group.Input();
groupList.Add(group);
}
}
else
{
Console.WriteLine("Pls enter N from 2 to 10");
}
ShowInfor showInfor = delegate {
foreach (Group group in groupList)
{
group.Display();
}
};
showInfor();
}
}
}
#Project.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace Bt2312
{
class Project
{
public string Name { get; set; }
private string _projectType;
public string ProjectType
{
get
{
return this._projectType;
}
set
{
if(value == "Development & Design Website" || value == "Website Developer"
|| value == "Application Developer")
{
this._projectType = value;
} else
{
Console.WriteLine("Project type must be: Development & Design Website," +
"Website Developer or Application Developer");
}
}
}
public Project()
{
}
public Project(string name, string projectType)
{
Name = name;
ProjectType = projectType;
}
public void Input()
{
Console.WriteLine("Enter project name: ");
Name = Console.ReadLine();
Console.WriteLine("Enter project type: ");
ProjectType = Console.ReadLine();
}
public void Display()
{
Console.WriteLine("Project name: {0}, type: {1}", Name, ProjectType);
}
}
}
![Đào Mạnh Dũng [C2010L]](https://www.gravatar.com/avatar/6a111fa53fd75dc87034660a8857df16.jpg?s=80&d=mm&r=g)
Đào Mạnh Dũng
2021-10-23 13:44:12
#Group.cs
namespace _2312
{
internal class Group
{
public string name { get; set; }
public string center { get; set; }
public Project project { get; set; }
public Group()
{
}
public Group(string name, string center, Project project)
{
this.name = name;
this.center = center;
this.project = project;
}
public void Input()
{
System.Console.WriteLine("nhap name");
this.name = System.Console.ReadLine();
System.Console.WriteLine("nhap center");
this.center = System.Console.ReadLine();
this.project = new Project();
this.project.Input();
}
public void Display()
{
System.Console.WriteLine(this);
}
public override string ToString()
{
return "Group{" + "name=" + name + ", center=" + center + ", project=" + project + '}';
}
}
}
#Program.cs
using System;
using System.Collections.Generic;
namespace _2312
{
internal class Program
{
private delegate void ShowInfor();
private static void Main(string[] args)
{
List<Group> groupList = new List<Group>();
ShowInfor showInfors = null;
for (int i = 0; i < 10; i++)
{
Group group = new Group();
group.Input();
showInfors += group.Display;
if (i >= 1)
{
Console.WriteLine("co nhap tiep khong Y/N");
if (Console.ReadLine().ToLower().Equals("n"))
{
break;
}
}
}
showInfors();
}
}
}
#Project.cs
namespace _2312
{
internal class Project
{
public string name { get; set; }
private string projectType;
public string ProjectType
{
get
{
return projectType;
}
set
{
switch (value)
{
case "Design Website":
{
projectType = value;
break;
}
case "Website Developer":
{
projectType = value;
break;
}
case "Application Developer":
{
projectType = value;
break;
}
default:
{
while (true)
{
System.Console.WriteLine("gia tri khong ho le! nhap lai");
string val = System.Console.ReadLine();
switch (val)
{
case "Design Website":
{
projectType = val;
return;
}
case "Website Developer":
{
projectType = val;
return;
}
case "Application Developer":
{
projectType = val;
return;
}
}
}
break;
}
}
}
}
public Project()
{
}
public Project(string name, string projectType)
{
this.name = name;
this.ProjectType = projectType;
}
public void Input()
{
System.Console.WriteLine("nhap name");
this.name = System.Console.ReadLine();
System.Console.WriteLine("nhap ProjectType");
this.ProjectType = System.Console.ReadLine();
}
public void Display()
{
System.Console.WriteLine(this);
}
public override string ToString()
{
return "Project{" + "name=" + name + ", projectType=" + projectType + '}';
}
}
}
![PHẠM VĂN LIÊM [C2010G]](https://www.gravatar.com/avatar/dd86ba4e56b73bc1514e889b2ac18c6d.jpg?s=80&d=mm&r=g)
PHẠM VĂN LIÊM
2021-10-20 03:10:34
#Group.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace Test04
{
class Group
{
public string name { get; set; }
public string center { get; set; }
public Project project { get; set; }
public Group()
{
center = "Trung Tam Aptech";
project = new Project();
}
public void Input()
{
Console.WriteLine("Nhap ten nhom");
name = Console.ReadLine();
project.Input();
}
public void Display()
{
Console.Write("Group Name: {0}, Center: {1}", name, center);
project.Display();
}
}
}
#Program.cs
using System;
using System.Collections.Generic;
namespace Test04
{
class Program
{
static List<Group> groupList = new List<Group>();
static void Main(string[] args)
{
int choose;
do
{
ShowMenuU();
choose = Utility.ReadInt();
switch(choose)
{
case 1:
Console.WriteLine("Nhập n nhom muon them");
int n = Utility.ReadInt();
for(int i = 1; i <= n; i++)
{
Console.WriteLine("Nhap thong tin nhom " + i);
Group group = new Group();
group.Input();
groupList.Add(group);
}
break;
case 2:
foreach(Group item in groupList)
{
item.Display();
}
break;
case 3:
Console.WriteLine("Thoat");
break;
default:
Console.WriteLine("Wrong option");
break;
}
} while (choose != 3);
}
static public void ShowMenuU()
{
Console.WriteLine("1:Nhap nhom");
Console.WriteLine("2:Hien thi");
Console.WriteLine("3:Thoat");
}
}
}
#Project.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace Test04
{
class Project
{
public string name { get; set; }
public string groupName { get; set; }
public Project()
{
}
public Project(string name, string groupname)
{
this.name = name;
this.groupName = groupname;
}
public void Input()
{
Console.WriteLine("Nhap ten de tai");
name = Console.ReadLine();
int choose = 0;
while(choose != 1 && choose != 2 && choose != 3)
{
ShowMenu();
choose = Utility.ReadInt();
if(choose == 1)
{
groupName = "Development & Design Website";
} else if(choose == 2)
{
groupName = "Website Developer";
} else if(choose == 3)
{
groupName = "Application Developer";
} else
{
Console.WriteLine("Wrong option!");
}
}
}
public void ShowMenu()
{
Console.WriteLine("1:Development & Design Website.");
Console.WriteLine("2:Website Developer.");
Console.WriteLine("3:Application Developer");
}
public void Display()
{
Console.WriteLine("De tai: {0}, Group name: {1}", name, groupName);
}
}
}
#Utility.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace Test04
{
class Utility
{
public static int ReadInt()
{
int result;
while(true)
{
try
{
result = int.Parse(Console.ReadLine());
return result;
} catch
{
Console.WriteLine("Wrong input!");
}
}
}
}
}
![GokiSoft.com [Teacher]](https://www.gravatar.com/avatar/fc6ba9324e017d540af3613b3a77dd21.jpg?s=80&d=mm&r=g)
GokiSoft.com
2021-10-07 09:26:22
#Project.cs
using System;
namespace BT2312
{
public class Project
{
public string Name { get; set; }
public string GroupName { get; set; }
public Project()
{
}
public void Input()
{
Console.WriteLine("Nhap ten de tai: ");
Name = Console.ReadLine();
Console.WriteLine("Chon loai de tai: ");
Console.WriteLine("1. Development & Design Website");
Console.WriteLine("2. Website Develper");
Console.WriteLine("3. Application Developer");
Console.WriteLine("Chon: ");
int choose = int.Parse(Console.ReadLine());
switch(choose)
{
case 1:
GroupName = "Development & Design Website";
break;
case 2:
GroupName = "Website Develper";
break;
default:
GroupName = "Application Developer";
break;
}
}
public void Display()
{
Console.WriteLine("Ten de tai: {0}, loai: {1}", Name, GroupName);
}
}
}
#Program.cs
using System;
using System.Collections.Generic;
namespace BT2312
{
delegate void ShowInfor();
class Program
{
static List<Group> groupList;
static void Main(string[] args)
{
groupList = new List<Group>();
//Cau 1: Tao ngau nhien N group (2-4)
Random random = new Random();
int N = random.Next(2) + 2;
Console.WriteLine("So nhom dc tao ra: " + N);
for(int i=0;i<N;i++)
{
Group group = new Group();
group.Input();
groupList.Add(group);
}
//Cau 2: delegate
ShowInfor displayAll = null;
foreach(Group g in groupList)
{
displayAll += g.Display;
}
displayAll();
}
}
}
#Group.cs
using System;
namespace BT2312
{
public class Group
{
public string Name { get; set; }
public string Center { get; set; }
public Project MyProject { get; set; }
public Group()
{
MyProject = new Project();
}
public void Input()
{
Console.WriteLine("Nhap ten nhom: ");
Name = Console.ReadLine();
Console.WriteLine("Nhap ten trung tam: ");
Center = Console.ReadLine();
MyProject.Input();
}
public void Display()
{
Console.WriteLine("Ten nhom: {0}, trung tam: {1}", Name, Center);
MyProject.Display();
}
}
}
![le bui kien giang [community]](https://www.gravatar.com/avatar/9b3fcd0a34071c7b09e69cce50513da9.jpg?s=80&d=mm&r=g)
le bui kien giang
2021-10-07 09:14:04
#Group.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace test
{
class Group
{
public String name { get; set; }
public String center { get; set; }
public Project project { get; set; }
public Group(){
}
public void Input()
{
Console.WriteLine("enter name group ");
name = Console.ReadLine();
Console.WriteLine("enter Center ");
center = Console.ReadLine();
this.project = new Project();
}
public void Display()
{
Console.WriteLine("group name :" + this.name);
Console.WriteLine("group center :"+this.center);
Console.WriteLine("project name :"+ this.project.name);
Console.WriteLine("group :" + this.project.group);
}
}
}
#Program.cs
using System;
using System.Collections.Generic;
namespace test
{
class Program
{
public delegate void ShowInfor();
public static List<Group> groupList = new List<Group>();
static void Main(string[] args)
{
int c;
do
{
Console.WriteLine("enter group : ");
c = int.Parse(Console.ReadLine());
} while (c < 2 || c > 10);
for (int i = 0; i< c; i++)
{
Group group = new Group();
group.Input();
groupList.Add(group);
}
ShowInfor showInfor = delegate()
}
}
}
#Project.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace test
{
class Project
{
public String name { get; set; }
public String group { get; set; }
public Project() { }
public void Input() {
Console.WriteLine("enter name");
name = Console.ReadLine();
Console.WriteLine("enter group (Development & Design Website, Website Developer, Application Developer)");
group = Console.ReadLine();
}
}
}
![Phạm Ngọc Mai [community,AAHN-C2009G]](https://www.gravatar.com/avatar/555a0e0ad040cb0a76c628dab4607c47.jpg?s=80&d=mm&r=g)
Phạm Ngọc Mai
2021-10-07 09:11:19
#Group.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace test
{
class Group
{
public string Name { get; set; }
public string Center { get; set; }
public Project Project { get; set; }
public Group() {
this.Project = new Project();
}
public void Input()
{
Console.Write("Nhap ten nhom: ");
Name = Console.ReadLine();
Console.Write("Nhap trung tam: ");
Center = Console.ReadLine();
Console.WriteLine("Nhap Project:");
Project.Input();
}
public void Display()
{
Console.WriteLine("ten:{0}, Center: {1},Project: {2}", Name, Center, Project); }
}
}
#Program.cs
using System;
using System.Collections.Generic;
namespace test
{
class Program
{
public delegate void ShowInfor();
public static List<Group> groupList = new List<Group>();
static void Main(string[] args)
{
int i;
do
{
Console.Write("Nhap so nhom: ");
i = int.Parse(Console.ReadLine());
} while (i < 2 || i > 10);
for (int n =0; n<i; n++) {
Group group = new Group();
group.Input();
groupList.Add(group);
}
ShowInfor show = delegate ()
{
foreach (Group group in groupList)
{
Console.WriteLine("ten du an: " + group.Project.Name, "Nhom du an: " + group.Project.Group);
}
};
show();
Console.ReadLine();
}
}
}
#Project.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace test
{
class Project
{
public string Name { get; set; }
public string Group { get; set; }
public Project() { }
public Project(string Name , string group)
{
this.Name = Name;
if(!group.Equals("Development & Design Website")|| !group.Equals("Website Developer") || !group.Equals("Application Developer"))
{
this.Group = group;
}
}
public void Input()
{
Console.Write("Nhap ten: ");
Name = Console.ReadLine();
Console.Write("Nhap nhom:(Development & Design Website, Website Developer, Application Developer) ");
string group = Console.ReadLine();
while (!group.Equals("Development & Design Website") || !group.Equals("Website Developer") || !group.Equals("Application Developer"))
{
this.Group = group;
}
}
public void Display()
{
Console.WriteLine("Ten: {0}, Nhom: {1}",Name,Group);
}
}
}
![Nguyen Anh Huy [community,AAHN-C2009G]](https://www.gravatar.com/avatar/7d7fca44858b0ac649b9f691dc8b9120.jpg?s=80&d=mm&r=g)
Nguyen Anh Huy
2021-10-07 09:10:13
#Utility.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace Test2
{
class Utility
{
public static int ReadInt()
{
int value;
while (true)
{
try
{
value = int.Parse(Console.ReadLine());
return value;
}
catch (Exception e)
{
Console.WriteLine("Try again!!!");
}
}
}
}
}
#Project.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace Test2.Models
{
class Project
{
public string Name { get; set; }
private string _group;
public string Group
{
get
{
return this._group;
}
set
{
while (!(value.Equals("Development & Design Website") || value.Equals("Website Developer") ||
value.Equals("Application Developer")))
{
Console.WriteLine("Group must be 'Development & Design Website' or 'Website Developer' or 'Application Developer'!");
Console.WriteLine("Try again: ");
value = Console.ReadLine();
}
this._group = value;
}
}
public Project()
{
}
public void Input()
{
Console.WriteLine("Enter project name: ");
this.Name = Console.ReadLine();
Console.WriteLine("Enter group name: ");
this.Group = Console.ReadLine();
}
public void Display()
{
Console.WriteLine(this);
}
public override string ToString()
{
return string.Format("Project name: {0}, Group name: {1}", Name, Group);
}
}
}
#Group.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace Test2.Models
{
class Group
{
public string Name { get; set; }
public string Center { get; set; }
public Project Project { get; set; }
public Group()
{
}
public void Input()
{
Console.WriteLine("Enter Group name: ");
this.Name = Console.ReadLine();
Console.WriteLine("Enter center name: ");
this.Center = Console.ReadLine();
this.Project = new Project();
this.Project.Input();
}
public void Display()
{
Console.WriteLine(this);
}
public override string ToString()
{
return string.Format("Group name: {0}, Center name: {1}, {2}",this.Name,this.Center,this.Project);
}
}
}
#Program.cs
using System;
using System.Collections.Generic;
using Test2.Models;
namespace Test2
{
class Program
{
public delegate void ShowInfor();
static void Main(string[] args)
{
List<Group> ListGroup = new List<Group>();
int num = 0;
do
{
Console.WriteLine("Enter number of groups(from 2 to 10): ");
num = Utility.ReadInt();
if(num < 2 || num > 10)
{
Console.WriteLine("Number of groups is from 2 to 10. Try again!");
}
}
while (num < 2 || num > 10);
for(int i = 1; i <= num; i++)
{
Console.WriteLine("Group number " + i);
Group newG = new Group();
newG.Input();
ListGroup.Add(newG);
}
ShowInfor showInfor = delegate
{
foreach (Group g in ListGroup)
{
g.Project.Display();
}
};
showInfor();
}
}
}
![Nam20021608 [community,AAHN-C2009G]](https://www.gravatar.com/avatar/0b1940debe745e5d5db19e96d6e57811.jpg?s=80&d=mm&r=g)
Nam20021608
2021-10-07 09:09:43
#Grorp.cs
using System;
using System.Collections.Generic;
namespace lap7 {
class Group
{
public String Name{get;set;}
public String Center{get;set;}
public List<Project> project;
public Group(){}
public void Input(){
Console.WriteLine("-----------Group-----------");
Console.WriteLine("Nhap ten Group: ");
Name = Console.ReadLine();
Console.WriteLine("NHap Ten trung tam Aptech: ");
Center = Console.ReadLine();
Console.WriteLine("NHap so luong Project: ");
int sl = int.Parse(Console.ReadLine());
do{
sl = int.Parse(Console.ReadLine());
}while(sl > 0);
for(int i = 0 ; i < sl ; i++){
Project p = new Project();
p.Input();
project.Add(p);
}
}
public void Display(){
String s = "Ten group: "+Name + " , Center : "+Center;
foreach(Project p in project){
p.Display();
}
}
}
}
#Program.cs
using System;
using System.Collections.Generic;
namespace lap7
{
public delegate void ShowInfor();
class Program
{
public static List<Group> grouplist = new List<Group>();
public static void Show(){
ShowInfor showInfor = delegate {
for(int i = 0; i< grouplist.Count; i++){
for(int c = 0 ; c < grouplist[i].project.Count ;c++ ){
grouplist[i].project[c].Display();
}
}
};
}
static void Main(string[] args)
{
}
static void main(){
int choose;
do{
Console.WriteLine("1. Nhap N nhom");
Console.WriteLine("2. Hien thi tat ca cac project");
Console.WriteLine("3. Thoat");
choose = int.Parse(Console.ReadLine());
switch(choose){
case 1:
Console.WriteLine("Nhap N nhom: ");
int sl = int.Parse(Console.ReadLine());
for(int i = 0 ; i < sl ; i++){
Group g = new Group();
g.Input();
grouplist.Add(g);
}
break;
case 2:
Show();
break;
case 3:
break;
default:
Console.WriteLine("Nhap lai !");
break;
}
}while(choose !=3);
}
}
}
#Project.cs
using System;
namespace lap7 {
class Project
{
public String name{get; set;}
public String group;
public String Group{
get{return group;}
set{
if(value == "Development & Design Website" || value =="Website Developer" || value =="Application Developer" ){
group = value;
}else{
value = Console.ReadLine();
}
}
}
public Project(){}
public Project(String name , String group){
this.name = name ;
this.group =group;
}
public void Input(){
Console.WriteLine("-----------Nhap du lieu Project-----------");
Console.WriteLine("Nhap ten du an: ");
name = Console.ReadLine();
Console.WriteLine("Nhap nhom du an ( Development & Design Website, Website Developer, Application Developer ): ");
Group = Console.ReadLine();
}
public void Display(){
String d = "Name Projet: "+name + " , Group : "+group;
Console.WriteLine(d);
}
}
}
![Hoàng Thiện Thanh [community,AAHN-C2009G]](https://www.gravatar.com/avatar/58e377dde293f6da38c0b5168578557a.jpg?s=80&d=mm&r=g)
Hoàng Thiện Thanh
2021-10-07 09:07:26
#Group.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace T2008A
{
public class Group
{
public string Name { get; set; }
public string Center { get; set; }
public Project Project { get; set; }
public Group()
{
this.Project = new Project();
}
public Group(string Name, string Center)
{
this.Name = Name;
this.Center = Center;
this.Project = new Project();
}
public Group(string Name, string Center, Project Project)
{
this.Name = Name;
this.Center = Center;
this.Project = Project;
}
public void input()
{
Console.WriteLine("Input Name of the Group:");
Name = Console.ReadLine();
Console.WriteLine("Input the Center of this Group:");
Center = Console.ReadLine();
Console.WriteLine("Input the Project's Name:");
Project = Utility.GetProject();
}
}
}
#Program.cs
using System;
using System.Collections.Generic;
namespace T2008A
{
class Program
{
public static List<Project> ProjectList = new List<Project>();
public static List<Group> ListGroup = new List<Group>();
public delegate void ShowInfor();
static void Main(string[] args)
{
Console.WriteLine("Input a random maximum groups from 2 to 10:");
int N = Utility.ReadInt();
while(N < 2 || N > 10)
{
Console.WriteLine("Input range must be between 2 and 10");
N = Utility.ReadInt();
}
for (int i = 0; i < N; i++)
{
Group g = new Group();
g.input();
ListGroup.Add(g);
}
}
}
}
#Project.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace T2008A
{
public class Project
{
public string Name { get; set; }
public string Group { get; set; }
public Project()
{
}
public Project(string Name, string Group)
{
this.Name = Name;
this.Group = Group;
}
public void input()
{
Console.WriteLine("Enter Project Name:");
Name = Console.ReadLine();
Console.WriteLine("Enter Group by one of the followings\n(Development & Design Website, Website Developer, Application Developer):");
Group = Utility.ReadGroup();
}
public void display()
{
Console.WriteLine("Project Name: {0}\n" +
"Project Group: {1}", Name, Group);
}
}
}
#Utility.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace T2008A
{
public class Utility
{
public static string ReadGroup()
{
string str = Console.ReadLine();
while(!str.Equals("Development & Design Website") &&
!str.Equals("Website Developer") &&
!str.Equals("Application Developer"))
{
str = Console.ReadLine();
}
return str;
}
public static Project GetProject()
{
string str = Console.ReadLine();
Project get = new Project();
foreach(Project p in Program.ProjectList)
{
if (p.Name.Equals(str))
{
get = p;
} else
{
get.input();
Program.ProjectList.Add(get);
}
}
return get;
}
public static int ReadInt()
{
string str = Console.ReadLine();
bool check()
{
try { int.Parse(str); } catch (Exception) { return false; }
return true;
}
while (!check())
{
str = Console.ReadLine();
}
return int.Parse(str);
}
}
}