fix: rename containers and registers in 'Lab5.TouristInformationCenter'
This commit is contained in:
parent
ecf83fbfd6
commit
c099ec3bb3
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Append the museums from the second container to the first one
|
||||
/// Append the locations from the second container to the first one
|
||||
/// </summary>
|
||||
/// <param name="container1">First container</param>
|
||||
/// <param name="container2">Second container</param>
|
||||
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
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decode a list of museums from a given list of lines.
|
||||
/// Decode a list of locations from a given list of lines.
|
||||
/// </summary>
|
||||
/// <param name="lines"></param>
|
||||
/// <returns>Container of museums</returns>
|
||||
public static MuseumsContainer DecodeMuseums(List<string> lines)
|
||||
/// <returns>Container of locations</returns>
|
||||
public static LocationsContainer DecodeLocations(List<string> 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<Weekday> workdays = new List<Weekday>();
|
||||
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<Weekday> workdays = new List<Weekday>(); */
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read and decode a list of museums from a file.
|
||||
/// Read and decode a list of locations from a file.
|
||||
/// </summary>
|
||||
/// <param name="filename">Target file</param>
|
||||
/// <returns>Container of museums</returns>
|
||||
public static MuseumsContainer ReadMuseumsFromCSV(string filename)
|
||||
/// <returns>Container of locations</returns>
|
||||
public static LocationsContainer ReadLocationsFromCSV(string filename)
|
||||
{
|
||||
List<string> lines = new List<string>();
|
||||
foreach (string line in File.ReadAllLines(filename, Encoding.UTF8))
|
||||
{
|
||||
lines.Add(line);
|
||||
}
|
||||
return DecodeMuseums(lines);
|
||||
return DecodeLocations(lines);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="filename">Target filename</param>
|
||||
/// <returns>Register of museums</returns>
|
||||
public static MuseumsContainer ReadMuseumsFromZIP(string filename)
|
||||
/// <returns>Register of locations</returns>
|
||||
public static LocationsContainer ReadLocationsFromZIP(string filename)
|
||||
{
|
||||
MuseumsContainer mainContainer = new MuseumsContainer();
|
||||
LocationsContainer mainContainer = new LocationsContainer();
|
||||
|
||||
using (ZipArchive zipFile = ZipFile.Open(filename, ZipArchiveMode.Read))
|
||||
{
|
||||
@ -95,7 +95,7 @@ namespace Lab5.TouristInformationCenter
|
||||
}
|
||||
}
|
||||
|
||||
MuseumsContainer contaienr = DecodeMuseums(lines);
|
||||
LocationsContainer contaienr = DecodeLocations(lines);
|
||||
AppendContainer(mainContainer, contaienr);
|
||||
}
|
||||
|
||||
@ -105,79 +105,80 @@ namespace Lab5.TouristInformationCenter
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="filenames">Target files</param>
|
||||
/// <returns>Register containing museums from all files</returns>
|
||||
public static MuseumsContainer ReadMuseums(params string[] filenames)
|
||||
/// <returns>Register containing locations from all files</returns>
|
||||
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 "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="filename">Target file</param>
|
||||
/// <param name="container">Container of museums</param>
|
||||
public static void WriteMuseums(string filename, MuseumsContainer container)
|
||||
/// <param name="container">Container of locations</param>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="filename">Target location</param>
|
||||
/// <param name="register">Register containing museums</param>
|
||||
public static void WriteMuseums(string filename, MuseumsRegister register)
|
||||
/// <param name="register">Register containing locations</param>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write out a container of museums in a table to the console.
|
||||
/// Write out a container of locations in a table to the console.
|
||||
/// </summary>
|
||||
/// <param name="container">Container of museums</param>
|
||||
public static void PrintMuseums(MuseumsContainer container)
|
||||
/// <param name="container">Container of locations</param>
|
||||
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));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="register">Register containing museums</param>
|
||||
public static void PrintMuseums(MuseumsRegister register)
|
||||
/// <param name="register">Register containing locations</param>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
26
Lab5/Lab5.TouristInformationCenter/Location.cs
Normal file
26
Lab5/Lab5.TouristInformationCenter/Location.cs
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
2
Lab5/Lab5.TouristInformationCenter/LocationsAlytus.csv
Normal file
2
Lab5/Lab5.TouristInformationCenter/LocationsAlytus.csv
Normal file
@ -0,0 +1,2 @@
|
||||
Alytus
|
||||
Ona Onaite
|
|
10
Lab5/Lab5.TouristInformationCenter/LocationsComparator.cs
Normal file
10
Lab5/Lab5.TouristInformationCenter/LocationsComparator.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace Lab5.TouristInformationCenter
|
||||
{
|
||||
class LocationsComparator
|
||||
{
|
||||
public virtual int Compare(Location a, Location b)
|
||||
{
|
||||
return a.CompareTo(b);
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
217
Lab5/Lab5.TouristInformationCenter/LocationsContainer.cs
Normal file
217
Lab5/Lab5.TouristInformationCenter/LocationsContainer.cs
Normal file
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a location to the end of the container
|
||||
/// </summary>
|
||||
/// <param name="location">Target location</param>
|
||||
public void Add(Location location)
|
||||
{
|
||||
if (Count == Capacity)
|
||||
{
|
||||
EnsureCapacity(Capacity * 2);
|
||||
}
|
||||
|
||||
locations[Count] = location;
|
||||
Count++;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a musem by index from container
|
||||
/// </summary>
|
||||
/// <param name="index">Target index</param>
|
||||
/// <returns>Location at given index</returns>
|
||||
public Location Get(int index)
|
||||
{
|
||||
return locations[index];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if given location exists in container
|
||||
/// </summary>
|
||||
/// <param name="location">Target location</param>
|
||||
/// <returns>True if contains</returns>
|
||||
public bool Contains(Location location)
|
||||
{
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (locations[i].Equals(location))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Put a location at a specific index
|
||||
/// </summary>
|
||||
/// <param name="index">Target index</param>
|
||||
/// <param name="location">Target location</param>
|
||||
public void Put(int index, Location location)
|
||||
{
|
||||
locations[index] = location;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
/// <summary>
|
||||
/// Filter by property "HasGuide"
|
||||
/// </summary>
|
||||
/// <param name="hasGuide">Target value</param>
|
||||
/// <returns>A filtered container of locations</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filter by property "Type".
|
||||
/// </summary>
|
||||
/// <param name="type">Target type</param>
|
||||
/// <returns>A filtered container of locations</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filter by property "Price".
|
||||
/// </summary>
|
||||
/// <param name="maxPrice">Maximum allowed price to be included</param>
|
||||
/// <returns>A container with locations that dont't have a larger price then "maxPrice"</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return a list of "active" locations from the contaner.
|
||||
/// A location is considered active if it is working at least some amount a week.
|
||||
/// </summary>
|
||||
/// <param name="threshold">Threshold which determines what is active</param>
|
||||
/// <returns>A container of "active" locations</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filter by property "Name"
|
||||
/// </summary>
|
||||
/// <param name="name">Target name</param>
|
||||
/// <returns>A filtered container</returns>
|
||||
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;
|
||||
}
|
||||
*/
|
||||
|
||||
/// <summary>
|
||||
/// Sort container by given comparator
|
||||
/// </summary>
|
||||
/// <param name="comparator">Defined how it should be sorted</param>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sort container by "Name" in alphabetical order.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,24 +1,19 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Lab5.TouristInformationCenter
|
||||
{
|
||||
/// <summary>
|
||||
/// Class used for storing data related a single museum.
|
||||
/// </summary>
|
||||
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<Weekday> Workdays { get; set; }
|
||||
public double Price { get; set; }
|
||||
public bool HasGuide { get; set; }
|
||||
public Museum(string name, string city, string manager, string type, List<Weekday> workdays, double price, bool hasGuide)
|
||||
|
||||
public Location(string name, string city, string address, int year, string manager, string type, List<Weekday> workdays, double price, bool hasGuide) : base(name, city, address, year, manager)
|
||||
{
|
||||
Name = name;
|
||||
Manager = manager;
|
||||
City = city;
|
||||
Type = type;
|
||||
Workdays = workdays;
|
||||
Price = price;
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a museum to the end of the container
|
||||
/// </summary>
|
||||
/// <param name="museum">Target museum</param>
|
||||
public void Add(Museum museum)
|
||||
{
|
||||
if (Count == Capacity)
|
||||
{
|
||||
EnsureCapacity(Capacity * 2);
|
||||
}
|
||||
|
||||
museums[Count] = museum;
|
||||
Count++;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a musem by index from container
|
||||
/// </summary>
|
||||
/// <param name="index">Target index</param>
|
||||
/// <returns>Museum at given index</returns>
|
||||
public Museum Get(int index)
|
||||
{
|
||||
return museums[index];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if given museum exists in container
|
||||
/// </summary>
|
||||
/// <param name="museum">Target museum</param>
|
||||
/// <returns>True if contains</returns>
|
||||
public bool Contains(Museum museum)
|
||||
{
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (museums[i].Equals(museum))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Put a museum at a specific index
|
||||
/// </summary>
|
||||
/// <param name="index">Target index</param>
|
||||
/// <param name="museum">Target museum</param>
|
||||
public void Put(int index, Museum museum)
|
||||
{
|
||||
museums[index] = museum;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filter by property "HasGuide"
|
||||
/// </summary>
|
||||
/// <param name="hasGuide">Target value</param>
|
||||
/// <returns>A filtered container of museums</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filter by property "Type".
|
||||
/// </summary>
|
||||
/// <param name="type">Target type</param>
|
||||
/// <returns>A filtered container of museums</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filter by property "Price".
|
||||
/// </summary>
|
||||
/// <param name="maxPrice">Maximum allowed price to be included</param>
|
||||
/// <returns>A container with museums that dont't have a larger price then "maxPrice"</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filter by property "Type"
|
||||
/// </summary>
|
||||
/// <param name="city">Target city</param>
|
||||
/// <returns>A container of museums</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return a list of "active" museums from the contaner.
|
||||
/// A museum is considered active if it is working at least some amount a week.
|
||||
/// </summary>
|
||||
/// <param name="threshold">Threshold which determines what is active</param>
|
||||
/// <returns>A container of "active" museums</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filter by property "Name"
|
||||
/// </summary>
|
||||
/// <param name="name">Target name</param>
|
||||
/// <returns>A filtered container</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all of the different types of cities.
|
||||
/// </summary>
|
||||
/// <returns>A list of city names</returns>
|
||||
public List<string> GetAllCities()
|
||||
{
|
||||
List<string> cities = new List<string>();
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
Museum museum = museums[i];
|
||||
if (!cities.Contains(museum.City))
|
||||
{
|
||||
cities.Add(museum.City);
|
||||
}
|
||||
}
|
||||
return cities;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sort container by "City" and "Name" in alphabetical order.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,170 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Lab5.TouristInformationCenter
|
||||
{
|
||||
/// <summary>
|
||||
/// Class used to store multiple museums in one place
|
||||
/// </summary>
|
||||
class MuseumsRegister
|
||||
{
|
||||
private MuseumsContainer AllMuseums;
|
||||
|
||||
public MuseumsRegister()
|
||||
{
|
||||
AllMuseums = new MuseumsContainer();
|
||||
}
|
||||
|
||||
public MuseumsRegister(MuseumsContainer museums)
|
||||
{
|
||||
AllMuseums = new MuseumsContainer(museums);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add one museum to the register.
|
||||
/// </summary>
|
||||
/// <param name="museum">Target museum</param>
|
||||
public void Add(Museum museum)
|
||||
{
|
||||
AllMuseums.Add(museum);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The amount of stored museums in the register.
|
||||
/// </summary>
|
||||
/// <returns>Museum count</returns>
|
||||
public int Count()
|
||||
{
|
||||
return AllMuseums.Count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Access museum from register by index
|
||||
/// </summary>
|
||||
/// <param name="index">Target index</param>
|
||||
/// <returns>Museum</returns>
|
||||
public Museum GetByIndex(int index)
|
||||
{
|
||||
return AllMuseums.Get(index);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return a list of active museums from the register.
|
||||
/// A museum is considered active if it is working at least some amount a week.
|
||||
/// </summary>
|
||||
/// <param name="threshold">Threshold which determines what is active</param>
|
||||
/// <returns>A list of active museums</returns>
|
||||
public MuseumsContainer FilterByActiveMuseums(int threshold)
|
||||
{
|
||||
return AllMuseums.FilterByActivity(threshold);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find museum that work the most days in a week
|
||||
/// </summary>
|
||||
/// <returns>Most active museum</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find all museums that work the most days in a week
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all of the different types of cities.
|
||||
/// </summary>
|
||||
/// <returns>A list of city names</returns>
|
||||
public List<string> GetAllCities()
|
||||
{
|
||||
return AllMuseums.GetAllCities();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filter the museums by city name from register
|
||||
/// </summary>
|
||||
/// <param name="city">Target city</param>
|
||||
/// <returns>A container of museums</returns>
|
||||
public MuseumsContainer FilterByCity(string city)
|
||||
{
|
||||
return AllMuseums.FilterByCity(city);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filter by property "Type".
|
||||
/// </summary>
|
||||
/// <param name="type">Target type</param>
|
||||
/// <returns>A filtered container of museums</returns>
|
||||
public MuseumsContainer FilterByType(string type)
|
||||
{
|
||||
return AllMuseums.FilterByType(type);
|
||||
}
|
||||
|
||||
private List<string> GetMuseumNames()
|
||||
{
|
||||
List<string> result = new List<string>();
|
||||
for (int i = 0; i < AllMuseums.Count; i++)
|
||||
{
|
||||
Museum museum = AllMuseums.Get(i);
|
||||
if (!result.Contains(museum.Name))
|
||||
{
|
||||
result.Add(museum.Name);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find all museums that have matching names
|
||||
/// </summary>
|
||||
/// <returns>A container with museums that have matching names</returns>
|
||||
public MuseumsContainer FindMuseumsWithDuplicateNames()
|
||||
{
|
||||
MuseumsContainer result = new MuseumsContainer();
|
||||
List<string> 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -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<string> 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<string> 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);
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
283
Lab5/Lab5.TouristInformationCenter/Register.cs
Normal file
283
Lab5/Lab5.TouristInformationCenter/Register.cs
Normal file
@ -0,0 +1,283 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Lab5.TouristInformationCenter
|
||||
{
|
||||
/// <summary>
|
||||
/// Class used to store multiple locations in one place
|
||||
/// </summary>
|
||||
class Register
|
||||
{
|
||||
private LocationsContainer AllLocations;
|
||||
|
||||
public Register()
|
||||
{
|
||||
AllLocations = new LocationsContainer();
|
||||
}
|
||||
|
||||
public Register(LocationsContainer locations)
|
||||
{
|
||||
AllLocations = new LocationsContainer(locations);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add one location to the register.
|
||||
/// </summary>
|
||||
/// <param name="location">Target location</param>
|
||||
public void Add(Location location)
|
||||
{
|
||||
AllLocations.Add(location);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The amount of stored locations in the register.
|
||||
/// </summary>
|
||||
/// <returns>Location count</returns>
|
||||
public int Count()
|
||||
{
|
||||
return AllLocations.Count;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Access location from register by index
|
||||
/// </summary>
|
||||
/// <param name="index">Target index</param>
|
||||
/// <returns>Location</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all of the different types of cities.
|
||||
/// </summary>
|
||||
/// <returns>A list of city names</returns>
|
||||
public List<string> GetAllCities()
|
||||
{
|
||||
List<string> cities = new List<string>();
|
||||
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<string> GetAllTypes()
|
||||
{
|
||||
List<string> types = new List<string>();
|
||||
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<string> FindCommonTypesBetweenCities()
|
||||
{
|
||||
List<string> allCities = GetAllCities();
|
||||
Dictionary<string, int> types = new Dictionary<string, int>();
|
||||
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<string> result = new List<string>();
|
||||
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<string> FindCommonTypesWithGuidesAtWeekends()
|
||||
{
|
||||
List<string> types = new List<string>();
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
/// <summary>
|
||||
/// Return a list of active locations from the register.
|
||||
/// A location is considered active if it is working at least some amount a week.
|
||||
/// </summary>
|
||||
/// <param name="threshold">Threshold which determines what is active</param>
|
||||
/// <returns>A list of active locations</returns>
|
||||
public LocationsContainer FilterByActiveLocations(int threshold)
|
||||
{
|
||||
return AllLocations.FilterByActivity(threshold);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find location that work the most days in a week
|
||||
/// </summary>
|
||||
/// <returns>Most active location</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find all locations that work the most days in a week
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Filter by property "Type".
|
||||
/// </summary>
|
||||
/// <param name="type">Target type</param>
|
||||
/// <returns>A filtered container of locations</returns>
|
||||
public LocationsContainer FilterByType(string type)
|
||||
{
|
||||
return AllLocations.FilterByType(type);
|
||||
}
|
||||
|
||||
private List<string> GetLocationNames()
|
||||
{
|
||||
List<string> result = new List<string>();
|
||||
for (int i = 0; i < AllLocations.Count; i++)
|
||||
{
|
||||
Location location = AllLocations.Get(i);
|
||||
if (!result.Contains(location.Name))
|
||||
{
|
||||
result.Add(location.Name);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find all locations that have matching names
|
||||
/// </summary>
|
||||
/// <returns>A container with locations that have matching names</returns>
|
||||
public LocationsContainer FindLocationsWithDuplicateNames()
|
||||
{
|
||||
LocationsContainer result = new LocationsContainer();
|
||||
List<string> 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;
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
15
Lab5/Lab5.TouristInformationCenter/Statue.cs
Normal file
15
Lab5/Lab5.TouristInformationCenter/Statue.cs
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user