Skip to content

Commit e47a950

Browse files
committed
Basic project with which to practice exceptions
0 parents  commit e47a950

17 files changed

+274
-0
lines changed

Diff for: .vs/ExceptionsDemo/v16/.suo

45 KB
Binary file not shown.

Diff for: .vs/ExceptionsDemo/v16/Server/sqlite3/db.lock

Whitespace-only changes.

Diff for: .vs/ExceptionsDemo/v16/Server/sqlite3/storage.ide

448 KB
Binary file not shown.

Diff for: ExceptionsDemo.sln

+25
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.29613.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExceptionsDemo", "ExceptionsDemo\ExceptionsDemo.csproj", "{7A036EC4-FBE4-42B5-93DA-750B4E62AEB8}"
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+
{7A036EC4-FBE4-42B5-93DA-750B4E62AEB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{7A036EC4-FBE4-42B5-93DA-750B4E62AEB8}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{7A036EC4-FBE4-42B5-93DA-750B4E62AEB8}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{7A036EC4-FBE4-42B5-93DA-750B4E62AEB8}.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 = {8562F08C-FC29-40AC-BD76-BF951BEDBBF9}
24+
EndGlobalSection
25+
EndGlobal

Diff for: ExceptionsDemo/App.config

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
5+
</startup>
6+
</configuration>

Diff for: ExceptionsDemo/ExceptionsDemo.csproj

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{7A036EC4-FBE4-42B5-93DA-750B4E62AEB8}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>ExceptionsDemo</RootNamespace>
10+
<AssemblyName>ExceptionsDemo</AssemblyName>
11+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
<Deterministic>true</Deterministic>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<PlatformTarget>AnyCPU</PlatformTarget>
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<PlatformTarget>AnyCPU</PlatformTarget>
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<ItemGroup>
36+
<Reference Include="System" />
37+
<Reference Include="System.Core" />
38+
<Reference Include="System.Xml.Linq" />
39+
<Reference Include="System.Data.DataSetExtensions" />
40+
<Reference Include="Microsoft.CSharp" />
41+
<Reference Include="System.Data" />
42+
<Reference Include="System.Net.Http" />
43+
<Reference Include="System.Xml" />
44+
</ItemGroup>
45+
<ItemGroup>
46+
<Compile Include="Program.cs" />
47+
<Compile Include="Properties\AssemblyInfo.cs" />
48+
<Compile Include="Starship.cs" />
49+
</ItemGroup>
50+
<ItemGroup>
51+
<None Include="App.config" />
52+
</ItemGroup>
53+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
54+
</Project>

Diff for: ExceptionsDemo/Program.cs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace ExceptionsDemo
8+
{
9+
class Program
10+
{
11+
static void Main(string[] args)
12+
{
13+
Starship Serenity = new Starship("Serenity", "Firefly", "404-E-132-4FE274A", 9);
14+
Serenity.AddCrew("Captain", "Malcolm Reynolds");
15+
Serenity.AddCrew("FirstMate", "Zoe Washburne");
16+
Serenity.AddCrew("Pilot", "Hoban Washburne");
17+
Serenity.AddCrew("Engineer", "Kaywinnet Lee Frye");
18+
Serenity.AddCrew("PublicRelations", "Jayne Cobb");
19+
Serenity.AddCrew("Ambassador", "Inara Serra");
20+
Serenity.AddCrew("Shepherd", "Derrial Book");
21+
Serenity.AddCrew("Medic", "Simon Tam");
22+
Serenity.AddCrew("Crew", "River Tam");
23+
24+
Serenity.Print();
25+
Serenity.PrintRoster();
26+
Console.ReadLine();
27+
}
28+
}
29+
}

Diff for: ExceptionsDemo/Properties/AssemblyInfo.cs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("ExceptionsDemo")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("ExceptionsDemo")]
13+
[assembly: AssemblyCopyright("Copyright © 2020")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("7a036ec4-fbe4-42b5-93da-750b4e62aeb8")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

Diff for: ExceptionsDemo/Starship.cs

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
5+
namespace ExceptionsDemo
6+
{
7+
class Starship
8+
{
9+
//Data members
10+
private Dictionary<string, List<string>> roster;
11+
12+
public List<string> GetCrew(string position)
13+
{
14+
return roster[position];
15+
}
16+
17+
18+
19+
public int CrewCapacity
20+
{
21+
get;
22+
set;
23+
}
24+
25+
public string Name
26+
{
27+
get;
28+
set;
29+
}
30+
31+
public string Class
32+
{
33+
get;
34+
set;
35+
}
36+
37+
public string RegistrationNumber
38+
{
39+
get;
40+
set;
41+
}
42+
43+
//Constructors
44+
public Starship()
45+
{
46+
CrewCapacity = 1;
47+
RegistrationNumber = "0";
48+
roster = new Dictionary<string, List<string>>();
49+
50+
}
51+
52+
public Starship(string Name, string Class, string RegistrationNumber = "0", int CrewCapacity = 1)
53+
{
54+
this.Name = Name;
55+
this.Class = Class;
56+
this.RegistrationNumber = RegistrationNumber;
57+
this.CrewCapacity = CrewCapacity;
58+
roster = new Dictionary<string, List<string>>();
59+
}
60+
61+
62+
// Methods
63+
public void AddCrew(string position, string name)
64+
{
65+
// If the position exists in the roster, add the name to its list
66+
if (roster.ContainsKey(position))
67+
{
68+
roster[position].Add(name);
69+
}
70+
// If the position is not yet in the roster, add it
71+
else
72+
{
73+
SetCrew(position, name);
74+
}
75+
}
76+
77+
public void SetCrew(string position, string name)
78+
{
79+
roster[position] = new List<string>() { name };
80+
}
81+
82+
public void Print()
83+
{
84+
Console.WriteLine("Vessel {0} of class {1} has a crew capacity of {2}", Name, Class, CrewCapacity);
85+
}
86+
87+
public void PrintRoster()
88+
{
89+
foreach (KeyValuePair<string, List<string>> kvp in roster)
90+
{
91+
Console.Write("{0}: ", kvp.Key);
92+
foreach (string value in kvp.Value)
93+
{
94+
Console.Write("{0} ", value);
95+
}
96+
Console.Write("\n");
97+
}
98+
int currentCrewSize = this.CurrentCrewSize();
99+
Console.WriteLine("{0} has a total of {1} crew members.", Name, currentCrewSize);
100+
}
101+
102+
public int CurrentCrewSize()
103+
{
104+
int count = 0;
105+
foreach (KeyValuePair<string, List<string>> kvp in roster)
106+
{
107+
count += kvp.Value.Count;
108+
}
109+
return count;
110+
}
111+
}
112+
}

Diff for: ExceptionsDemo/bin/Debug/ExceptionsDemo.exe

7.5 KB
Binary file not shown.

Diff for: ExceptionsDemo/bin/Debug/ExceptionsDemo.exe.config

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
5+
</startup>
6+
</configuration>

Diff for: ExceptionsDemo/bin/Debug/ExceptionsDemo.pdb

25.5 KB
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
F:\Source\cs371\ExceptionsDemo\ExceptionsDemo\bin\Debug\ExceptionsDemo.exe.config
2+
F:\Source\cs371\ExceptionsDemo\ExceptionsDemo\bin\Debug\ExceptionsDemo.exe
3+
F:\Source\cs371\ExceptionsDemo\ExceptionsDemo\bin\Debug\ExceptionsDemo.pdb
4+
F:\Source\cs371\ExceptionsDemo\ExceptionsDemo\obj\Debug\ExceptionsDemo.csprojAssemblyReference.cache
5+
F:\Source\cs371\ExceptionsDemo\ExceptionsDemo\obj\Debug\ExceptionsDemo.exe
6+
F:\Source\cs371\ExceptionsDemo\ExceptionsDemo\obj\Debug\ExceptionsDemo.pdb
Binary file not shown.

Diff for: ExceptionsDemo/obj/Debug/ExceptionsDemo.exe

7.5 KB
Binary file not shown.

Diff for: ExceptionsDemo/obj/Debug/ExceptionsDemo.pdb

25.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)