Skip to content

Commit 66eac72

Browse files
committed
Last exam prep.
1 parent 6374fad commit 66eac72

File tree

10 files changed

+473
-0
lines changed

10 files changed

+473
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.31729.503
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bombs", "Bombs\Bombs.csproj", "{2899CA33-29DE-4398-A0AD-912CD0047B6E}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Snake", "Snake\Snake.csproj", "{26D50804-41D7-43BF-A922-82F615466109}"
9+
EndProject
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Parking", "..\..\..\Desktop\03. Parking_Skeleton\Parking\Parking\Parking.csproj", "{8DBF9700-597E-4D5E-AE32-A3F28F5B85E3}"
11+
EndProject
12+
Global
13+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
14+
Debug|Any CPU = Debug|Any CPU
15+
Release|Any CPU = Release|Any CPU
16+
EndGlobalSection
17+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
18+
{2899CA33-29DE-4398-A0AD-912CD0047B6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19+
{2899CA33-29DE-4398-A0AD-912CD0047B6E}.Debug|Any CPU.Build.0 = Debug|Any CPU
20+
{2899CA33-29DE-4398-A0AD-912CD0047B6E}.Release|Any CPU.ActiveCfg = Release|Any CPU
21+
{2899CA33-29DE-4398-A0AD-912CD0047B6E}.Release|Any CPU.Build.0 = Release|Any CPU
22+
{26D50804-41D7-43BF-A922-82F615466109}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23+
{26D50804-41D7-43BF-A922-82F615466109}.Debug|Any CPU.Build.0 = Debug|Any CPU
24+
{26D50804-41D7-43BF-A922-82F615466109}.Release|Any CPU.ActiveCfg = Release|Any CPU
25+
{26D50804-41D7-43BF-A922-82F615466109}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{8DBF9700-597E-4D5E-AE32-A3F28F5B85E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{8DBF9700-597E-4D5E-AE32-A3F28F5B85E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{8DBF9700-597E-4D5E-AE32-A3F28F5B85E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{8DBF9700-597E-4D5E-AE32-A3F28F5B85E3}.Release|Any CPU.Build.0 = Release|Any CPU
30+
EndGlobalSection
31+
GlobalSection(SolutionProperties) = preSolution
32+
HideSolutionNode = FALSE
33+
EndGlobalSection
34+
GlobalSection(ExtensibilityGlobals) = postSolution
35+
SolutionGuid = {45DCE62C-D67F-4F95-B6BA-0642B2D179C2}
36+
EndGlobalSection
37+
EndGlobal
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
</PropertyGroup>
7+
8+
</Project>
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
namespace Bombs
6+
{
7+
class Program
8+
{
9+
static void Main(string[] args)
10+
{
11+
int[] forQueueing = ReadIntArray();
12+
int[] forStacking = ReadIntArray();
13+
14+
Queue<int> effects = new Queue<int>(forQueueing);
15+
Stack<int> casings = new Stack<int>(forStacking);
16+
Dictionary<string, int> bombPouch = new Dictionary<string, int>
17+
{
18+
{"Cherry Bombs", 0},
19+
{"Datura Bombs", 0},
20+
{"Smoke Decoy Bombs", 0}
21+
};
22+
string datura = "Datura Bombs";
23+
string cherry = "Cherry Bombs";
24+
string smoke = "Smoke Decoy Bombs";
25+
bool filledPouch = false;
26+
27+
while (effects.Count > 0 && casings.Count > 0)
28+
{
29+
int currentEffect = effects.Peek();
30+
int currentCasing = casings.Peek();
31+
bool success = false;
32+
33+
int tinker = currentEffect + currentCasing;
34+
35+
if (tinker.Equals(40))
36+
{
37+
success = true;
38+
bombPouch[datura]++;
39+
}
40+
else if (tinker.Equals(60))
41+
{
42+
success = true;
43+
bombPouch[cherry]++;
44+
}
45+
else if (tinker.Equals(120))
46+
{
47+
success = true;
48+
bombPouch[smoke]++;
49+
}
50+
else
51+
{
52+
casings.Push(casings.Pop() - 5);
53+
}
54+
55+
if (success)
56+
{
57+
effects.Dequeue();
58+
casings.Pop();
59+
}
60+
61+
if (bombPouch[datura] >= 3 && bombPouch[cherry] >= 3 && bombPouch[smoke] >= 3)
62+
{
63+
filledPouch = true;
64+
break;
65+
}
66+
67+
}
68+
GC.Collect();
69+
Console.WriteLine(filledPouch
70+
? "Bene! You have successfully filled the bomb pouch!"
71+
: "You don't have enough materials to fill the bomb pouch.");
72+
73+
Console.WriteLine(effects.Any()
74+
? $"Bomb Effects: {string.Join(", ", effects)}"
75+
: "Bomb Effects: empty");
76+
77+
Console.WriteLine(casings.Any()
78+
? $"Bomb Casings: {string.Join(", ", casings)}"
79+
: "Bomb Casings: empty");
80+
81+
PrintKeyValuePairs(bombPouch);
82+
83+
}
84+
private static void PrintKeyValuePairs(Dictionary<string, int> bombPouch)
85+
{
86+
foreach (var bomb in bombPouch)
87+
{
88+
Console.WriteLine(string.Join(Environment.NewLine, $"{bomb.Key}: {bomb.Value}"));
89+
}
90+
}
91+
private static int[] ReadIntArray()
92+
{
93+
return Console.ReadLine()
94+
.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)
95+
.Select(int.Parse)
96+
.ToArray();
97+
}
98+
}
99+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace Parking
2+
{
3+
public class Car
4+
{
5+
public Car(string manufacturer, string model, int year)
6+
{
7+
Manufacturer = manufacturer;
8+
Model = model;
9+
Year = year;
10+
}
11+
public string Manufacturer { get; set; }
12+
public string Model { get; set; }
13+
public int Year { get; set; }
14+
15+
public override string ToString()
16+
{
17+
return $"{this.Manufacturer} {this.Model} ({this.Year})";
18+
}
19+
20+
}
21+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using System.Text;
4+
5+
namespace Parking
6+
{
7+
public class Parking
8+
{
9+
private List<Car> data;
10+
public Parking(string type, int capacity)
11+
{
12+
Type = type;
13+
Capacity = capacity;
14+
Data = new List<Car>();
15+
}
16+
public string Type { get; set; }
17+
public int Capacity { get; set; }
18+
public List<Car> Data { get; private set; }
19+
public int Count => this.Data.Count;
20+
21+
public void Add(Car car)
22+
{
23+
if (Capacity > Count)
24+
{
25+
Data.Add(car);
26+
}
27+
}
28+
public bool Remove(string manufacturer, string model)
29+
{
30+
if (Data.Any(x => x.Manufacturer == manufacturer) && Data.Any(x => x.Model == model))
31+
{
32+
var targetCar = Data
33+
.Where(x => x.Manufacturer == manufacturer)
34+
.FirstOrDefault(x => x.Model == model);
35+
Data.Remove(targetCar);
36+
37+
return true;
38+
}
39+
40+
return false;
41+
}
42+
public Car GetLatestCar()
43+
{
44+
if (Data.Count > 0)
45+
{
46+
var search = Data.Select(x => x.Year).Max();
47+
var latestOne = Data.FirstOrDefault(x => x.Year == search);
48+
return latestOne;
49+
}
50+
51+
return null;
52+
}
53+
public Car GetCar(string manufacturer, string model)
54+
{
55+
bool firstCheck = Data.Exists(x => x.Manufacturer == manufacturer);
56+
bool secondCheck = Data.Exists(x => x.Model == model);
57+
58+
if (firstCheck && secondCheck)
59+
{
60+
var targetCar = Data
61+
.Where(x => x.Manufacturer == manufacturer)
62+
.FirstOrDefault(x => x.Model == model);
63+
return targetCar;
64+
}
65+
66+
return null;
67+
}
68+
public string GetStatistics()
69+
{
70+
StringBuilder sb = new StringBuilder();
71+
sb.AppendLine($"The cars are parked in {this.Type}:");
72+
73+
foreach (var car in this.Data)
74+
{
75+
sb.AppendLine(car.ToString());
76+
}
77+
78+
return sb.ToString().TrimEnd();
79+
}
80+
}
81+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
</PropertyGroup>
7+
8+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29728.190
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Parking", "Parking\Parking.csproj", "{F6DF34FD-89BC-4813-B93C-4220CBCBFE5A}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{F6DF34FD-89BC-4813-B93C-4220CBCBFE5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{F6DF34FD-89BC-4813-B93C-4220CBCBFE5A}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{F6DF34FD-89BC-4813-B93C-4220CBCBFE5A}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{F6DF34FD-89BC-4813-B93C-4220CBCBFE5A}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {E9FEB942-F40B-4568-BF89-D7CEFA87C97E}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System;
2+
3+
namespace Parking
4+
{
5+
public class StartUp
6+
{
7+
static void Main(string[] args)
8+
{
9+
// Initialize the repository
10+
Parking parking = new Parking("Underground parking garage", 5);
11+
12+
// Initialize entity
13+
Car volvo = new Car("Volvo", "XC70", 2010);
14+
15+
// Print Car
16+
Console.WriteLine(volvo); // Volvo XC70 (2010)
17+
18+
// Add Car
19+
parking.Add(volvo);
20+
21+
// Remove Car
22+
Console.WriteLine(parking.Remove("Volvo", "XC90")); // False
23+
Console.WriteLine(parking.Remove("Volvo", "XC70")); // True
24+
25+
Car peugeot = new Car("Peugeot", "307", 2011);
26+
Car audi = new Car("Audi", "S4", 2005);
27+
28+
parking.Add(peugeot);
29+
parking.Add(audi);
30+
31+
// Get Latest Car
32+
Car latestCar = parking.GetLatestCar();
33+
Console.WriteLine(latestCar); // Peugeot 307 (2011)
34+
35+
// Get Car
36+
Car audiS4 = parking.GetCar("Audi", "S4");
37+
Console.WriteLine(audiS4); // Audi S4 (2005)
38+
39+
// Count
40+
Console.WriteLine(parking.Count); // 2
41+
42+
// Get Statistics
43+
Console.WriteLine(parking.GetStatistics());
44+
// The cars are parked in Underground parking garage:
45+
// Peugeot 307(2011)
46+
// Audi S4(2005)
47+
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)