feat: initial commit
This commit is contained in:
commit
e2acb27115
388
.gitignore
vendored
Normal file
388
.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
|
15
Lab1.1Savarankiskas/1Savarankiskas.csproj
Normal file
15
Lab1.1Savarankiskas/1Savarankiskas.csproj
Normal file
@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net461</TargetFramework>
|
||||
<RootNamespace>Lab1._1Savarankiskas</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="Tourists.csv">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
39
Lab1.1Savarankiskas/InOutUtils.cs
Normal file
39
Lab1.1Savarankiskas/InOutUtils.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace Lab1._1Savarankiskas
|
||||
{
|
||||
class InOutUtils
|
||||
{
|
||||
public static List<Tourist> ReadTourists(string fileName)
|
||||
{
|
||||
List<Tourist> tourists = new List<Tourist>();
|
||||
string[] lines = File.ReadAllLines(fileName, Encoding.UTF8);
|
||||
foreach (string line in lines)
|
||||
{
|
||||
string[] values = line.Split(";");
|
||||
string name = values[0];
|
||||
string surname = values[1];
|
||||
double money = double.Parse(values[2]);
|
||||
Tourist tourist = new Tourist(name, surname, money);
|
||||
tourists.Add(tourist);
|
||||
}
|
||||
return tourists;
|
||||
}
|
||||
|
||||
public static void PrintTourists(List<Tourist> tourists)
|
||||
{
|
||||
Console.WriteLine(new string('-', 47));
|
||||
Console.WriteLine("| {0,-12} | {1,-12} | {2,-13} |", "Vardas", "Pavardė", "Pinigai");
|
||||
Console.WriteLine(new string('-', 47));
|
||||
foreach (Tourist tourist in tourists)
|
||||
{
|
||||
Console.WriteLine("| {0,-12} | {1,-12} | {2,-13:c2} |", tourist.Name, tourist.Surname, tourist.Money);
|
||||
}
|
||||
Console.WriteLine(new string('-', 47));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
35
Lab1.1Savarankiskas/Program.cs
Normal file
35
Lab1.1Savarankiskas/Program.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Lab1._1Savarankiskas
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
List<Tourist> tourists = InOutUtils.ReadTourists("Tourists.csv");
|
||||
InOutUtils.PrintTourists(tourists);
|
||||
|
||||
double spendingBudget = TaskUtils.GetBudget(tourists);
|
||||
Console.WriteLine("Grupės išlaidų biudžetas: {0:c2}", spendingBudget);
|
||||
Console.WriteLine();
|
||||
|
||||
List<Tourist> largestContributors = TaskUtils.GetLargestBudgetContributors(tourists);
|
||||
if (largestContributors.Count > 0)
|
||||
{
|
||||
if (largestContributors.Count == 1)
|
||||
{
|
||||
Console.WriteLine("Turistas kuris daugiausiai prisidėjo prie išlaidų biudžeto:");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Turistai kurie daugiausiai prisidėjo prie išlaidų biudžeto:");
|
||||
}
|
||||
foreach (Tourist tourist in largestContributors)
|
||||
{
|
||||
Console.WriteLine("{0} {1}", tourist.Name, tourist.Surname);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
56
Lab1.1Savarankiskas/TaskUtils.cs
Normal file
56
Lab1.1Savarankiskas/TaskUtils.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Lab1._1Savarankiskas
|
||||
{
|
||||
class TaskUtils
|
||||
{
|
||||
public static double GetBudget(List<Tourist> tourists)
|
||||
{
|
||||
double spendingBudget = 0;
|
||||
foreach (Tourist tourist in tourists)
|
||||
{
|
||||
spendingBudget += tourist.Money;
|
||||
}
|
||||
spendingBudget *= 0.3;
|
||||
return spendingBudget;
|
||||
}
|
||||
|
||||
public static Tourist GetLargestBudgetContributor(List<Tourist> tourists)
|
||||
{
|
||||
if (tourists.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Tourist largestContributor = tourists[0];
|
||||
foreach (Tourist tourist in tourists)
|
||||
{
|
||||
if (tourist.Money > largestContributor.Money)
|
||||
{
|
||||
largestContributor = tourist;
|
||||
}
|
||||
}
|
||||
return largestContributor;
|
||||
}
|
||||
|
||||
public static List<Tourist> GetLargestBudgetContributors(List<Tourist> tourists) {
|
||||
List<Tourist> largestContributors = new List<Tourist>();
|
||||
Tourist largestContributor = GetLargestBudgetContributor(tourists);
|
||||
if (largestContributor == null)
|
||||
{
|
||||
return largestContributors;
|
||||
}
|
||||
|
||||
foreach (Tourist tourist in tourists)
|
||||
{
|
||||
if (tourist.Money == largestContributor.Money)
|
||||
{
|
||||
largestContributors.Add(tourist);
|
||||
}
|
||||
}
|
||||
return largestContributors;
|
||||
}
|
||||
}
|
||||
}
|
19
Lab1.1Savarankiskas/Tourist.cs
Normal file
19
Lab1.1Savarankiskas/Tourist.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Lab1._1Savarankiskas
|
||||
{
|
||||
class Tourist
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Surname { get; set; }
|
||||
public double Money { get; set; }
|
||||
public Tourist(string name, string surname, double money)
|
||||
{
|
||||
Name = name;
|
||||
Surname = surname;
|
||||
Money = money;
|
||||
}
|
||||
}
|
||||
}
|
5
Lab1.1Savarankiskas/Tourists.csv
Normal file
5
Lab1.1Savarankiskas/Tourists.csv
Normal file
@ -0,0 +1,5 @@
|
||||
Jonas;Jonaitis;100
|
||||
Rokas;Jonaitis;150
|
||||
Petras;Jonaitis;81
|
||||
Ona;Jonaitis;69
|
||||
Mantas;Jonaitis;150
|
|
33
Lab1.Exercises.Register/Dog.cs
Normal file
33
Lab1.Exercises.Register/Dog.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Lab1.Exercises.Register
|
||||
{
|
||||
class Dog
|
||||
{
|
||||
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 Dog(int id, string name, string breed, DateTime birthDate, Gender gender)
|
||||
{
|
||||
ID = id;
|
||||
Name = name;
|
||||
Breed = breed;
|
||||
BirthDate = birthDate;
|
||||
Gender = gender;
|
||||
}
|
||||
public int CalculateAge()
|
||||
{
|
||||
DateTime today = DateTime.Today;
|
||||
int age = today.Year - BirthDate.Year;
|
||||
if (BirthDate.Date > today.AddYears(-age))
|
||||
{
|
||||
age--;
|
||||
}
|
||||
return age;
|
||||
}
|
||||
}
|
||||
}
|
6
Lab1.Exercises.Register/Dogs.csv
Normal file
6
Lab1.Exercises.Register/Dogs.csv
Normal file
@ -0,0 +1,6 @@
|
||||
123;Reksas;Buldogas;2014-01-01;Male
|
||||
124;Margis;Dalmantinas;2014-02-28;Male
|
||||
125;Bitė;Senbernaras;2008-07-17;Female
|
||||
320;Rikis;Taksas;2012-01-07;Male
|
||||
415;Pifas;Taksas;2014-07-07;Male
|
||||
420;Markas;Dalmantinas;2013-02-28;Female
|
|
12
Lab1.Exercises.Register/Gender.cs
Normal file
12
Lab1.Exercises.Register/Gender.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Lab1.Exercises.Register
|
||||
{
|
||||
enum Gender
|
||||
{
|
||||
Male = 1,
|
||||
Female = 2,
|
||||
}
|
||||
}
|
64
Lab1.Exercises.Register/InOutUtils.cs
Normal file
64
Lab1.Exercises.Register/InOutUtils.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Lab1.Exercises.Register
|
||||
{
|
||||
class InOutUtils
|
||||
{
|
||||
public static List<Dog> ReadDogs(string fileName)
|
||||
{
|
||||
List<Dog> Dogs = new List<Dog>();
|
||||
string[] Lines = File.ReadAllLines(fileName, Encoding.UTF8);
|
||||
foreach (string line in Lines)
|
||||
{
|
||||
string[] Values = line.Split(';');
|
||||
int id = int.Parse(Values[0]);
|
||||
string name = Values[1];
|
||||
string breed = Values[2];
|
||||
DateTime birthDate = DateTime.Parse(Values[3]);
|
||||
Gender gender;
|
||||
Enum.TryParse(Values[4], out gender); //tries to convert value to enum
|
||||
Dog dog = new Dog(id, name, breed, birthDate, gender);
|
||||
Dogs.Add(dog);
|
||||
}
|
||||
return Dogs;
|
||||
}
|
||||
public static void PrintDogs(List<Dog> Dogs)
|
||||
{
|
||||
Console.WriteLine(new string('-', 74));
|
||||
Console.WriteLine("| {0,8} | {1,-15} | {2,-15} | {3,-12} | {4,-8} |", "Reg.Nr.", "Vardas", "Veislė", "Gimimo data", "Lytis");
|
||||
Console.WriteLine(new string('-', 74));
|
||||
foreach (Dog dog in Dogs)
|
||||
{
|
||||
Console.WriteLine("| {0,8} | {1,-15} | {2,-15} | {3,-12:yyyy-MM-dd} | {4,-8} |", dog.ID, dog.Name, dog.Breed, dog.BirthDate, dog.Gender);
|
||||
}
|
||||
Console.WriteLine(new string('-', 74));
|
||||
}
|
||||
|
||||
public static void PrintDog(Dog dog)
|
||||
{
|
||||
Console.WriteLine("Vardas: {0}, Veislė: {1}, Amžius: {2}", dog.Name, dog.Breed, dog.CalculateAge());
|
||||
}
|
||||
|
||||
public static void PrintBreeds(List<string> breeds)
|
||||
{
|
||||
foreach (string breed in breeds)
|
||||
{
|
||||
Console.WriteLine(breed);
|
||||
}
|
||||
}
|
||||
|
||||
public static void PrintDogsToCSVFile(string fileName, List<Dog> Dogs)
|
||||
{
|
||||
string[] lines = new string[Dogs.Count + 1];
|
||||
lines[0] = String.Format("{0};{1};{2};{3};{4}", "Reg.Nr.", "Vardas", "Veislė", "Gimimo data", "Lytis");
|
||||
for (int i = 0; i < Dogs.Count; i++)
|
||||
{
|
||||
lines[i + 1] = String.Format("{0};{1};{2};{3};{4}", Dogs[i].ID, Dogs[i].Name, Dogs[i].Breed, Dogs[i].BirthDate, Dogs[i].Gender);
|
||||
}
|
||||
File.WriteAllLines(fileName, lines, Encoding.UTF8);
|
||||
}
|
||||
}
|
||||
}
|
14
Lab1.Exercises.Register/Lab1.Exercises.Register.csproj
Normal file
14
Lab1.Exercises.Register/Lab1.Exercises.Register.csproj
Normal file
@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="Dogs.csv">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
58
Lab1.Exercises.Register/Program.cs
Normal file
58
Lab1.Exercises.Register/Program.cs
Normal file
@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Lab1.Exercises.Register
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
List<Dog> allDogs = InOutUtils.ReadDogs("Dogs.csv");
|
||||
Console.WriteLine("Registro informacija:");
|
||||
InOutUtils.PrintDogs(allDogs);
|
||||
|
||||
Console.WriteLine("Iš viso šunų: {0}", allDogs.Count);
|
||||
Console.WriteLine("Patinų: {0}", TaskUtils.CountByGender(allDogs, Gender.Male));
|
||||
Console.WriteLine("Patelių: {0}", TaskUtils.CountByGender(allDogs, Gender.Female));
|
||||
Console.WriteLine();
|
||||
|
||||
Dog oldestDog = TaskUtils.FindOldestDog(allDogs);
|
||||
Console.WriteLine("Seniausias šuo:");
|
||||
InOutUtils.PrintDog(oldestDog);
|
||||
Console.WriteLine();
|
||||
|
||||
List<string> breeds = TaskUtils.FindBreeds(allDogs);
|
||||
Console.WriteLine("Šunų veislės:");
|
||||
InOutUtils.PrintBreeds(breeds);
|
||||
Console.WriteLine();
|
||||
|
||||
List<string> popularBreeds = TaskUtils.FindMostPopularBreeds(allDogs);
|
||||
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(allDogs, 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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
99
Lab1.Exercises.Register/TaskUtils.cs
Normal file
99
Lab1.Exercises.Register/TaskUtils.cs
Normal file
@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Lab1.Exercises.Register
|
||||
{
|
||||
class TaskUtils
|
||||
{
|
||||
public static int CountByGender(List<Dog> dogs, Gender gender)
|
||||
{
|
||||
int count = 0;
|
||||
foreach (Dog dog in dogs)
|
||||
{
|
||||
if (dog.Gender.Equals(gender))
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
public static Dog FindOldestDog(List<Dog> dogs)
|
||||
{
|
||||
Dog oldest = dogs[0]; // means least value
|
||||
for (int i = 1; i < dogs.Count; i++)
|
||||
{
|
||||
if (DateTime.Compare(dogs[i].BirthDate, oldest.BirthDate) < 0)
|
||||
{
|
||||
oldest = dogs[i];
|
||||
}
|
||||
}
|
||||
return oldest;
|
||||
}
|
||||
public static List<string> FindBreeds(List<Dog> dogs)
|
||||
{
|
||||
List<string> Breeds = new List<string>();
|
||||
foreach (Dog dog in dogs)
|
||||
{
|
||||
string breed = dog.Breed;
|
||||
if (!Breeds.Contains(breed)) // uses List method Contains()
|
||||
{
|
||||
Breeds.Add(breed);
|
||||
}
|
||||
}
|
||||
return Breeds;
|
||||
}
|
||||
|
||||
public static List<Dog> FilterByBreed(List<Dog> dogs, string breed)
|
||||
{
|
||||
List<Dog> Filtered = new List<Dog>();
|
||||
foreach (Dog dog in dogs)
|
||||
{
|
||||
if (dog.Breed.Equals(breed)) // uses string method Equals()
|
||||
{
|
||||
Filtered.Add(dog);
|
||||
}
|
||||
}
|
||||
return Filtered;
|
||||
}
|
||||
|
||||
public static int CountByBreed(List<Dog> dogs, string breed)
|
||||
{
|
||||
int count = 0;
|
||||
foreach (Dog dog in dogs)
|
||||
{
|
||||
if (dog.Breed.Equals(breed)) // uses string method Equals()
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public static List<string> FindMostPopularBreeds(List<Dog> dogs)
|
||||
{
|
||||
List<string> breeds = FindBreeds(dogs);
|
||||
int mostPopularCount = CountByBreed(dogs, breeds[0]);
|
||||
foreach (string breed in breeds)
|
||||
{
|
||||
int count = CountByBreed(dogs, breed);
|
||||
if (count > mostPopularCount)
|
||||
{
|
||||
mostPopularCount = count;
|
||||
}
|
||||
}
|
||||
|
||||
List<string> popularBreeds = new List<string>();
|
||||
foreach (string breed in breeds)
|
||||
{
|
||||
if (CountByBreed(dogs, breed) == mostPopularCount)
|
||||
{
|
||||
popularBreeds.Add(breed);
|
||||
}
|
||||
}
|
||||
|
||||
return popularBreeds;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
79
Lab1.Exercises.sln
Normal file
79
Lab1.Exercises.sln
Normal file
@ -0,0 +1,79 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.28307.1525
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "1Savarankiskas", "Lab1.1Savarankiskas\1Savarankiskas.csproj", "{D07BFD15-69E6-4D59-866D-CEB9730B1DF5}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lab1.Exercises.Register", "Lab1.Exercises.Register\Lab1.Exercises.Register.csproj", "{2EEB9341-1B3B-41F0-B22A-762984B255B0}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lab1.IMDB", "Lab1.IMDB\Lab1.IMDB.csproj", "{FA4EC695-560B-43F8-A864-ADC843A91D65}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab1.TouristInformationCenter", "Lab1.TouristInformationCenter\Lab1.TouristInformationCenter.csproj", "{7E583A11-4139-40AA-89C6-E5CAE0F27AD5}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{D07BFD15-69E6-4D59-866D-CEB9730B1DF5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D07BFD15-69E6-4D59-866D-CEB9730B1DF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D07BFD15-69E6-4D59-866D-CEB9730B1DF5}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{D07BFD15-69E6-4D59-866D-CEB9730B1DF5}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{D07BFD15-69E6-4D59-866D-CEB9730B1DF5}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{D07BFD15-69E6-4D59-866D-CEB9730B1DF5}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{D07BFD15-69E6-4D59-866D-CEB9730B1DF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D07BFD15-69E6-4D59-866D-CEB9730B1DF5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{D07BFD15-69E6-4D59-866D-CEB9730B1DF5}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{D07BFD15-69E6-4D59-866D-CEB9730B1DF5}.Release|x64.Build.0 = Release|Any CPU
|
||||
{D07BFD15-69E6-4D59-866D-CEB9730B1DF5}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{D07BFD15-69E6-4D59-866D-CEB9730B1DF5}.Release|x86.Build.0 = Release|Any CPU
|
||||
{2EEB9341-1B3B-41F0-B22A-762984B255B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{2EEB9341-1B3B-41F0-B22A-762984B255B0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{2EEB9341-1B3B-41F0-B22A-762984B255B0}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{2EEB9341-1B3B-41F0-B22A-762984B255B0}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{2EEB9341-1B3B-41F0-B22A-762984B255B0}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{2EEB9341-1B3B-41F0-B22A-762984B255B0}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{2EEB9341-1B3B-41F0-B22A-762984B255B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{2EEB9341-1B3B-41F0-B22A-762984B255B0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{2EEB9341-1B3B-41F0-B22A-762984B255B0}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{2EEB9341-1B3B-41F0-B22A-762984B255B0}.Release|x64.Build.0 = Release|Any CPU
|
||||
{2EEB9341-1B3B-41F0-B22A-762984B255B0}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{2EEB9341-1B3B-41F0-B22A-762984B255B0}.Release|x86.Build.0 = Release|Any CPU
|
||||
{FA4EC695-560B-43F8-A864-ADC843A91D65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{FA4EC695-560B-43F8-A864-ADC843A91D65}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FA4EC695-560B-43F8-A864-ADC843A91D65}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{FA4EC695-560B-43F8-A864-ADC843A91D65}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{FA4EC695-560B-43F8-A864-ADC843A91D65}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{FA4EC695-560B-43F8-A864-ADC843A91D65}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{FA4EC695-560B-43F8-A864-ADC843A91D65}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FA4EC695-560B-43F8-A864-ADC843A91D65}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{FA4EC695-560B-43F8-A864-ADC843A91D65}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{FA4EC695-560B-43F8-A864-ADC843A91D65}.Release|x64.Build.0 = Release|Any CPU
|
||||
{FA4EC695-560B-43F8-A864-ADC843A91D65}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{FA4EC695-560B-43F8-A864-ADC843A91D65}.Release|x86.Build.0 = Release|Any CPU
|
||||
{7E583A11-4139-40AA-89C6-E5CAE0F27AD5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7E583A11-4139-40AA-89C6-E5CAE0F27AD5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7E583A11-4139-40AA-89C6-E5CAE0F27AD5}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{7E583A11-4139-40AA-89C6-E5CAE0F27AD5}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{7E583A11-4139-40AA-89C6-E5CAE0F27AD5}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{7E583A11-4139-40AA-89C6-E5CAE0F27AD5}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{7E583A11-4139-40AA-89C6-E5CAE0F27AD5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7E583A11-4139-40AA-89C6-E5CAE0F27AD5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{7E583A11-4139-40AA-89C6-E5CAE0F27AD5}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{7E583A11-4139-40AA-89C6-E5CAE0F27AD5}.Release|x64.Build.0 = Release|Any CPU
|
||||
{7E583A11-4139-40AA-89C6-E5CAE0F27AD5}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{7E583A11-4139-40AA-89C6-E5CAE0F27AD5}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {03AFC156-496A-4000-9EFE-0E6803C9EC9A}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
5
Lab1.IMDB/Actors.csv
Normal file
5
Lab1.IMDB/Actors.csv
Normal file
@ -0,0 +1,5 @@
|
||||
T. Cruise
|
||||
Tiesiog Petras
|
||||
Kaimynas Rokas
|
||||
N. Kidman
|
||||
Tiesiog Jonas
|
|
39
Lab1.IMDB/InOutUtils.cs
Normal file
39
Lab1.IMDB/InOutUtils.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Lab1.IMDB
|
||||
{
|
||||
class InOutUtils
|
||||
{
|
||||
public static List<Movie> ReadMovies(string filename)
|
||||
{
|
||||
List<Movie> movies = new List<Movie>();
|
||||
string[] lines = File.ReadAllLines(filename, Encoding.UTF8);
|
||||
foreach (string line in lines)
|
||||
{
|
||||
string[] values = line.Split(';');
|
||||
string title = values[0];
|
||||
int year = int.Parse(values[1]);
|
||||
string genre = values[2];
|
||||
string studio = values[3];
|
||||
string producer = values[4];
|
||||
string actor1 = values[5];
|
||||
string actor2 = values[6];
|
||||
Movie movie = new Movie(title, year, genre, studio, producer, actor1, actor2);
|
||||
movies.Add(movie);
|
||||
}
|
||||
return movies;
|
||||
}
|
||||
|
||||
public static void WriteActors(string filename, List<string> actors)
|
||||
{
|
||||
string[] lines = new string[actors.Count];
|
||||
for (int i = 0; i < actors.Count; i++)
|
||||
{
|
||||
lines[i] = actors[i];
|
||||
}
|
||||
File.WriteAllLines(filename, lines, Encoding.UTF8);
|
||||
}
|
||||
}
|
||||
}
|
14
Lab1.IMDB/Lab1.IMDB.csproj
Normal file
14
Lab1.IMDB/Lab1.IMDB.csproj
Normal file
@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net461</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="Movies.csv">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
24
Lab1.IMDB/Movie.cs
Normal file
24
Lab1.IMDB/Movie.cs
Normal file
@ -0,0 +1,24 @@
|
||||
|
||||
namespace Lab1.IMDB
|
||||
{
|
||||
class Movie
|
||||
{
|
||||
public string Title { get; set; }
|
||||
public int Year { get; set; }
|
||||
public string Genre { get; set; }
|
||||
public string Studio { get; set; }
|
||||
public string Producer { get; set; }
|
||||
public string Actor1 { get; set; }
|
||||
public string Actor2 { get; set; }
|
||||
public Movie(string title, int year, string genre, string studio, string producer, string actor1, string actor2) {
|
||||
Title = title;
|
||||
Year = year;
|
||||
Genre = genre;
|
||||
Studio = studio;
|
||||
Producer = producer;
|
||||
Actor1 = actor1;
|
||||
Actor2 = actor2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
7
Lab1.IMDB/Movies.csv
Normal file
7
Lab1.IMDB/Movies.csv
Normal file
@ -0,0 +1,7 @@
|
||||
MovieA;2020;FooBar;Warner Bros;Jonaitis jonas;T. Cruise;Tiesiog Petras
|
||||
MovieB;2010;FooBar;Mano Bros;Kaimyne Ona;Tiesiog Petras;Kaimynas Rokas
|
||||
MovieC;2024;FooBar;Mano Bros;Jonaitis jonas;T. Cruise;Tiesiog Petras
|
||||
MovieD;1020;FooBar;Warner Bros;Jonaitis jonas;T. Cruise;N. Kidman
|
||||
MovieE;2012;FooBar;Warner Bros;Jonaitis kasparas;T. Cruise;Tiesiog Petras
|
||||
MovieF;2110;FooBar;Tavo Bros;Jonaitis petras;Tiesiog Petras;Tiesiog Jonas
|
||||
MovieG;2120;FooBar;Tavo Bros;Jonaitis jonas;N. Kidman;T. Cruise
|
|
33
Lab1.IMDB/Program.cs
Normal file
33
Lab1.IMDB/Program.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
// Variant U1-21.
|
||||
namespace Lab1.IMDB
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
List<Movie> movies = InOutUtils.ReadMovies("Movies.csv");
|
||||
|
||||
List<Movie> filteredByActors = TaskUtils.FilterByActors(movies, "T. Cruise", "N. Kidman");
|
||||
Console.WriteLine("Movies with T. Cruise and N. Kidman:");
|
||||
foreach (Movie movie in filteredByActors)
|
||||
{
|
||||
Console.WriteLine("{0} {1}", movie.Title, movie.Year);
|
||||
}
|
||||
Console.WriteLine();
|
||||
|
||||
|
||||
List<Movie> filteredByStudio = TaskUtils.FilterByStudio(movies, "Warner Bros");
|
||||
Console.WriteLine("Movies by Warner Bros:");
|
||||
foreach (Movie movie in filteredByStudio)
|
||||
{
|
||||
Console.WriteLine("{0} {1}", movie.Title, movie.Year);
|
||||
}
|
||||
|
||||
List<string> actors = TaskUtils.GetActors(movies);
|
||||
InOutUtils.WriteActors("Actors.csv", actors);
|
||||
}
|
||||
}
|
||||
}
|
51
Lab1.IMDB/TaskUtils.cs
Normal file
51
Lab1.IMDB/TaskUtils.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
namespace Lab1.IMDB
|
||||
{
|
||||
class TaskUtils
|
||||
{
|
||||
public static List<Movie> FilterByActors(List<Movie> movies, string actor1, string actor2)
|
||||
{
|
||||
List<Movie> filtered = new List<Movie>();
|
||||
foreach (Movie movie in movies)
|
||||
{
|
||||
if (movie.Actor1 == actor1 && movie.Actor2 == actor2 || movie.Actor1 == actor2 && movie.Actor2 == actor1)
|
||||
{
|
||||
filtered.Add(movie);
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
public static List<Movie> FilterByStudio(List<Movie> movies, string studio)
|
||||
{
|
||||
List<Movie> filtered = new List<Movie>();
|
||||
foreach (Movie movie in movies)
|
||||
{
|
||||
if (movie.Studio.Equals(studio))
|
||||
{
|
||||
filtered.Add(movie);
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
public static List<string> GetActors(List<Movie> movies)
|
||||
{
|
||||
List<string> actors = new List<string>();
|
||||
foreach (Movie movie in movies)
|
||||
{
|
||||
if (!actors.Contains(movie.Actor1))
|
||||
{
|
||||
actors.Add(movie.Actor1);
|
||||
}
|
||||
if (!actors.Contains(movie.Actor2))
|
||||
{
|
||||
actors.Add(movie.Actor2);
|
||||
}
|
||||
}
|
||||
return actors;
|
||||
}
|
||||
}
|
||||
}
|
113
Lab1.TouristInformationCenter/InOutUtils.cs
Executable file
113
Lab1.TouristInformationCenter/InOutUtils.cs
Executable file
@ -0,0 +1,113 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace Lab1.TouristInformationCenter
|
||||
{
|
||||
/// <summary>
|
||||
/// Class that stores functions that are related to reading and writing data
|
||||
/// </summary>
|
||||
class InOutUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// Read and decode a list of museums from a file. The file must be in a csv format using ";" as seperators.
|
||||
/// </summary>
|
||||
/// <param name="filename">Target file</param>
|
||||
/// <returns>List of museums</returns>
|
||||
public static List<Museum> ReadMuseums(string filename)
|
||||
{
|
||||
List<Museum> museums = new List<Museum>();
|
||||
string[] lines = File.ReadAllLines(filename, Encoding.UTF8);
|
||||
foreach (string line in lines)
|
||||
{
|
||||
string[] values = line.Split(';');
|
||||
string name = values[0];
|
||||
string city = values[1];
|
||||
string type = values[2];
|
||||
List<Weekday> workdays = new List<Weekday>();
|
||||
if (int.Parse(values[3]) == 1)
|
||||
{
|
||||
workdays.Add(Weekday.Monday);
|
||||
}
|
||||
if (int.Parse(values[4]) == 1)
|
||||
{
|
||||
workdays.Add(Weekday.Tuesday);
|
||||
}
|
||||
if (int.Parse(values[5]) == 1)
|
||||
{
|
||||
workdays.Add(Weekday.Wednesday);
|
||||
}
|
||||
if (int.Parse(values[6]) == 1)
|
||||
{
|
||||
workdays.Add(Weekday.Thursday);
|
||||
}
|
||||
if (int.Parse(values[7]) == 1)
|
||||
{
|
||||
workdays.Add(Weekday.Friday);
|
||||
}
|
||||
if (int.Parse(values[8]) == 1)
|
||||
{
|
||||
workdays.Add(Weekday.Saturday);
|
||||
}
|
||||
if (int.Parse(values[9]) == 1)
|
||||
{
|
||||
workdays.Add(Weekday.Sunday);
|
||||
}
|
||||
double price = double.Parse(values[10]);
|
||||
bool hasGuide = int.Parse(values[11]) == 1;
|
||||
|
||||
Museum museum = new Museum(name, city, type, workdays, price, hasGuide);
|
||||
museums.Add(museum);
|
||||
}
|
||||
return museums;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write and encodes a list of museums to a file. The file will be in a csv format using ";" as seperators.
|
||||
/// </summary>
|
||||
/// <param name="filename">Target file</param>
|
||||
/// <param name="museums">List of museums</param>
|
||||
public static void WriteMuseums(string filename, List<Museum> museums)
|
||||
{
|
||||
string[] lines = new string[museums.Count];
|
||||
for (int i = 0; i < museums.Count; i++)
|
||||
{
|
||||
Museum m = museums[i];
|
||||
string workDays = "";
|
||||
workDays += m.Workdays.Contains(Weekday.Monday) ? "1" : "0";
|
||||
workDays += m.Workdays.Contains(Weekday.Tuesday) ? ";1" : ";0";
|
||||
workDays += m.Workdays.Contains(Weekday.Wednesday) ? ";1" : ";0";
|
||||
workDays += m.Workdays.Contains(Weekday.Thursday) ? ";1" : ";0";
|
||||
workDays += m.Workdays.Contains(Weekday.Friday) ? ";1" : ";0";
|
||||
workDays += m.Workdays.Contains(Weekday.Saturday) ? ";1" : ";0";
|
||||
workDays += m.Workdays.Contains(Weekday.Sunday) ? ";1" : ";0";
|
||||
|
||||
lines[i] = String.Join(";", m.Name, m.City, m.Type, workDays, m.Price, m.HasGuide ? '1' : '0');
|
||||
}
|
||||
File.WriteAllLines(filename, lines, Encoding.UTF8);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write out a list of museums in a table to the console.
|
||||
/// </summary>
|
||||
/// <param name="museums">List of museums</param>
|
||||
public static void PrintMuseums(List<Museum> museums)
|
||||
{
|
||||
if (museums.Count == 0)
|
||||
{
|
||||
Console.WriteLine("Nėra");
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine(new string('-', 97));
|
||||
Console.WriteLine("| {0,20} | {1,-15} | {2,-10} | {3,-18} | {4,-3} | {5,-4} |", "Vardas", "Miestas", "Tipas", "Darbo dienų kiekis", "Kaina", "Turi gidą?");
|
||||
Console.WriteLine(new string('-', 97));
|
||||
foreach (Museum m in museums)
|
||||
{
|
||||
Console.WriteLine("| {0,20} | {1,-15} | {2,-10} | {3,-18} | {4,-5:f2} | {5,-10} |", m.Name, m.City, m.Type, m.Workdays.Count, m.Price, m.HasGuide ? "Taip" : "Ne");
|
||||
}
|
||||
Console.WriteLine(new string('-', 97));
|
||||
}
|
||||
}
|
||||
}
|
14
Lab1.TouristInformationCenter/Lab1.TouristInformationCenter.csproj
Executable file
14
Lab1.TouristInformationCenter/Lab1.TouristInformationCenter.csproj
Executable file
@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="Museums.csv">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
26
Lab1.TouristInformationCenter/Museum.cs
Executable file
26
Lab1.TouristInformationCenter/Museum.cs
Executable file
@ -0,0 +1,26 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Lab1.TouristInformationCenter
|
||||
{
|
||||
/// <summary>
|
||||
/// Class used for storing data related a single museum.
|
||||
/// </summary>
|
||||
class Museum
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string City { get; set; }
|
||||
public string Type { get; set; }
|
||||
public List<Weekday> Workdays { get; set; }
|
||||
public double Price { get; set; }
|
||||
public bool HasGuide { get; set; }
|
||||
public Museum(string name, string city, string type, List<Weekday> workdays, double price, bool hasGuide)
|
||||
{
|
||||
Name = name;
|
||||
City = city;
|
||||
Type = type;
|
||||
Workdays = workdays;
|
||||
Price = price;
|
||||
HasGuide = hasGuide;
|
||||
}
|
||||
}
|
||||
}
|
6
Lab1.TouristInformationCenter/Museums.csv
Executable file
6
Lab1.TouristInformationCenter/Museums.csv
Executable file
@ -0,0 +1,6 @@
|
||||
VilnausMuziejus;Vilnius;History;1;1;0;1;1;0;0;5,49;0
|
||||
KaunoMuziejus;Kaunas;Computer;1;1;0;1;1;1;1;4,69;1
|
||||
ŠiauliųMuziejus;Šiauliai;History;0;1;1;1;1;0;0;1,23;1
|
||||
MarijampolėsMuziejus;Marijampolė;Food;1;1;1;1;1;1;1;6,90;1
|
||||
AlytausMuziejus;Alytus;History;0;1;0;1;1;0;1;10,49;0
|
||||
KlaipėdosMuziejus;Klaipėda;Space;1;1;0;1;0;0;0;1,00;0
|
|
30
Lab1.TouristInformationCenter/Program.cs
Executable file
30
Lab1.TouristInformationCenter/Program.cs
Executable file
@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Lab1.TouristInformationCenter
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
// Read all museums from initial data file.
|
||||
List<Museum> museums = InOutUtils.ReadMuseums("Museums.csv");
|
||||
Console.WriteLine("Visi muziejai:");
|
||||
InOutUtils.PrintMuseums(museums);
|
||||
Console.WriteLine();
|
||||
|
||||
// Filter out museums that are free and a guide. And output those museums to the console.
|
||||
Console.WriteLine("Muziejai kurie yra nemokami ir turi gidą:");
|
||||
InOutUtils.PrintMuseums(TaskUtils.FilterByFreeAndWithGuide(museums));
|
||||
Console.WriteLine();
|
||||
|
||||
// Filter out museums that are "active". And output those museums to the console.
|
||||
Console.WriteLine("Muziejai kurie dirba bent 5 kartus per savaitę:");
|
||||
InOutUtils.PrintMuseums(TaskUtils.FilterByActiveMuseums(museums));
|
||||
Console.WriteLine();
|
||||
|
||||
// Filter out museums that are from "non-popular" cities. And save them to a file.
|
||||
InOutUtils.WriteMuseums("Atrinkti.csv", TaskUtils.FilterByNonPopularCity(museums));
|
||||
}
|
||||
}
|
||||
}
|
66
Lab1.TouristInformationCenter/TaskUtils.cs
Executable file
66
Lab1.TouristInformationCenter/TaskUtils.cs
Executable file
@ -0,0 +1,66 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Lab1.TouristInformationCenter
|
||||
{
|
||||
/// <summary>
|
||||
/// Class used for storing functions that manipulate or filter data.
|
||||
/// </summary>
|
||||
class TaskUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// Return a sub-list of given museums where all museums in the returned list are free and have a guide.
|
||||
/// </summary>
|
||||
/// <param name="museums">List of museums</param>
|
||||
/// <returns>Filtered sub-list of museums</returns>
|
||||
public static List<Museum> FilterByFreeAndWithGuide(List<Museum> museums)
|
||||
{
|
||||
List<Museum> filtered = new List<Museum>();
|
||||
foreach (Museum museum in museums)
|
||||
{
|
||||
if (museum.HasGuide && museum.Price == 0)
|
||||
{
|
||||
filtered.Add(museum);
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return a sub-list of given museums where all museums in the returned list are "active".
|
||||
/// A museum is considered active if it is working at least 5 times a week.
|
||||
/// </summary>
|
||||
/// <param name="museums">List of museums</param>
|
||||
/// <returns>Filtered sub-list of museums</returns>
|
||||
public static List<Museum> FilterByActiveMuseums(List<Museum> museums)
|
||||
{
|
||||
List<Museum> filtered = new List<Museum>();
|
||||
foreach (Museum museum in museums)
|
||||
{
|
||||
if (museum.Workdays.Count >= 5)
|
||||
{
|
||||
filtered.Add(museum);
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return a sub-list of given museums where all museums in the returned list are from "non-popular" cities.
|
||||
/// A city is "non-popular" if it is not "Vilnius", "Kaunas" or "Klaipėda".
|
||||
/// </summary>
|
||||
/// <param name="museums">List of museums</param>
|
||||
/// <returns>Filtered sub-list of museums</returns>
|
||||
public static List<Museum> FilterByNonPopularCity(List<Museum> museums)
|
||||
{
|
||||
List<Museum> filtered = new List<Museum>();
|
||||
foreach (Museum museum in museums)
|
||||
{
|
||||
if (!(museum.City.Equals("Vilnius") || museum.City.Equals("Kaunas") || museum.City.Equals("Klaipėda")))
|
||||
{
|
||||
filtered.Add(museum);
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
}
|
||||
}
|
17
Lab1.TouristInformationCenter/Weekday.cs
Executable file
17
Lab1.TouristInformationCenter/Weekday.cs
Executable file
@ -0,0 +1,17 @@
|
||||
|
||||
namespace Lab1.TouristInformationCenter
|
||||
{
|
||||
/// <summary>
|
||||
/// Used for storing weekdays as numbers rather than strings
|
||||
/// </summary>
|
||||
enum Weekday
|
||||
{
|
||||
Monday = 1,
|
||||
Tuesday = 2,
|
||||
Wednesday = 3,
|
||||
Thursday = 4,
|
||||
Friday = 5,
|
||||
Saturday = 6,
|
||||
Sunday = 7
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user