fix: merge submodule 'Lab5'
This commit is contained in:
parent
bb091a6eba
commit
e04ccb2a28
14
Lab5/.editorconfig
Normal file
14
Lab5/.editorconfig
Normal file
@ -0,0 +1,14 @@
|
||||
root=true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_style = tab
|
||||
indent_size = 2
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.cs]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
388
Lab5/.gitignore
vendored
Normal file
388
Lab5/.gitignore
vendored
Normal file
@ -0,0 +1,388 @@
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
##
|
||||
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||
|
||||
# User-specific files
|
||||
*.rsuser
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Mono auto generated files
|
||||
mono_crash.*
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
[Ww][Ii][Nn]32/
|
||||
[Aa][Rr][Mm]/
|
||||
[Aa][Rr][Mm]64/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
[Ll]ogs/
|
||||
|
||||
# Visual Studio 2015/2017 cache/options directory
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
#wwwroot/
|
||||
|
||||
# Visual Studio 2017 auto generated files
|
||||
Generated\ Files/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
# NUnit
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
nunit-*.xml
|
||||
|
||||
# Build Results of an ATL Project
|
||||
[Dd]ebugPS/
|
||||
[Rr]eleasePS/
|
||||
dlldata.c
|
||||
|
||||
# Benchmark Results
|
||||
BenchmarkDotNet.Artifacts/
|
||||
|
||||
# .NET Core
|
||||
project.lock.json
|
||||
project.fragment.lock.json
|
||||
artifacts/
|
||||
|
||||
# ASP.NET Scaffolding
|
||||
ScaffoldingReadMe.txt
|
||||
|
||||
# StyleCop
|
||||
StyleCopReport.xml
|
||||
|
||||
# Files built by Visual Studio
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_h.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.iobj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.ipdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*_wpftmp.csproj
|
||||
*.log
|
||||
*.tlog
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.svclog
|
||||
*.scc
|
||||
|
||||
# Chutzpah Test files
|
||||
_Chutzpah*
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opendb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
*.sap
|
||||
|
||||
# Visual Studio Trace Files
|
||||
*.e2e
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
$tf/
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
*.DotSettings.user
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# AxoCover is a Code Coverage Tool
|
||||
.axoCover/*
|
||||
!.axoCover/settings.json
|
||||
|
||||
# Coverlet is a free, cross platform Code Coverage Tool
|
||||
coverage*.json
|
||||
coverage*.xml
|
||||
coverage*.info
|
||||
|
||||
# Visual Studio code coverage results
|
||||
*.coverage
|
||||
*.coveragexml
|
||||
|
||||
# NCrunch
|
||||
_NCrunch_*
|
||||
.*crunch*.local.xml
|
||||
nCrunchTemp_*
|
||||
|
||||
# MightyMoose
|
||||
*.mm.*
|
||||
AutoTest.Net/
|
||||
|
||||
# Web workbench (sass)
|
||||
.sass-cache/
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.[Pp]ublish.xml
|
||||
*.azurePubxml
|
||||
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||
# but database connection strings (with potential passwords) will be unencrypted
|
||||
*.pubxml
|
||||
*.publishproj
|
||||
|
||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||
# in these scripts will be unencrypted
|
||||
PublishScripts/
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
# NuGet Symbol Packages
|
||||
*.snupkg
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/[Pp]ackages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
!**/[Pp]ackages/build/
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
#!**/[Pp]ackages/repositories.config
|
||||
# NuGet v3's project.json files produces more ignorable files
|
||||
*.nuget.props
|
||||
*.nuget.targets
|
||||
|
||||
# Nuget personal access tokens and Credentials
|
||||
# nuget.config
|
||||
|
||||
# Microsoft Azure Build Output
|
||||
csx/
|
||||
*.build.csdef
|
||||
|
||||
# Microsoft Azure Emulator
|
||||
ecf/
|
||||
rcf/
|
||||
|
||||
# Windows Store app package directories and files
|
||||
AppPackages/
|
||||
BundleArtifacts/
|
||||
Package.StoreAssociation.xml
|
||||
_pkginfo.txt
|
||||
*.appx
|
||||
*.appxbundle
|
||||
*.appxupload
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
*.[Cc]ache
|
||||
# but keep track of directories ending in .cache
|
||||
!?*.[Cc]ache/
|
||||
|
||||
# Others
|
||||
ClientBin/
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.jfm
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
orleans.codegen.cs
|
||||
|
||||
# Including strong name files can present a security risk
|
||||
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||
#*.snk
|
||||
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||
#bower_components/
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
ServiceFabricBackup/
|
||||
*.rptproj.bak
|
||||
|
||||
# SQL Server files
|
||||
*.mdf
|
||||
*.ldf
|
||||
*.ndf
|
||||
|
||||
# Business Intelligence projects
|
||||
*.rdl.data
|
||||
*.bim.layout
|
||||
*.bim_*.settings
|
||||
*.rptproj.rsuser
|
||||
*- [Bb]ackup.rdl
|
||||
*- [Bb]ackup ([0-9]).rdl
|
||||
*- [Bb]ackup ([0-9][0-9]).rdl
|
||||
|
||||
# Microsoft Fakes
|
||||
FakesAssemblies/
|
||||
|
||||
# GhostDoc plugin setting file
|
||||
*.GhostDoc.xml
|
||||
|
||||
# Node.js Tools for Visual Studio
|
||||
.ntvs_analysis.dat
|
||||
node_modules/
|
||||
|
||||
# Visual Studio 6 build log
|
||||
*.plg
|
||||
|
||||
# Visual Studio 6 workspace options file
|
||||
*.opt
|
||||
|
||||
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||
*.vbw
|
||||
|
||||
# Visual Studio LightSwitch build output
|
||||
**/*.HTMLClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/ModelManifest.xml
|
||||
**/*.Server/GeneratedArtifacts
|
||||
**/*.Server/ModelManifest.xml
|
||||
_Pvt_Extensions
|
||||
|
||||
# Paket dependency manager
|
||||
.paket/paket.exe
|
||||
paket-files/
|
||||
|
||||
# FAKE - F# Make
|
||||
.fake/
|
||||
|
||||
# CodeRush personal settings
|
||||
.cr/personal
|
||||
|
||||
# Python Tools for Visual Studio (PTVS)
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
# Cake - Uncomment if you are using it
|
||||
# tools/**
|
||||
# !tools/packages.config
|
||||
|
||||
# Tabs Studio
|
||||
*.tss
|
||||
|
||||
# Telerik's JustMock configuration file
|
||||
*.jmconfig
|
||||
|
||||
# BizTalk build output
|
||||
*.btp.cs
|
||||
*.btm.cs
|
||||
*.odx.cs
|
||||
*.xsd.cs
|
||||
|
||||
# OpenCover UI analysis results
|
||||
OpenCover/
|
||||
|
||||
# Azure Stream Analytics local run output
|
||||
ASALocalRun/
|
||||
|
||||
# MSBuild Binary and Structured Log
|
||||
*.binlog
|
||||
|
||||
# NVidia Nsight GPU debugger configuration file
|
||||
*.nvuser
|
||||
|
||||
# MFractors (Xamarin productivity tool) working folder
|
||||
.mfractor/
|
||||
|
||||
# Local History for Visual Studio
|
||||
.localhistory/
|
||||
|
||||
# BeatPulse healthcheck temp database
|
||||
healthchecksdb
|
||||
|
||||
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
||||
MigrationBackup/
|
||||
|
||||
# Ionide (cross platform F# VS Code tools) working folder
|
||||
.ionide/
|
||||
|
||||
# Fody - auto-generated XML schema
|
||||
FodyWeavers.xsd
|
||||
|
||||
# VS Code files for those working on multiple tools
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
*.code-workspace
|
||||
|
||||
# Local History for Visual Studio Code
|
||||
.history/
|
||||
|
||||
# Windows Installer files from build outputs
|
||||
*.cab
|
||||
*.msi
|
||||
*.msix
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# JetBrains Rider
|
||||
.idea/
|
||||
*.sln.iml
|
53
Lab5/Lab5.Exercises.Register/Animal.cs
Normal file
53
Lab5/Lab5.Exercises.Register/Animal.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Lab5.Exercises.Register
|
||||
{
|
||||
abstract class Animal
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Breed { get; set; }
|
||||
public DateTime BirthDate { get; set; }
|
||||
public Gender Gender { get; set; }
|
||||
public int Age
|
||||
{
|
||||
get
|
||||
{
|
||||
DateTime today = DateTime.Today;
|
||||
int age = today.Year - this.BirthDate.Year;
|
||||
if (this.BirthDate.Date > today.AddYears(-age))
|
||||
{
|
||||
age--;
|
||||
}
|
||||
return age;
|
||||
}
|
||||
}
|
||||
public Animal(int id, string name, string breed, DateTime birthDate, Gender gender)
|
||||
{
|
||||
this.ID = id;
|
||||
this.Name = name;
|
||||
this.Breed = breed;
|
||||
this.BirthDate = birthDate;
|
||||
this.Gender = gender;
|
||||
}
|
||||
public override bool Equals(object other)
|
||||
{
|
||||
return this.ID == ((Animal)other).ID;
|
||||
}
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.ID.GetHashCode();
|
||||
}
|
||||
public int CompareTo(Animal other)
|
||||
{
|
||||
int result = this.Breed.CompareTo(other.Breed);
|
||||
if (result == 0)
|
||||
{
|
||||
return this.Gender.CompareTo(other.Gender);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
9
Lab5/Lab5.Exercises.Register/Animals.csv
Normal file
9
Lab5/Lab5.Exercises.Register/Animals.csv
Normal file
@ -0,0 +1,9 @@
|
||||
DOG;123;Reksas;Buldogas;2014-01-01;Male;true
|
||||
DOG;124;Margis;Dalmantinas;2014-02-28;Male;false
|
||||
DOG;125;Bitė;Senbernaras;2008-07-17;Female;false
|
||||
DOG;320;Rikis;Taksas;2012-01-07;Male;true
|
||||
DOG;123;Reksas;Buldogas;2014-01-01;Male;true
|
||||
DOG;415;Pifas;Taksas;2014-07-07;Male;true
|
||||
DOG;420;Markas;Dalmantinas;2013-02-28;Female;false
|
||||
DOG;123;Reksas;Buldogas;2014-01-01;Male;true
|
||||
CAT;987;Garfildas;Princas;2008-04-10;Male
|
|
14
Lab5/Lab5.Exercises.Register/AnimalsComparator.cs
Normal file
14
Lab5/Lab5.Exercises.Register/AnimalsComparator.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Lab5.Exercises.Register
|
||||
{
|
||||
class AnimalsComparator
|
||||
{
|
||||
public virtual int Compare(Animal a, Animal b)
|
||||
{
|
||||
return a.CompareTo(b);
|
||||
}
|
||||
}
|
||||
}
|
22
Lab5/Lab5.Exercises.Register/AnimalsComparatorByBirthDate.cs
Normal file
22
Lab5/Lab5.Exercises.Register/AnimalsComparatorByBirthDate.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Lab5.Exercises.Register
|
||||
{
|
||||
class AnimalsComparatorByBirthDate : AnimalsComparator
|
||||
{
|
||||
public override int Compare(Animal a, Animal b)
|
||||
{
|
||||
int birthCompare = a.BirthDate.CompareTo(b.BirthDate);
|
||||
if (birthCompare == 0)
|
||||
{
|
||||
return a.ID.CompareTo(b.ID);
|
||||
}
|
||||
else
|
||||
{
|
||||
return birthCompare;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
21
Lab5/Lab5.Exercises.Register/AnimalsComparatorByName.cs
Normal file
21
Lab5/Lab5.Exercises.Register/AnimalsComparatorByName.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Lab5.Exercises.Register
|
||||
{
|
||||
class AnimalsComparatorByName : AnimalsComparator
|
||||
{
|
||||
public override int Compare(Animal a, Animal b)
|
||||
{
|
||||
int nameCompare = a.Name.CompareTo(b.Name);
|
||||
if (nameCompare == 0)
|
||||
{
|
||||
return a.ID.CompareTo(b.ID);
|
||||
} else
|
||||
{
|
||||
return nameCompare;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
150
Lab5/Lab5.Exercises.Register/AnimalsContainer.cs
Normal file
150
Lab5/Lab5.Exercises.Register/AnimalsContainer.cs
Normal file
@ -0,0 +1,150 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Lab5.Exercises.Register
|
||||
{
|
||||
class AnimalsContainer
|
||||
{
|
||||
private Animal[] animals;
|
||||
private int Capacity;
|
||||
public int Count { get; private set; }
|
||||
|
||||
public AnimalsContainer(int capacity = 16)
|
||||
{
|
||||
Capacity = capacity;
|
||||
animals = new Animal[capacity];
|
||||
}
|
||||
|
||||
public AnimalsContainer(AnimalsContainer container) : this(container.Capacity) //call another constructor
|
||||
{
|
||||
for (int i = 0; i < container.Count; i++)
|
||||
{
|
||||
Add(container.Get(i));
|
||||
}
|
||||
}
|
||||
|
||||
public void Add(Animal animal)
|
||||
{
|
||||
if (Count == Capacity)
|
||||
{
|
||||
EnsureCapacity(Capacity * 2);
|
||||
}
|
||||
|
||||
animals[Count] = animal;
|
||||
Count++;
|
||||
}
|
||||
public Animal Get(int index)
|
||||
{
|
||||
return animals[index];
|
||||
}
|
||||
public bool Contains(Animal animal)
|
||||
{
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (animals[i].Equals(animal))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Put(int index, Animal animal)
|
||||
{
|
||||
animals[index] = animal;
|
||||
}
|
||||
|
||||
public void Insert(int index, Animal animal)
|
||||
{
|
||||
if (Count == Capacity)
|
||||
{
|
||||
EnsureCapacity(Capacity * 2);
|
||||
}
|
||||
for (int i = Count+1; i > index; i--)
|
||||
{
|
||||
animals[i] = animals[i-1];
|
||||
}
|
||||
animals[index] = animal;
|
||||
Count++;
|
||||
}
|
||||
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
for (int i = index; i < Count; i++)
|
||||
{
|
||||
animals[i] = animals[i + 1];
|
||||
}
|
||||
Count--;
|
||||
}
|
||||
|
||||
public void Remove(Animal animal)
|
||||
{
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (animals[i].ID == animal.ID)
|
||||
{
|
||||
RemoveAt(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureCapacity(int minimumCapacity)
|
||||
{
|
||||
if (minimumCapacity > Capacity)
|
||||
{
|
||||
Animal[] animalsClone = new Animal[minimumCapacity];
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
animalsClone[i] = animals[i];
|
||||
}
|
||||
Capacity = minimumCapacity;
|
||||
animals = animalsClone;
|
||||
}
|
||||
}
|
||||
|
||||
public void Sort(AnimalsComparator comparator)
|
||||
{
|
||||
bool flag = true;
|
||||
while (flag)
|
||||
{
|
||||
flag = false;
|
||||
for (int i = 0; i < this.Count - 1; i++)
|
||||
{
|
||||
Animal a = this.animals[i];
|
||||
Animal b = this.animals[i + 1];
|
||||
if (comparator.Compare(a, b) > 0)
|
||||
{
|
||||
this.animals[i] = b;
|
||||
this.animals[i + 1] = a;
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Sort()
|
||||
{
|
||||
Sort(new AnimalsComparator());
|
||||
}
|
||||
|
||||
public AnimalsContainer Intersect(AnimalsContainer other)
|
||||
{
|
||||
AnimalsContainer result = new AnimalsContainer();
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
Animal current = animals[i];
|
||||
if (other.Contains(current))
|
||||
{
|
||||
result.Add(current);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
26
Lab5/Lab5.Exercises.Register/Cat.cs
Normal file
26
Lab5/Lab5.Exercises.Register/Cat.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Lab5.Exercises.Register
|
||||
{
|
||||
class Cat : VaccinatedAnimal
|
||||
{
|
||||
private const int VaccinationDurationMonths = 6;
|
||||
public Cat(int id, string name, string breed, DateTime birthDate, Gender gender) : base(id, name, breed, birthDate, gender)
|
||||
{
|
||||
}
|
||||
public override bool RequiresVaccination
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.LastVaccinationDate.Equals(DateTime.MinValue))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return LastVaccinationDate.AddMonths(VaccinationDurationMonths)
|
||||
.CompareTo(DateTime.Now) < 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
27
Lab5/Lab5.Exercises.Register/Dog.cs
Normal file
27
Lab5/Lab5.Exercises.Register/Dog.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Lab5.Exercises.Register
|
||||
{
|
||||
class Dog : VaccinatedAnimal
|
||||
{
|
||||
private const int VaccinationDuration = 1;
|
||||
public bool Aggresive { get; set; }
|
||||
public Dog(int id, string name, string breed, DateTime birthDate, Gender gender, bool aggresive) : base(id, name, breed, birthDate, gender)
|
||||
{
|
||||
this.Aggresive = aggresive;
|
||||
}
|
||||
public override bool RequiresVaccination
|
||||
{
|
||||
get
|
||||
{
|
||||
if (LastVaccinationDate.Equals(DateTime.MinValue))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return LastVaccinationDate.AddYears(VaccinationDuration).CompareTo(DateTime.Now) < 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
12
Lab5/Lab5.Exercises.Register/Gender.cs
Normal file
12
Lab5/Lab5.Exercises.Register/Gender.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Lab5.Exercises.Register
|
||||
{
|
||||
enum Gender
|
||||
{
|
||||
Male = 1,
|
||||
Female = 2,
|
||||
}
|
||||
}
|
153
Lab5/Lab5.Exercises.Register/InOutUtils.cs
Normal file
153
Lab5/Lab5.Exercises.Register/InOutUtils.cs
Normal file
@ -0,0 +1,153 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Lab5.Exercises.Register
|
||||
{
|
||||
class InOutUtils
|
||||
{
|
||||
public static List<Vaccination> ReadVaccinations(string fileName)
|
||||
{
|
||||
List<Vaccination> Vaccinations = new List<Vaccination>();
|
||||
string[] Lines = File.ReadAllLines(fileName);
|
||||
foreach (string line in Lines)
|
||||
{
|
||||
string[] values = line.Split(';');
|
||||
int id = int.Parse(values[0]);
|
||||
DateTime vaccinationDate = DateTime.Parse(values[1]);
|
||||
Vaccination v = new Vaccination(id, vaccinationDate);
|
||||
Vaccinations.Add(v);
|
||||
}
|
||||
return Vaccinations;
|
||||
}
|
||||
|
||||
public static AnimalsContainer ReadAnimals(string fileName)
|
||||
{
|
||||
AnimalsContainer animals = new AnimalsContainer();
|
||||
string[] lines = File.ReadAllLines(fileName, Encoding.UTF8);
|
||||
foreach (string line in lines)
|
||||
{
|
||||
string[] values = line.Split(';');
|
||||
string type = values[0];
|
||||
int id = int.Parse(values[1]);
|
||||
string name = values[2];
|
||||
string breed = values[3];
|
||||
DateTime birthDate = DateTime.Parse(values[4]);
|
||||
Gender gender;
|
||||
Enum.TryParse(values[5], out gender); //tries to convert value to enum
|
||||
switch (type)
|
||||
{
|
||||
case "DOG":
|
||||
bool aggresive = bool.Parse(values[6]);
|
||||
Dog dog = new Dog(id, name, breed, birthDate, gender, aggresive);
|
||||
animals.Add(dog);
|
||||
break;
|
||||
case "CAT":
|
||||
Cat cat = new Cat(id, name, breed, birthDate, gender);
|
||||
animals.Add(cat);
|
||||
break;
|
||||
default:
|
||||
break;//unknown type
|
||||
}
|
||||
}
|
||||
return animals;
|
||||
}
|
||||
|
||||
public static void PrintAnimals(Register register)
|
||||
{
|
||||
PrintAnimalsHeader();
|
||||
for (int i = 0; i < register.AnimalsCount(); i++)
|
||||
{
|
||||
PrintAnimalsRow(register.GetByIndex(i));
|
||||
}
|
||||
PrintAnimalsFooter();
|
||||
}
|
||||
|
||||
public static void PrintAnimals(List<Animal> animals)
|
||||
{
|
||||
PrintAnimalsHeader();
|
||||
foreach (Animal animal in animals)
|
||||
{
|
||||
PrintAnimalsRow(animal);
|
||||
}
|
||||
PrintAnimalsFooter();
|
||||
}
|
||||
|
||||
public static void PrintAnimals(AnimalsContainer container)
|
||||
{
|
||||
PrintAnimalsHeader();
|
||||
for (int i = 0; i < container.Count; i++)
|
||||
{
|
||||
PrintAnimalsRow(container.Get(i));
|
||||
}
|
||||
PrintAnimalsFooter();
|
||||
}
|
||||
|
||||
public static void PrintAnimals(string label, AnimalsContainer container)
|
||||
{
|
||||
PrintAnimalsHeader(label);
|
||||
for (int i = 0; i < container.Count; i++)
|
||||
{
|
||||
PrintAnimalsRow(container.Get(i));
|
||||
}
|
||||
PrintAnimalsFooter();
|
||||
}
|
||||
|
||||
private static void PrintAnimalsHeader()
|
||||
{
|
||||
Console.WriteLine(new string('-', 87));
|
||||
Console.WriteLine("| {0,8} | {1,-15} | {2,-15} | {3,-12} | {4,-8} | {5,-10} |", "Reg.Nr.", "Vardas", "Veislė", "Gimimo data", "Lytis", "Agresyvus");
|
||||
Console.WriteLine(new string('-', 87));
|
||||
}
|
||||
|
||||
private static void PrintAnimalsHeader(string label)
|
||||
{
|
||||
Console.WriteLine(new string('-', 87));
|
||||
Console.WriteLine("| {0,-70} |", label);
|
||||
PrintAnimalsHeader();
|
||||
}
|
||||
|
||||
private static void PrintAnimalsFooter()
|
||||
{
|
||||
Console.WriteLine(new string('-', 87));
|
||||
}
|
||||
|
||||
private static void PrintAnimalsRow(Animal animal)
|
||||
{
|
||||
if (animal is Dog)
|
||||
{
|
||||
Dog dog = animal as Dog;
|
||||
Console.WriteLine("| {0,8} | {1,-15} | {2,-15} | {3,-12:yyyy-MM-dd} | {4,-8} | {5,-10} |", dog.ID, dog.Name, dog.Breed, dog.BirthDate, dog.Gender, dog.Aggresive ? "taip" : "ne");
|
||||
} else
|
||||
{
|
||||
Console.WriteLine("| {0,8} | {1,-15} | {2,-15} | {3,-12:yyyy-MM-dd} | {4,-8} | {5, -10} |", animal.ID, animal.Name, animal.Breed, animal.BirthDate, animal.Gender, "-");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void PrintAnimal(Animal animal)
|
||||
{
|
||||
Console.WriteLine("Vardas: {0}, Veislė: {1}, Amžius: {2}", animal.Name, animal.Breed, animal.Age);
|
||||
}
|
||||
|
||||
public static void PrintBreeds(List<string> breeds)
|
||||
{
|
||||
foreach (string breed in breeds)
|
||||
{
|
||||
Console.WriteLine(breed);
|
||||
}
|
||||
}
|
||||
|
||||
public static void PrintDogsToCSVFile(string fileName, List<Animal> Animals)
|
||||
{
|
||||
string[] lines = new string[Animals.Count + 1];
|
||||
lines[0] = String.Format("{0};{1};{2};{3};{4}", "Reg.Nr.", "Vardas", "Veislė", "Gimimo data", "Lytis");
|
||||
for (int i = 0; i < Animals.Count; i++)
|
||||
{
|
||||
lines[i + 1] = String.Format("{0};{1};{2};{3};{4}", Animals[i].ID, Animals[i].Name, Animals[i].Breed, Animals[i].BirthDate, Animals[i].Gender);
|
||||
}
|
||||
File.WriteAllLines(fileName, lines, Encoding.UTF8);
|
||||
}
|
||||
}
|
||||
}
|
17
Lab5/Lab5.Exercises.Register/Lab5.Exercises.Register.csproj
Normal file
17
Lab5/Lab5.Exercises.Register/Lab5.Exercises.Register.csproj
Normal file
@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="Animals.csv">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Vaccinations.csv">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
82
Lab5/Lab5.Exercises.Register/Program.cs
Normal file
82
Lab5/Lab5.Exercises.Register/Program.cs
Normal file
@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Lab5.Exercises.Register
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
AnimalsContainer container = InOutUtils.ReadAnimals(@"Animals.csv");
|
||||
|
||||
Console.WriteLine("Registro informacija:");
|
||||
container.Sort(new AnimalsComparatorByName());
|
||||
InOutUtils.PrintAnimals(container);
|
||||
Console.WriteLine();
|
||||
|
||||
container.Sort(new AnimalsComparatorByBirthDate());
|
||||
InOutUtils.PrintAnimals(container);
|
||||
Console.WriteLine();
|
||||
|
||||
/*
|
||||
Console.WriteLine("Iš viso gyvūnų: {0}", register.AnimalsCount());
|
||||
Console.WriteLine("Patinų: {0}", register.CountByGender(Gender.Male));
|
||||
Console.WriteLine("Patelių: {0}", register.CountByGender(Gender.Female));
|
||||
Console.WriteLine();
|
||||
|
||||
Console.WriteLine("Gyvūnai kuriems reikia vakcinuotis:");
|
||||
AnimalsContainer animalsThatNeedVaccination = register.FilterByVaccinationExpired();
|
||||
InOutUtils.PrintDogs(animalsThatNeedVaccination);
|
||||
Console.WriteLine();
|
||||
|
||||
string vaccinationBreed = "Taksas";
|
||||
AnimalsContainer allAnimalsByBreed = register.FilterByBreed(vaccinationBreed);
|
||||
Console.WriteLine("Gyvūnai kuriems reikia vakcinuotis ({0}):", vaccinationBreed);
|
||||
InOutUtils.PrintDogs(allAnimalsByBreed.Intersect(animalsThatNeedVaccination));
|
||||
Console.WriteLine();
|
||||
|
||||
Console.WriteLine("Registre yra agresyvių šunų kiekis: {0}", register.CountAggresiveDogs());
|
||||
*/
|
||||
|
||||
/*
|
||||
Dog oldestDog = TaskUtils.FindOldestDog(register);
|
||||
Console.WriteLine("Seniausias šuo:");
|
||||
InOutUtils.PrintDog(oldestDog);
|
||||
Console.WriteLine();
|
||||
|
||||
List<string> breeds = TaskUtils.FindBreeds(register);
|
||||
Console.WriteLine("Šunų veislės:");
|
||||
InOutUtils.PrintBreeds(breeds);
|
||||
Console.WriteLine();
|
||||
|
||||
List<string> popularBreeds = TaskUtils.FindMostPopularBreeds(register);
|
||||
Console.WriteLine("Populiariausios šunų veislės:");
|
||||
InOutUtils.PrintBreeds(popularBreeds);
|
||||
Console.WriteLine();
|
||||
|
||||
Console.WriteLine("Kokios veislės šunis atrinkti?");
|
||||
string selectedBreed = Console.ReadLine().Trim();
|
||||
if (selectedBreed.Equals(""))
|
||||
{
|
||||
Console.WriteLine("Šunio veislė neįvesta");
|
||||
return;
|
||||
}
|
||||
|
||||
List<Dog> filteredByBreed = TaskUtils.FilterByBreed(register, selectedBreed);
|
||||
if (filteredByBreed.Count == 0)
|
||||
{
|
||||
Console.WriteLine("Šunų su veisle '{0}' nerasta", selectedBreed);
|
||||
return;
|
||||
}
|
||||
|
||||
Dog oldestFilteredDog = TaskUtils.FindOldestDog(filteredByBreed);
|
||||
Console.WriteLine("Seniausias šuo pagal '{0}' veislę:", selectedBreed);
|
||||
InOutUtils.PrintDog(oldestFilteredDog);
|
||||
InOutUtils.PrintDogs(filteredByBreed);
|
||||
string fileName = selectedBreed + ".csv";
|
||||
InOutUtils.PrintDogsToCSVFile(fileName, filteredByBreed);
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
}
|
145
Lab5/Lab5.Exercises.Register/Register.cs
Normal file
145
Lab5/Lab5.Exercises.Register/Register.cs
Normal file
@ -0,0 +1,145 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Lab5.Exercises.Register
|
||||
{
|
||||
class Register
|
||||
{
|
||||
private AnimalsContainer AllAnimals;
|
||||
public Register()
|
||||
{
|
||||
AllAnimals = new AnimalsContainer();
|
||||
}
|
||||
public Register(AnimalsContainer Animals)
|
||||
{
|
||||
AllAnimals = new AnimalsContainer();
|
||||
for (int i = 0; i < Animals.Count; i++)
|
||||
{
|
||||
this.AllAnimals.Add(Animals.Get(i));
|
||||
}
|
||||
}
|
||||
public void Add(Animal animal)
|
||||
{
|
||||
AllAnimals.Add(animal);
|
||||
}
|
||||
|
||||
public int AnimalsCount()
|
||||
{
|
||||
return AllAnimals.Count;
|
||||
}
|
||||
|
||||
public Animal GetByIndex(int index)
|
||||
{
|
||||
return AllAnimals.Get(index);
|
||||
}
|
||||
|
||||
public int CountByGender(Gender gender)
|
||||
{
|
||||
int count = 0;
|
||||
for (int i = 0; i < AllAnimals.Count; i++)
|
||||
{
|
||||
Animal animal = AllAnimals.Get(i);
|
||||
if (animal.Gender.Equals(gender))
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public Animal FindOldestAnimal()
|
||||
{
|
||||
return this.FindOldestAnimal(this.AllAnimals);
|
||||
}
|
||||
|
||||
public AnimalsContainer FilterByBreed(string breed)
|
||||
{
|
||||
AnimalsContainer Filtered = new AnimalsContainer();
|
||||
for (int i = 0; i < AllAnimals.Count; i++)
|
||||
{
|
||||
Animal animal = AllAnimals.Get(i);
|
||||
if (animal.Breed.Equals(breed)) // uses string method Equals()
|
||||
{
|
||||
Filtered.Add(animal);
|
||||
}
|
||||
}
|
||||
return Filtered;
|
||||
}
|
||||
|
||||
public Animal FindOldestAnimal(string breed)
|
||||
{
|
||||
AnimalsContainer Filtered = this.FilterByBreed(breed);
|
||||
return this.FindOldestAnimal(Filtered);
|
||||
}
|
||||
private Animal FindOldestAnimal(AnimalsContainer Animals)
|
||||
{
|
||||
Animal oldest = Animals.Get(0);
|
||||
for (int i = 1; i < Animals.Count; i++) //starts on index value 1
|
||||
{
|
||||
Animal animal = Animals.Get(i);
|
||||
if (DateTime.Compare(oldest.BirthDate, animal.BirthDate) > 0)
|
||||
{
|
||||
oldest = animal;
|
||||
}
|
||||
}
|
||||
return oldest;
|
||||
}
|
||||
private Animal FindAnimalByID(int ID)
|
||||
{
|
||||
for (int i = 0; i < AllAnimals.Count; i++)
|
||||
{
|
||||
Animal animal = AllAnimals.Get(i);
|
||||
if (animal.ID == ID)
|
||||
{
|
||||
return animal;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
public void UpdateVaccinationsInfo(List<Vaccination> Vaccinations)
|
||||
{
|
||||
foreach (Vaccination vaccination in Vaccinations)
|
||||
{
|
||||
VaccinatedAnimal animal = FindAnimalByID(vaccination.AnimalID) as VaccinatedAnimal;
|
||||
if (animal != null && vaccination > animal.LastVaccinationDate)
|
||||
{
|
||||
animal.LastVaccinationDate = vaccination.Date;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public AnimalsContainer FilterByVaccinationExpired()
|
||||
{
|
||||
AnimalsContainer Filtered = new AnimalsContainer();
|
||||
for (int i = 0; i < AllAnimals.Count; i++)
|
||||
{
|
||||
VaccinatedAnimal animal = AllAnimals.Get(i) as VaccinatedAnimal;
|
||||
if (animal != null && animal.RequiresVaccination)
|
||||
{
|
||||
Filtered.Add(animal);
|
||||
}
|
||||
}
|
||||
return Filtered;
|
||||
}
|
||||
public bool Contains(Animal animal)
|
||||
{
|
||||
return AllAnimals.Contains(animal);
|
||||
}
|
||||
|
||||
public int CountAggresiveDogs()
|
||||
{
|
||||
int count = 0;
|
||||
for (int i = 0; i < this.AllAnimals.Count; i++)
|
||||
{
|
||||
Animal animal = this.AllAnimals.Get(i);
|
||||
if (animal is Dog && (animal as Dog).Aggresive)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
}
|
16
Lab5/Lab5.Exercises.Register/VaccinatedAnimal.cs
Normal file
16
Lab5/Lab5.Exercises.Register/VaccinatedAnimal.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Lab5.Exercises.Register
|
||||
{
|
||||
abstract class VaccinatedAnimal : Animal
|
||||
{
|
||||
public DateTime LastVaccinationDate { get; set; }
|
||||
public abstract bool RequiresVaccination { get; }
|
||||
|
||||
public VaccinatedAnimal(int id, string name, string breed, DateTime birthDate, Gender gender) : base(id, name, breed, birthDate, gender)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
26
Lab5/Lab5.Exercises.Register/Vaccination.cs
Normal file
26
Lab5/Lab5.Exercises.Register/Vaccination.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Lab5.Exercises.Register
|
||||
{
|
||||
class Vaccination
|
||||
{
|
||||
public int AnimalID { get; set; }
|
||||
public DateTime Date { get; set; }
|
||||
public Vaccination(int animalID, DateTime date)
|
||||
{
|
||||
AnimalID = animalID;
|
||||
Date = date;
|
||||
}
|
||||
public static bool operator <(Vaccination vaccination, DateTime date)
|
||||
{
|
||||
return vaccination.Date.CompareTo(date) < 0;
|
||||
}
|
||||
public static bool operator >(Vaccination vaccination, DateTime date)
|
||||
{
|
||||
return vaccination.Date.CompareTo(date) > 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
6
Lab5/Lab5.Exercises.Register/Vaccinations.csv
Normal file
6
Lab5/Lab5.Exercises.Register/Vaccinations.csv
Normal file
@ -0,0 +1,6 @@
|
||||
123;2020-07-24
|
||||
124;2021-05-17
|
||||
421;2021-07-01
|
||||
125;2021-01-01
|
||||
320;2021-07-01
|
||||
320;2010-07-01
|
|
25
Lab5/Lab5.sln
Normal file
25
Lab5/Lab5.sln
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.28307.1525
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab5.Exercises.Register", "Lab5.Exercises.Register\Lab5.Exercises.Register.csproj", "{47BEC004-9D86-465A-9331-B525D8517FA5}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{47BEC004-9D86-465A-9331-B525D8517FA5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{47BEC004-9D86-465A-9331-B525D8517FA5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{47BEC004-9D86-465A-9331-B525D8517FA5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{47BEC004-9D86-465A-9331-B525D8517FA5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {D84405CC-3FBE-4F67-A523-6B74D8647B83}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
6
Lab5/README.md
Normal file
6
Lab5/README.md
Normal file
@ -0,0 +1,6 @@
|
||||
# Lab5 example project
|
||||
|
||||
This project is from the "Object oriented programming" course in KTU.
|
||||
|
||||
It is not polished in any way, so don't expect anything from this.
|
||||
|
5
Lab5/global.json
Normal file
5
Lab5/global.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"sdk": {
|
||||
"version": "3.0.103"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user