diff --git a/Lab5/Lab5.TouristInformationCenter/InOutUtils.cs b/Lab5/Lab5.TouristInformationCenter/InOutUtils.cs
index d61e25e..67dc32c 100644
--- a/Lab5/Lab5.TouristInformationCenter/InOutUtils.cs
+++ b/Lab5/Lab5.TouristInformationCenter/InOutUtils.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
@@ -12,11 +12,11 @@ namespace Lab5.TouristInformationCenter
class InOutUtils
{
///
- /// Append the museums from the second container to the first one
+ /// Append the locations from the second container to the first one
///
/// First container
/// Second container
- private static void AppendContainer(MuseumsContainer container1, MuseumsContainer container2)
+ private static void AppendContainer(LocationsContainer container1, LocationsContainer container2)
{
for (int i = 0; i < container2.Count; i++)
{
@@ -25,61 +25,61 @@ namespace Lab5.TouristInformationCenter
}
///
- /// Decode a list of museums from a given list of lines.
+ /// Decode a list of locations from a given list of lines.
///
///
- /// Container of museums
- public static MuseumsContainer DecodeMuseums(List lines)
+ /// Container of locations
+ public static LocationsContainer DecodeLocations(List lines)
{
- MuseumsContainer container = new MuseumsContainer(lines.Count-2);
+ LocationsContainer container = new LocationsContainer(lines.Count-2);
string city = lines[0];
string manager = lines[1];
for (int i = 2; i < lines.Count; i++)
{
string line = lines[i];
string[] values = line.Split(';');
- string name = values[0];
- string type = values[1];
- List workdays = new List();
- for (int j = 1; j <= 7; j++)
- {
- if (int.Parse(values[j + 1]) == 1)
- {
- workdays.Add((Weekday)j);
- }
- }
- double price = double.Parse(values[9]);
- bool hasGuide = int.Parse(values[10]) == 1;
+ /* string name = values[0]; */
+ /* string type = values[1]; */
+ /* List workdays = new List(); */
+ /* for (int j = 1; j <= 7; j++) */
+ /* { */
+ /* if (int.Parse(values[j + 1]) == 1) */
+ /* { */
+ /* workdays.Add((Weekday)j); */
+ /* } */
+ /* } */
+ /* double price = double.Parse(values[9]); */
+ /* bool hasGuide = int.Parse(values[10]) == 1; */
- Museum museum = new Museum(name, city, manager, type, workdays, price, hasGuide);
- container.Add(museum);
- }
+ /* Location location = new Location(name, city, manager, type, workdays, price, hasGuide); */
+ /* container.Add(location); */
+ }
return container;
}
///
- /// Read and decode a list of museums from a file.
+ /// Read and decode a list of locations from a file.
///
/// Target file
- /// Container of museums
- public static MuseumsContainer ReadMuseumsFromCSV(string filename)
+ /// Container of locations
+ public static LocationsContainer ReadLocationsFromCSV(string filename)
{
List lines = new List();
foreach (string line in File.ReadAllLines(filename, Encoding.UTF8))
{
lines.Add(line);
}
- return DecodeMuseums(lines);
+ return DecodeLocations(lines);
}
///
- /// Read all the entries from a zip file and decode the museums inside the csv entries.
+ /// Read all the entries from a zip file and decode the locations inside the csv entries.
///
/// Target filename
- /// Register of museums
- public static MuseumsContainer ReadMuseumsFromZIP(string filename)
+ /// Register of locations
+ public static LocationsContainer ReadLocationsFromZIP(string filename)
{
- MuseumsContainer mainContainer = new MuseumsContainer();
+ LocationsContainer mainContainer = new LocationsContainer();
using (ZipArchive zipFile = ZipFile.Open(filename, ZipArchiveMode.Read))
{
@@ -95,89 +95,90 @@ namespace Lab5.TouristInformationCenter
}
}
- MuseumsContainer contaienr = DecodeMuseums(lines);
+ LocationsContainer contaienr = DecodeLocations(lines);
AppendContainer(mainContainer, contaienr);
}
-
+
}
-
+
return mainContainer;
}
///
- /// Read and decode lists of museums from multiple files and put into a single register.
+ /// Read and decode lists of locations from multiple files and put into a single register.
///
/// Target files
- /// Register containing museums from all files
- public static MuseumsContainer ReadMuseums(params string[] filenames)
+ /// Register containing locations from all files
+ public static LocationsContainer ReadLocations(params string[] filenames)
{
- MuseumsContainer mainContainer = new MuseumsContainer();
+ LocationsContainer mainContainer = new LocationsContainer();
foreach (string filename in filenames)
{
if (filename.EndsWith(".csv"))
{
- AppendContainer(mainContainer, ReadMuseumsFromCSV(filename));
+ AppendContainer(mainContainer, ReadLocationsFromCSV(filename));
}
else if(filename.EndsWith(".zip"))
{
- AppendContainer(mainContainer, ReadMuseumsFromZIP(filename));
+ AppendContainer(mainContainer, ReadLocationsFromZIP(filename));
}
}
return mainContainer;
}
- private static string CreateMuseumLine(Museum museum)
+ private static string CreateLocationLine(Location location)
{
- string workDays = "";
- workDays += museum.Workdays.Contains(Weekday.Monday) ? "1" : "0";
- workDays += museum.Workdays.Contains(Weekday.Tuesday) ? ";1" : ";0";
- workDays += museum.Workdays.Contains(Weekday.Wednesday) ? ";1" : ";0";
- workDays += museum.Workdays.Contains(Weekday.Thursday) ? ";1" : ";0";
- workDays += museum.Workdays.Contains(Weekday.Friday) ? ";1" : ";0";
- workDays += museum.Workdays.Contains(Weekday.Saturday) ? ";1" : ";0";
- workDays += museum.Workdays.Contains(Weekday.Sunday) ? ";1" : ";0";
-
- return String.Join(";", museum.City, museum.Name, workDays, museum.Price);
+/* string workDays = ""; */
+/* workDays += location.Workdays.Contains(Weekday.Monday) ? "1" : "0"; */
+/* workDays += location.Workdays.Contains(Weekday.Tuesday) ? ";1" : ";0"; */
+/* workDays += location.Workdays.Contains(Weekday.Wednesday) ? ";1" : ";0"; */
+/* workDays += location.Workdays.Contains(Weekday.Thursday) ? ";1" : ";0"; */
+/* workDays += location.Workdays.Contains(Weekday.Friday) ? ";1" : ";0"; */
+/* workDays += location.Workdays.Contains(Weekday.Saturday) ? ";1" : ";0"; */
+/* workDays += location.Workdays.Contains(Weekday.Sunday) ? ";1" : ";0"; */
+/* */
+/* return String.Join(";", location.City, location.Name, workDays, location.Price); */
+ return "";
}
-
+
///
- /// Write and encode a list of museums to a file. The file will be in a csv format using ";" as seperators.
+ /// Write and encode a list of locations to a file. The file will be in a csv format using ";" as seperators.
///
/// Target file
- /// Container of museums
- public static void WriteMuseums(string filename, MuseumsContainer container)
+ /// Container of locations
+ public static void WriteLocations(string filename, LocationsContainer container)
{
string[] lines = new string[container.Count];
for (int i = 0; i < container.Count; i++)
{
- Museum museum = container.Get(i);
- lines[i] = CreateMuseumLine(museum);
+ Location location = container.Get(i);
+ lines[i] = CreateLocationLine(location);
}
File.WriteAllLines(filename, lines, Encoding.UTF8);
}
///
- /// Write and encode a list of museums to a file from a register.
+ /// Write and encode a list of locations to a file from a register.
///
/// Target location
- /// Register containing museums
- public static void WriteMuseums(string filename, MuseumsRegister register)
+ /// Register containing locations
+ public static void WriteLocations(string filename, Register register)
{
int n = register.Count();
string[] lines = new string[n];
for (int i = 0; i < n; i++)
{
- Museum museum = register.GetByIndex(i);
- lines[i] = CreateMuseumLine(museum);
+ Location location = register.GetByIndex(i);
+ lines[i] = CreateLocationLine(location);
}
File.WriteAllLines(filename, lines, Encoding.UTF8);
}
///
- /// Write out a container of museums in a table to the console.
+ /// Write out a container of locations in a table to the console.
///
- /// Container of museums
- public static void PrintMuseums(MuseumsContainer container)
+ /// Container of locations
+ public static void PrintLocations(LocationsContainer container)
{
if (container.Count == 0)
{
@@ -186,28 +187,28 @@ namespace Lab5.TouristInformationCenter
}
Console.WriteLine(new string('-', 123));
- Console.WriteLine("| {0,-20} | {1,-10} | {2,-20} | {3,-10} | {4,18} | {5,13} | {6,-4} |", "Vardas", "Miestas", "Atsakingas", "Tipas", "Darbo dienų kiekis", "Kaina", "Turi gidą?");
+ /* Console.WriteLine("| {0,-20} | {1,-10} | {2,-20} | {3,-10} | {4,18} | {5,13} | {6,-4} |", "Vardas", "Miestas", "Atsakingas", "Tipas", "Darbo dienų kiekis", "Kaina", "Turi gidą?"); */
Console.WriteLine(new string('-', 123));
for (int i = 0; i < container.Count; i++)
{
- Museum m = container.Get(i);
- Console.WriteLine("| {0,-20} | {1,-10} | {2,-20} | {3,-10} | {4,18} | {5,13:f2} | {6,-10} |", m.Name, m.City, m.Manager, m.Type, m.Workdays.Count, m.Price, m.HasGuide ? "Taip" : "Ne");
+ Location l = container.Get(i);
+ /* Console.WriteLine("| {0,-20} | {1,-10} | {2,-20} | {3,-10} | {4,18} | {5,13:f2} | {6,-10} |", l.Name, l.City, l.Manager, l.Type, l.Workdays.Count, l.Price, l.HasGuide ? "Taip" : "Ne"); */
}
Console.WriteLine(new string('-', 123));
}
///
- /// Write out a list of museums in a table to the console from a register.
+ /// Write out a list of locations in a table to the console from a register.
///
- /// Register containing museums
- public static void PrintMuseums(MuseumsRegister register)
+ /// Register containing locations
+ public static void PrintLocations(Register register)
{
- MuseumsContainer museums = new MuseumsContainer();
+ LocationsContainer locations = new LocationsContainer();
for (int i = 0; i < register.Count(); i++)
{
- museums.Add(register.GetByIndex(i));
+ locations.Add(register.GetByIndex(i));
}
- PrintMuseums(museums);
+ PrintLocations(locations);
}
}
}
diff --git a/Lab5/Lab5.TouristInformationCenter/Lab5.TouristInformationCenter.csproj b/Lab5/Lab5.TouristInformationCenter/Lab5.TouristInformationCenter.csproj
index 23df604..958d2f1 100644
--- a/Lab5/Lab5.TouristInformationCenter/Lab5.TouristInformationCenter.csproj
+++ b/Lab5/Lab5.TouristInformationCenter/Lab5.TouristInformationCenter.csproj
@@ -2,7 +2,7 @@
Exe
- netcoreapp2.1
+ netcoreapp3.0
diff --git a/Lab5/Lab5.TouristInformationCenter/Location.cs b/Lab5/Lab5.TouristInformationCenter/Location.cs
new file mode 100644
index 0000000..fdebed6
--- /dev/null
+++ b/Lab5/Lab5.TouristInformationCenter/Location.cs
@@ -0,0 +1,26 @@
+
+namespace Lab5.TouristInformationCenter
+{
+ abstract class Location
+ {
+ public string Name { get; set; }
+ public string City { get; set; }
+ public string Address { get; set; }
+ public int Year { get; set; }
+ public string Manager { get; set; }
+
+ public Location(string name, string city, string address, int year, string manager)
+ {
+ Name = name;
+ City = city;
+ Address = address;
+ Year = year;
+ Manager = manager;
+ }
+
+ public int CompareTo(Location other)
+ {
+ return Name.CompareTo(other.Name);
+ }
+ }
+}
diff --git a/Lab5/Lab5.TouristInformationCenter/LocationsAlytus.csv b/Lab5/Lab5.TouristInformationCenter/LocationsAlytus.csv
new file mode 100644
index 0000000..973fad3
--- /dev/null
+++ b/Lab5/Lab5.TouristInformationCenter/LocationsAlytus.csv
@@ -0,0 +1,2 @@
+Alytus
+Ona Onaite
diff --git a/Lab5/Lab5.TouristInformationCenter/LocationsComparator.cs b/Lab5/Lab5.TouristInformationCenter/LocationsComparator.cs
new file mode 100644
index 0000000..13e9830
--- /dev/null
+++ b/Lab5/Lab5.TouristInformationCenter/LocationsComparator.cs
@@ -0,0 +1,10 @@
+namespace Lab5.TouristInformationCenter
+{
+ class LocationsComparator
+ {
+ public virtual int Compare(Location a, Location b)
+ {
+ return a.CompareTo(b);
+ }
+ }
+}
diff --git a/Lab5/Lab5.TouristInformationCenter/LocationsComparatorByNameAddress.cs b/Lab5/Lab5.TouristInformationCenter/LocationsComparatorByNameAddress.cs
new file mode 100644
index 0000000..e80242f
--- /dev/null
+++ b/Lab5/Lab5.TouristInformationCenter/LocationsComparatorByNameAddress.cs
@@ -0,0 +1,17 @@
+namespace Lab5.TouristInformationCenter
+{
+ class LocationsComparatorByNameAddress : LocationsComparator
+ {
+ public override int Compare(Location a, Location b)
+ {
+ int nameCompare = a.Name.CompareTo(b.Name);
+ if (nameCompare == 0)
+ {
+ return a.Address.CompareTo(b.Address);
+ } else
+ {
+ return nameCompare;
+ }
+ }
+ }
+}
diff --git a/Lab5/Lab5.TouristInformationCenter/LocationsContainer.cs b/Lab5/Lab5.TouristInformationCenter/LocationsContainer.cs
new file mode 100644
index 0000000..52383d6
--- /dev/null
+++ b/Lab5/Lab5.TouristInformationCenter/LocationsContainer.cs
@@ -0,0 +1,217 @@
+using System.Collections.Generic;
+
+namespace Lab5.TouristInformationCenter
+{
+ class LocationsContainer
+ {
+ private Location[] locations;
+ private int Capacity;
+ public int Count { get; private set; }
+ public LocationsContainer(int capacity = 16)
+ {
+ Capacity = capacity;
+ locations = new Location[capacity];
+ }
+
+ public LocationsContainer(LocationsContainer container) : this(container.Capacity)
+ {
+ for (int i = 0; i < container.Count; i++)
+ {
+ Add(container.Get(i));
+ }
+ }
+
+ ///
+ /// Add a location to the end of the container
+ ///
+ /// Target location
+ public void Add(Location location)
+ {
+ if (Count == Capacity)
+ {
+ EnsureCapacity(Capacity * 2);
+ }
+
+ locations[Count] = location;
+ Count++;
+ }
+
+ ///
+ /// Get a musem by index from container
+ ///
+ /// Target index
+ /// Location at given index
+ public Location Get(int index)
+ {
+ return locations[index];
+ }
+
+ ///
+ /// Check if given location exists in container
+ ///
+ /// Target location
+ /// True if contains
+ public bool Contains(Location location)
+ {
+ for (int i = 0; i < Count; i++)
+ {
+ if (locations[i].Equals(location))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ ///
+ /// Put a location at a specific index
+ ///
+ /// Target index
+ /// Target location
+ public void Put(int index, Location location)
+ {
+ locations[index] = location;
+ }
+
+ /*
+
+ ///
+ /// Filter by property "HasGuide"
+ ///
+ /// Target value
+ /// A filtered container of locations
+ public LocationsContainer FilterByGuide(bool hasGuide)
+ {
+ LocationsContainer filtered = new LocationsContainer();
+ for (int i = 0; i < Count; i++)
+ {
+ Location location = locations[i];
+ if (location.HasGuide == hasGuide)
+ {
+ filtered.Add(location);
+ }
+ }
+ return filtered;
+ }
+
+ ///
+ /// Filter by property "Type".
+ ///
+ /// Target type
+ /// A filtered container of locations
+ public LocationsContainer FilterByType(string type)
+ {
+ LocationsContainer filtered = new LocationsContainer();
+ for (int i = 0; i < Count; i++)
+ {
+ Location location = locations[i];
+ if (location.Type == type)
+ {
+ filtered.Add(location);
+ }
+ }
+ return filtered;
+ }
+
+ ///
+ /// Filter by property "Price".
+ ///
+ /// Maximum allowed price to be included
+ /// A container with locations that dont't have a larger price then "maxPrice"
+ public LocationsContainer FilterByPrice(double maxPrice)
+ {
+ LocationsContainer filtered = new LocationsContainer();
+ for (int i = 0; i < Count; i++)
+ {
+ Location location = locations[i];
+ if (location.Price <= maxPrice)
+ {
+ filtered.Add(location);
+ }
+ }
+ return filtered;
+ }
+
+ ///
+ /// Return a list of "active" locations from the contaner.
+ /// A location is considered active if it is working at least some amount a week.
+ ///
+ /// Threshold which determines what is active
+ /// A container of "active" locations
+ public LocationsContainer FilterByActivity(int threshold)
+ {
+ LocationsContainer filtered = new LocationsContainer();
+ for (int i = 0; i < Count; i++)
+ {
+ Location location = locations[i];
+ if (location.Workdays.Count >= threshold)
+ {
+ filtered.Add(location);
+ }
+ }
+ return filtered;
+ }
+
+ ///
+ /// Filter by property "Name"
+ ///
+ /// Target name
+ /// A filtered container
+ public LocationsContainer FilterByName(string name)
+ {
+ LocationsContainer filtered = new LocationsContainer();
+ for (int i = 0; i < Count; i++)
+ {
+ Location location = locations[i];
+ if (location.Name == name)
+ {
+ filtered.Add(location);
+ }
+ }
+ return filtered;
+ }
+ */
+
+ ///
+ /// Sort container by given comparator
+ ///
+ /// Defined how it should be sorted
+ public void Sort(LocationsComparator comparator)
+ {
+ for (int i = 0; i < Count - 1; i++)
+ {
+ for (int j = i + 1; j < Count; j++)
+ {
+ Location a = locations[i];
+ Location b = locations[j];
+ if (comparator.Compare(a, b) > 0)
+ {
+ locations[i] = b;
+ locations[j] = a;
+ }
+ }
+ }
+ }
+
+ ///
+ /// Sort container by "Name" in alphabetical order.
+ ///
+ public void Sort()
+ {
+ Sort(new LocationsComparator());
+ }
+
+ private void EnsureCapacity(int minimumCapacity)
+ {
+ if (minimumCapacity <= Capacity) return;
+
+ Location[] locationsClone = new Location[minimumCapacity];
+ for (int i = 0; i < Count; i++)
+ {
+ locationsClone[i] = locations[i];
+ }
+ Capacity = minimumCapacity;
+ locations = locationsClone;
+ }
+ }
+}
diff --git a/Lab5/Lab5.TouristInformationCenter/MuseumsKaunas.csv b/Lab5/Lab5.TouristInformationCenter/LocationsKaunas.csv
similarity index 100%
rename from Lab5/Lab5.TouristInformationCenter/MuseumsKaunas.csv
rename to Lab5/Lab5.TouristInformationCenter/LocationsKaunas.csv
diff --git a/Lab5/Lab5.TouristInformationCenter/MuseumsVilnius.csv b/Lab5/Lab5.TouristInformationCenter/LocationsVilnius.csv
similarity index 100%
rename from Lab5/Lab5.TouristInformationCenter/MuseumsVilnius.csv
rename to Lab5/Lab5.TouristInformationCenter/LocationsVilnius.csv
diff --git a/Lab5/Lab5.TouristInformationCenter/Museum.cs b/Lab5/Lab5.TouristInformationCenter/Museum.cs
index 09cbfa4..0e769f6 100644
--- a/Lab5/Lab5.TouristInformationCenter/Museum.cs
+++ b/Lab5/Lab5.TouristInformationCenter/Museum.cs
@@ -1,24 +1,19 @@
-using System.Collections.Generic;
+using System.Collections.Generic;
namespace Lab5.TouristInformationCenter
{
///
/// Class used for storing data related a single museum.
///
- class Museum
+ class Location : Location
{
- public string Name { get; set; }
- public string City { get; set; }
- public string Manager { get; set; }
public string Type { get; set; }
public List Workdays { get; set; }
public double Price { get; set; }
public bool HasGuide { get; set; }
- public Museum(string name, string city, string manager, string type, List workdays, double price, bool hasGuide)
+
+ public Location(string name, string city, string address, int year, string manager, string type, List workdays, double price, bool hasGuide) : base(name, city, address, year, manager)
{
- Name = name;
- Manager = manager;
- City = city;
Type = type;
Workdays = workdays;
Price = price;
diff --git a/Lab5/Lab5.TouristInformationCenter/MuseumsContainer.cs b/Lab5/Lab5.TouristInformationCenter/MuseumsContainer.cs
deleted file mode 100644
index be47016..0000000
--- a/Lab5/Lab5.TouristInformationCenter/MuseumsContainer.cs
+++ /dev/null
@@ -1,246 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace Lab5.TouristInformationCenter
-{
- class MuseumsContainer
- {
- private Museum[] museums;
- private int Capacity;
- public int Count { get; private set; }
- public MuseumsContainer(int capacity = 16)
- {
- Capacity = capacity;
- museums = new Museum[capacity];
- }
-
- public MuseumsContainer(MuseumsContainer container) : this(container.Capacity)
- {
- for (int i = 0; i < container.Count; i++)
- {
- Add(container.Get(i));
- }
- }
-
- ///
- /// Add a museum to the end of the container
- ///
- /// Target museum
- public void Add(Museum museum)
- {
- if (Count == Capacity)
- {
- EnsureCapacity(Capacity * 2);
- }
-
- museums[Count] = museum;
- Count++;
- }
-
- ///
- /// Get a musem by index from container
- ///
- /// Target index
- /// Museum at given index
- public Museum Get(int index)
- {
- return museums[index];
- }
-
- ///
- /// Check if given museum exists in container
- ///
- /// Target museum
- /// True if contains
- public bool Contains(Museum museum)
- {
- for (int i = 0; i < Count; i++)
- {
- if (museums[i].Equals(museum))
- {
- return true;
- }
- }
- return false;
- }
-
- ///
- /// Put a museum at a specific index
- ///
- /// Target index
- /// Target museum
- public void Put(int index, Museum museum)
- {
- museums[index] = museum;
- }
-
- ///
- /// Filter by property "HasGuide"
- ///
- /// Target value
- /// A filtered container of museums
- public MuseumsContainer FilterByGuide(bool hasGuide)
- {
- MuseumsContainer filtered = new MuseumsContainer();
- for (int i = 0; i < Count; i++)
- {
- Museum museum = museums[i];
- if (museum.HasGuide == hasGuide)
- {
- filtered.Add(museum);
- }
- }
- return filtered;
- }
-
- ///
- /// Filter by property "Type".
- ///
- /// Target type
- /// A filtered container of museums
- public MuseumsContainer FilterByType(string type)
- {
- MuseumsContainer filtered = new MuseumsContainer();
- for (int i = 0; i < Count; i++)
- {
- Museum museum = museums[i];
- if (museum.Type == type)
- {
- filtered.Add(museum);
- }
- }
- return filtered;
- }
-
- ///
- /// Filter by property "Price".
- ///
- /// Maximum allowed price to be included
- /// A container with museums that dont't have a larger price then "maxPrice"
- public MuseumsContainer FilterByPrice(double maxPrice)
- {
- MuseumsContainer filtered = new MuseumsContainer();
- for (int i = 0; i < Count; i++)
- {
- Museum museum = museums[i];
- if (museum.Price <= maxPrice)
- {
- filtered.Add(museum);
- }
- }
- return filtered;
- }
-
- ///
- /// Filter by property "Type"
- ///
- /// Target city
- /// A container of museums
- public MuseumsContainer FilterByCity(string city)
- {
- MuseumsContainer filtered = new MuseumsContainer();
- for (int i = 0; i < Count; i++)
- {
- Museum museum = museums[i];
- if (museum.City == city)
- {
- filtered.Add(museum);
- }
- }
- return filtered;
- }
-
- ///
- /// Return a list of "active" museums from the contaner.
- /// A museum is considered active if it is working at least some amount a week.
- ///
- /// Threshold which determines what is active
- /// A container of "active" museums
- public MuseumsContainer FilterByActivity(int threshold)
- {
- MuseumsContainer filtered = new MuseumsContainer();
- for (int i = 0; i < Count; i++)
- {
- Museum museum = museums[i];
- if (museum.Workdays.Count >= threshold)
- {
- filtered.Add(museum);
- }
- }
- return filtered;
- }
-
- ///
- /// Filter by property "Name"
- ///
- /// Target name
- /// A filtered container
- public MuseumsContainer FilterByName(string name)
- {
- MuseumsContainer filtered = new MuseumsContainer();
- for (int i = 0; i < Count; i++)
- {
- Museum museum = museums[i];
- if (museum.Name == name)
- {
- filtered.Add(museum);
- }
- }
- return filtered;
- }
-
- ///
- /// Get all of the different types of cities.
- ///
- /// A list of city names
- public List GetAllCities()
- {
- List cities = new List();
- for (int i = 0; i < Count; i++)
- {
- Museum museum = museums[i];
- if (!cities.Contains(museum.City))
- {
- cities.Add(museum.City);
- }
- }
- return cities;
- }
-
- ///
- /// Sort container by "City" and "Name" in alphabetical order.
- ///
- public void Sort()
- {
- for (int i = 0; i < Count - 1; i++)
- {
- for (int j = i + 1; j < Count; j++)
- {
- Museum a = museums[i];
- Museum b = museums[j];
- int nameCompare = a.Name.CompareTo(b.Name);
- int cityCompare = a.City.CompareTo(b.City);
- if (cityCompare > 0 || (cityCompare == 0 && nameCompare > 0))
- {
- museums[i] = b;
- museums[j] = a;
- }
- }
- }
- }
-
- private void EnsureCapacity(int minimumCapacity)
- {
- if (minimumCapacity <= Capacity) return;
-
- Museum[] museumsClone = new Museum[minimumCapacity];
- for (int i = 0; i < Count; i++)
- {
- museumsClone[i] = museums[i];
- }
- Capacity = minimumCapacity;
- museums = museumsClone;
- }
- }
-}
diff --git a/Lab5/Lab5.TouristInformationCenter/MuseumsRegister.cs b/Lab5/Lab5.TouristInformationCenter/MuseumsRegister.cs
deleted file mode 100644
index f538573..0000000
--- a/Lab5/Lab5.TouristInformationCenter/MuseumsRegister.cs
+++ /dev/null
@@ -1,170 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace Lab5.TouristInformationCenter
-{
- ///
- /// Class used to store multiple museums in one place
- ///
- class MuseumsRegister
- {
- private MuseumsContainer AllMuseums;
-
- public MuseumsRegister()
- {
- AllMuseums = new MuseumsContainer();
- }
-
- public MuseumsRegister(MuseumsContainer museums)
- {
- AllMuseums = new MuseumsContainer(museums);
- }
-
- ///
- /// Add one museum to the register.
- ///
- /// Target museum
- public void Add(Museum museum)
- {
- AllMuseums.Add(museum);
- }
-
- ///
- /// The amount of stored museums in the register.
- ///
- /// Museum count
- public int Count()
- {
- return AllMuseums.Count;
- }
-
- ///
- /// Access museum from register by index
- ///
- /// Target index
- /// Museum
- public Museum GetByIndex(int index)
- {
- return AllMuseums.Get(index);
- }
-
- ///
- /// Return a list of active museums from the register.
- /// A museum is considered active if it is working at least some amount a week.
- ///
- /// Threshold which determines what is active
- /// A list of active museums
- public MuseumsContainer FilterByActiveMuseums(int threshold)
- {
- return AllMuseums.FilterByActivity(threshold);
- }
-
- ///
- /// Find museum that work the most days in a week
- ///
- /// Most active museum
- public Museum FindMostActiveMuseum()
- {
- if (AllMuseums.Count == 0)
- {
- return null;
- }
-
- Museum mostActive = AllMuseums.Get(0);
- for (int i = 0; i < AllMuseums.Count; i++)
- {
- Museum museum = AllMuseums.Get(i);
- if (museum.Workdays.Count > mostActive.Workdays.Count)
- {
- mostActive = museum;
- }
- }
- return mostActive;
- }
-
- ///
- /// Find all museums that work the most days in a week
- ///
- ///
- public MuseumsContainer FindMostActiveMuseums()
- {
- Museum mostActive = FindMostActiveMuseum();
- MuseumsContainer activeMuseums = new MuseumsContainer();
- for (int i = 0; i < AllMuseums.Count; i++)
- {
- Museum museum = AllMuseums.Get(i);
- if (museum.Workdays.Count == mostActive.Workdays.Count)
- {
- activeMuseums.Add(museum);
- }
- }
- return activeMuseums;
- }
-
- ///
- /// Get all of the different types of cities.
- ///
- /// A list of city names
- public List GetAllCities()
- {
- return AllMuseums.GetAllCities();
- }
-
- ///
- /// Filter the museums by city name from register
- ///
- /// Target city
- /// A container of museums
- public MuseumsContainer FilterByCity(string city)
- {
- return AllMuseums.FilterByCity(city);
- }
-
- ///
- /// Filter by property "Type".
- ///
- /// Target type
- /// A filtered container of museums
- public MuseumsContainer FilterByType(string type)
- {
- return AllMuseums.FilterByType(type);
- }
-
- private List GetMuseumNames()
- {
- List result = new List();
- for (int i = 0; i < AllMuseums.Count; i++)
- {
- Museum museum = AllMuseums.Get(i);
- if (!result.Contains(museum.Name))
- {
- result.Add(museum.Name);
- }
- }
- return result;
- }
-
- ///
- /// Find all museums that have matching names
- ///
- /// A container with museums that have matching names
- public MuseumsContainer FindMuseumsWithDuplicateNames()
- {
- MuseumsContainer result = new MuseumsContainer();
- List names = GetMuseumNames();
- foreach (string name in names)
- {
- MuseumsContainer museumsByName = AllMuseums.FilterByName(name);
- if (museumsByName.Count <= 1) continue;
-
- for (int i = 0; i < museumsByName.Count; i++)
- {
- result.Add(museumsByName.Get(i));
- }
- }
- return result;
- }
-
- }
-}
diff --git a/Lab5/Lab5.TouristInformationCenter/Program.cs b/Lab5/Lab5.TouristInformationCenter/Program.cs
index c76e95c..f6f827f 100644
--- a/Lab5/Lab5.TouristInformationCenter/Program.cs
+++ b/Lab5/Lab5.TouristInformationCenter/Program.cs
@@ -8,12 +8,25 @@ namespace Lab5.TouristInformationCenter
static void Main(string[] args)
{
// Read all museums from initial data files
- MuseumsContainer container = InOutUtils.ReadMuseums("MuseumsKaunas.csv", "MuseumsVilnius.csv");
- MuseumsRegister register = new MuseumsRegister(container);
- Console.WriteLine("Visi muziejai:");
- InOutUtils.PrintMuseums(register);
+ LocationsContainer container = InOutUtils.ReadLocations("LocationsKaunas.csv", "LocationsVilnius.csv", "LocationsAlytus.csv");
+ Register register = new Register(container);
+ Console.WriteLine("Visos vietos:");
+ InOutUtils.PrintLocations(register);
Console.WriteLine();
+ int locationCount = register.CountLocationsThatHaveGuides();
+ Console.WriteLine("Lankytinų vietų skaičius kurie turi gidus: {0}", locationCount);
+ Console.WriteLine();
+
+ List types = register.FindCommonTypesWithGuidesAtWeekends();
+ Console.Write("Lankytinų vietų tipai kuriouse galima apsilankyti visuose miestuose savaitgaliais:");
+ foreach (string type in types)
+ {
+ Console.WriteLine("* {0}", type);
+ }
+ Console.WriteLine();
+
+ /*
// Write out a list of cities and if they have at least one museum that is free and with a guide
List cities = register.GetAllCities();
foreach (string city in cities)
@@ -41,6 +54,7 @@ namespace Lab5.TouristInformationCenter
MuseumsContainer artMuseums = register.FilterByType("Dailė");
artMuseums.Sort();
InOutUtils.WriteMuseums("Dailė.csv", artMuseums);
+ */
}
}
}
diff --git a/Lab5/Lab5.TouristInformationCenter/Register.cs b/Lab5/Lab5.TouristInformationCenter/Register.cs
new file mode 100644
index 0000000..d934b51
--- /dev/null
+++ b/Lab5/Lab5.TouristInformationCenter/Register.cs
@@ -0,0 +1,283 @@
+using System;
+using System.Collections.Generic;
+
+namespace Lab5.TouristInformationCenter
+{
+ ///
+ /// Class used to store multiple locations in one place
+ ///
+ class Register
+ {
+ private LocationsContainer AllLocations;
+
+ public Register()
+ {
+ AllLocations = new LocationsContainer();
+ }
+
+ public Register(LocationsContainer locations)
+ {
+ AllLocations = new LocationsContainer(locations);
+ }
+
+ ///
+ /// Add one location to the register.
+ ///
+ /// Target location
+ public void Add(Location location)
+ {
+ AllLocations.Add(location);
+ }
+
+ ///
+ /// The amount of stored locations in the register.
+ ///
+ /// Location count
+ public int Count()
+ {
+ return AllLocations.Count;
+ }
+
+ ///
+ /// Access location from register by index
+ ///
+ /// Target index
+ /// Location
+ public Location GetByIndex(int index)
+ {
+ return AllLocations.Get(index);
+ }
+
+ public int CountLocationsThatHaveGuides()
+ {
+ int count = 0;
+ for (int i = 0; i < AllLocations.Count; i++)
+ {
+ Location museum = AllLocations.Get(i) as Location;
+ if (museum != null && museum.HasGuide)
+ {
+ count++;
+ }
+ }
+ return count;
+ }
+
+ ///
+ /// Get all of the different types of cities.
+ ///
+ /// A list of city names
+ public List GetAllCities()
+ {
+ List cities = new List();
+ for (int i = 0; i < AllLocations.Count; i++)
+ {
+ Location location = AllLocations.Get(i);
+ if (!cities.Contains(location.City))
+ {
+ cities.Add(location.City);
+ }
+ }
+ return cities;
+ }
+
+ public List GetAllTypes()
+ {
+ List types = new List();
+ for (int i = 0; i < AllLocations.Count; i++)
+ {
+ Location museum = AllLocations.Get(i) as Location;
+ if (museum != null && !types.Contains(museum.Type))
+ {
+ types.Add(museum.Type);
+ }
+ }
+ return types;
+ }
+
+ public List FindCommonTypesBetweenCities()
+ {
+ List allCities = GetAllCities();
+ Dictionary types = new Dictionary();
+ foreach (string type in GetAllTypes())
+ {
+ types.Add(type, 0);
+ foreach (string city in allCities)
+ {
+ for (int i = 0; i < AllLocations.Count; i++)
+ {
+ Location museum = AllLocations.Get(i) as Location;
+ if (museum != null && museum.Type == type && museum.City == city)
+ {
+ types[type]++;
+ }
+ }
+ }
+ }
+
+ List result = new List();
+ foreach (var item in types)
+ {
+ if (item.Value == allCities.Count)
+ {
+ result.Add(item.Key);
+ }
+ }
+ return result;
+ }
+
+ public bool HasGuideAtWeekendByType(string type)
+ {
+ for (int i = 0; i < AllLocations.Count; i++)
+ {
+ Museum museum = AllLocations.Get(i) as Museum;
+ if (museum != null && museum.Type == type && museum.HasGuide)
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public List FindCommonTypesWithGuidesAtWeekends()
+ {
+ List types = new List();
+ foreach (string type in FindCommonTypesBetweenCities())
+ {
+ if (HasGuideAtWeekendByType(type))
+ {
+ types.Add(type);
+ }
+ }
+ return types;
+ }
+
+ public LocationsContainer FindLocationsByAuthor(string author)
+ {
+ LocationsContainer locations = new LocationsContainer();
+ for (int i = 0; i < AllLocations.Count; i++)
+ {
+ Statue statue = AllLocations.Get(i) as Statue;
+ if (statue != null && statue.Author == author)
+ {
+ locations.Add(statue);
+ }
+ }
+ return locations;
+ }
+
+ public LocationsContainer FindLocationsAfterYear(int year)
+ {
+ LocationsContainer locations = new LocationsContainer();
+ for (int i = 0; i < AllLocations.Count; i++)
+ {
+ Location location = AllLocations.Get(i);
+ if (location.Year > year)
+ {
+ locations.Add(location);
+ }
+ }
+ return locations;
+ }
+
+ /*
+ ///
+ /// Return a list of active locations from the register.
+ /// A location is considered active if it is working at least some amount a week.
+ ///
+ /// Threshold which determines what is active
+ /// A list of active locations
+ public LocationsContainer FilterByActiveLocations(int threshold)
+ {
+ return AllLocations.FilterByActivity(threshold);
+ }
+
+ ///
+ /// Find location that work the most days in a week
+ ///
+ /// Most active location
+ public Location FindMostActiveLocation()
+ {
+ if (AllLocations.Count == 0)
+ {
+ return null;
+ }
+
+ Location mostActive = AllLocations.Get(0);
+ for (int i = 0; i < AllLocations.Count; i++)
+ {
+ Location location = AllLocations.Get(i);
+ if (location.Workdays.Count > mostActive.Workdays.Count)
+ {
+ mostActive = location;
+ }
+ }
+ return mostActive;
+ }
+
+ ///
+ /// Find all locations that work the most days in a week
+ ///
+ ///
+ public LocationsContainer FindMostActiveLocations()
+ {
+ Location mostActive = FindMostActiveLocation();
+ LocationsContainer activeLocations = new LocationsContainer();
+ for (int i = 0; i < AllLocations.Count; i++)
+ {
+ Location location = AllLocations.Get(i);
+ if (location.Workdays.Count == mostActive.Workdays.Count)
+ {
+ activeLocations.Add(location);
+ }
+ }
+ return activeLocations;
+ }
+
+ ///
+ /// Filter by property "Type".
+ ///
+ /// Target type
+ /// A filtered container of locations
+ public LocationsContainer FilterByType(string type)
+ {
+ return AllLocations.FilterByType(type);
+ }
+
+ private List GetLocationNames()
+ {
+ List result = new List();
+ for (int i = 0; i < AllLocations.Count; i++)
+ {
+ Location location = AllLocations.Get(i);
+ if (!result.Contains(location.Name))
+ {
+ result.Add(location.Name);
+ }
+ }
+ return result;
+ }
+
+ ///
+ /// Find all locations that have matching names
+ ///
+ /// A container with locations that have matching names
+ public LocationsContainer FindLocationsWithDuplicateNames()
+ {
+ LocationsContainer result = new LocationsContainer();
+ List names = GetLocationNames();
+ foreach (string name in names)
+ {
+ LocationsContainer locationsByName = AllLocations.FilterByName(name);
+ if (locationsByName.Count <= 1) continue;
+
+ for (int i = 0; i < locationsByName.Count; i++)
+ {
+ result.Add(locationsByName.Get(i));
+ }
+ }
+ return result;
+ }
+ */
+
+ }
+}
diff --git a/Lab5/Lab5.TouristInformationCenter/Statue.cs b/Lab5/Lab5.TouristInformationCenter/Statue.cs
new file mode 100644
index 0000000..1038bd9
--- /dev/null
+++ b/Lab5/Lab5.TouristInformationCenter/Statue.cs
@@ -0,0 +1,15 @@
+
+namespace Lab5.TouristInformationCenter
+{
+ class Statue : Location {
+ public string Author { get; set; }
+ public string MonumentName { get; set; }
+
+ public Statue(string name, string city, string address, int year, string manager, string author, string monumentName) : base(name, city, address, year, manager)
+ {
+ Author = author;
+ MonumentName = monumentName;
+ }
+ }
+}
+