CS
This commit is contained in:
13
CS/CS0 Starter_assignment/.idea/.idea.Starter_assignment/.idea/.gitignore
generated
vendored
Normal file
13
CS/CS0 Starter_assignment/.idea/.idea.Starter_assignment/.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Rider ignored files
|
||||
/contentModel.xml
|
||||
/projectSettingsUpdater.xml
|
||||
/.idea.Starter_assignment.iml
|
||||
/modules.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
4
CS/CS0 Starter_assignment/.idea/.idea.Starter_assignment/.idea/encodings.xml
generated
Normal file
4
CS/CS0 Starter_assignment/.idea/.idea.Starter_assignment/.idea/encodings.xml
generated
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
|
||||
</project>
|
||||
8
CS/CS0 Starter_assignment/.idea/.idea.Starter_assignment/.idea/indexLayout.xml
generated
Normal file
8
CS/CS0 Starter_assignment/.idea/.idea.Starter_assignment/.idea/indexLayout.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="UserContentModel">
|
||||
<attachedFolders />
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
</component>
|
||||
</project>
|
||||
BIN
CS/CS0 Starter_assignment/Archive.zip
Normal file
BIN
CS/CS0 Starter_assignment/Archive.zip
Normal file
Binary file not shown.
74
CS/CS0 Starter_assignment/Course.cs
Normal file
74
CS/CS0 Starter_assignment/Course.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
namespace Starter_assignment;
|
||||
|
||||
class Course {
|
||||
private List<Student> students = new List<Student>();
|
||||
private Dictionary<string, List<Student>> groups = new Dictionary<string, List<Student>>();
|
||||
private int groupCounter = 1;
|
||||
|
||||
public void AddStudent(string name, int studentNumber) {
|
||||
name = name.Trim();
|
||||
|
||||
foreach (Student student in students) {
|
||||
if (student.GetStudentNumber() == studentNumber) {
|
||||
Console.WriteLine("Student number must be unique.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
string groupName = groups.Keys.LastOrDefault();
|
||||
if (groupName == null || groups[groupName].Count >= 3) {
|
||||
groupName = $"PG{groupCounter}";
|
||||
groups[groupName] = new List<Student>();
|
||||
groupCounter++;
|
||||
}
|
||||
|
||||
Student newStudent = new Student(name, studentNumber, groupName);
|
||||
students.Add(newStudent);
|
||||
groups[groupName].Add(newStudent);
|
||||
Console.WriteLine($"Student {name} added successfully to {groupName}.");
|
||||
}
|
||||
|
||||
public void ViewAllStudents() {
|
||||
foreach (Student student in students) {
|
||||
Console.WriteLine(student.GetInfo());
|
||||
}
|
||||
}
|
||||
|
||||
public void ViewAllGroups() {
|
||||
foreach (KeyValuePair<string, List<Student>> group in groups) {
|
||||
Console.WriteLine(group.Key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void SearchByStudentNumber(int studentNumber) {
|
||||
Student foundStudent = null;
|
||||
foreach (Student student in students) {
|
||||
int currentStudentNumber = student.GetStudentNumber();
|
||||
if (currentStudentNumber == studentNumber) {
|
||||
foundStudent = student;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (foundStudent != null) {
|
||||
Console.WriteLine(foundStudent.GetInfo());
|
||||
} else {
|
||||
Console.WriteLine("No student found.");
|
||||
}
|
||||
}
|
||||
|
||||
public void SearchByGroup(string groupName) {
|
||||
if (groups.ContainsKey(groupName)) {
|
||||
foreach (Student student in groups[groupName]) {
|
||||
Console.WriteLine(student.GetInfo());
|
||||
}
|
||||
} else {
|
||||
Console.WriteLine("Group not found.");
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowStatistics() {
|
||||
Console.WriteLine($"Total students: {students.Count}");
|
||||
Console.WriteLine($"Total groups: {groups.Count}");
|
||||
}
|
||||
}
|
||||
62
CS/CS0 Starter_assignment/Program.cs
Normal file
62
CS/CS0 Starter_assignment/Program.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
namespace Starter_assignment;
|
||||
|
||||
class Program {
|
||||
static void Main() {
|
||||
Course course = new Course();
|
||||
bool running = true;
|
||||
|
||||
while (running) {
|
||||
Console.WriteLine("\n1. Add Student" +
|
||||
"\n2. View All Students" +
|
||||
"\n3. View All Groups" +
|
||||
"\n4. Search Student by Number" +
|
||||
"\n5. Show Students in a Group" +
|
||||
"\n6. Show Statistics" +
|
||||
"\n7. Exit" +
|
||||
"\nChoose an option: ");
|
||||
|
||||
string choice = Console.ReadLine();
|
||||
|
||||
switch (choice)
|
||||
{
|
||||
case "1":
|
||||
Console.Write("Enter student name: ");
|
||||
string name = Console.ReadLine();
|
||||
Console.Write("Enter student number: ");
|
||||
if (int.TryParse(Console.ReadLine(), out int studentNumber)) {
|
||||
course.AddStudent(name, studentNumber);
|
||||
} else {
|
||||
Console.WriteLine("Invalid student number.");
|
||||
}
|
||||
break;
|
||||
case "2":
|
||||
course.ViewAllStudents();
|
||||
break;
|
||||
case "3":
|
||||
course.ViewAllGroups();
|
||||
break;
|
||||
case "4":
|
||||
Console.Write("Enter student number: ");
|
||||
if (int.TryParse(Console.ReadLine(), out int searchNumber)) {
|
||||
course.SearchByStudentNumber(searchNumber);
|
||||
}
|
||||
break;
|
||||
case "5":
|
||||
Console.Write("Enter group name: ");
|
||||
string groupName = Console.ReadLine();
|
||||
course.SearchByGroup(groupName);
|
||||
break;
|
||||
case "6":
|
||||
course.ShowStatistics();
|
||||
break;
|
||||
case "7":
|
||||
running = false;
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine("Invalid option, try again.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
10
CS/CS0 Starter_assignment/Starter_assignment.csproj
Normal file
10
CS/CS0 Starter_assignment/Starter_assignment.csproj
Normal file
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
BIN
CS/CS0 Starter_assignment/Starter_assignment.dll
Normal file
BIN
CS/CS0 Starter_assignment/Starter_assignment.dll
Normal file
Binary file not shown.
16
CS/CS0 Starter_assignment/Starter_assignment.sln
Normal file
16
CS/CS0 Starter_assignment/Starter_assignment.sln
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Starter_assignment", "Starter_assignment\Starter_assignment.csproj", "{C78EC255-456E-4C45-912E-49607AD28EDC}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{C78EC255-456E-4C45-912E-49607AD28EDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C78EC255-456E-4C45-912E-49607AD28EDC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C78EC255-456E-4C45-912E-49607AD28EDC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C78EC255-456E-4C45-912E-49607AD28EDC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,4 @@
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AConsole_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F2ccd2056ec55b7b67558d52e32a887ed5ac7e346fc429b218c188d0a99cb5be_003FConsole_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ATextReader_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002Econfig_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F5b34e2245c26def5c9df2f8c13df6c04246252f96a7cebf7db554fed90435_003FTextReader_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/PencilsConfiguration/ActualSeverity/@EntryValue">ERROR</s:String></wpf:ResourceDictionary>
|
||||
27
CS/CS0 Starter_assignment/Student.cs
Normal file
27
CS/CS0 Starter_assignment/Student.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
namespace Starter_assignment;
|
||||
|
||||
class Student {
|
||||
private string Name { get; }
|
||||
private int StudentNumber { get; }
|
||||
private string GroupName { get; }
|
||||
|
||||
public Student(string name, int studentNumber, string groupName) {
|
||||
if (string.IsNullOrWhiteSpace(name)) {
|
||||
throw new ArgumentException("Name cannot be empty.");
|
||||
}
|
||||
if (studentNumber < 10000 && studentNumber != -1) {
|
||||
throw new ArgumentException("Student number must be >= 10000 or -1.");
|
||||
}
|
||||
|
||||
Name = name;
|
||||
StudentNumber = studentNumber;
|
||||
GroupName = groupName;
|
||||
}
|
||||
|
||||
public int GetStudentNumber() {
|
||||
return StudentNumber;
|
||||
}
|
||||
public string GetInfo() {
|
||||
return $"{Name} ({StudentNumber}) - {GroupName}";
|
||||
}
|
||||
}
|
||||
BIN
CS/CS0 Starter_assignment/starter_assignment
Normal file
BIN
CS/CS0 Starter_assignment/starter_assignment
Normal file
Binary file not shown.
Reference in New Issue
Block a user