Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuinny committed Jul 14, 2024
1 parent 2a557b3 commit 024eccd
Show file tree
Hide file tree
Showing 5 changed files with 561 additions and 660 deletions.
86 changes: 31 additions & 55 deletions Source/Oligopoly.Game/Code/Company.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,127 +2,103 @@

public class Company
{
private string name;
private string industry;
private string description;
private decimal sharePrice;
private int numberOfShares;
private string _name;
private string _industry;
private string _description;
private decimal _sharePrice;
private int _numberOfShares;

/// <summary>
/// Gets or sets the name of the company.
/// The name cannot be null or whitespace.
/// </summary>
/// <summary>Gets or sets the name of the company.</summary>
/// <remarks>Name of the company must not be null or whitespace.</remarks>
[XmlElement("Name")]
public string Name
{
get
{
return name;
}
get => _name;
set
{
if (string.IsNullOrEmpty(value))
{
throw new Exception("Name cannot be null or whitespace!");
throw new Exception("Name of the company must not be null or whitespace!");
}
else
{
name = value;
_name = value;
}
}
}

/// <summary>
/// Gets or sets the industry of the company.
/// The industry cannot be null or whitespace.
/// </summary>
/// <summary>Gets or sets the industry of the company.</summary>
/// <remarks>Industry of the company must not be null or whitespace.</remarks>
[XmlElement("Industry")]
public string Industry
{
get
{
return industry;
}
get => _industry;
set
{
if (string.IsNullOrEmpty(value))
{
throw new Exception("Industry cannot be null or whitespace!");
throw new Exception("Industry of the company must not be null or whitespace!");
}
else
{
industry = value;
_industry = value;
}
}
}

/// <summary>
/// Gets or sets the description of the company.
/// The description cannot be null or whitespace.
/// </summary>
/// <summary>Gets or sets the description of the company.</summary>
/// <remarks>Description of the company must not be null or whitespace.</remarks>
[XmlElement("Description")]
public string Description
{
get
{
return description;
}
get => _description;
set
{
if (string.IsNullOrEmpty(value))
{
throw new Exception("Description cannot be null or whitespace!");
throw new Exception("Description of the company must not be null or whitespace!");
}
else
{
description = value;
_description = value;
}
}
}

/// <summary>
/// Gets or sets the share price of the company.
/// The share price cannot less than or equal to zero.
/// </summary>
/// <summary>Gets or sets the share price of the company.</summary>
/// <remarks>Share price of the company must be greater than zero.</remarks>
[XmlElement("SharePrice")]
public decimal SharePrice
{
get
{
return sharePrice;
}
get => _sharePrice;
set
{
if (value <= 0)
{
throw new Exception("Share Price cannot be less than or equal to zero!");
throw new Exception("Share price of the company must be greater than zero!");
}
else
{
sharePrice = value;
_sharePrice = value;
}
}
}

/// <summary>
/// Gets or sets the number of shares of the company.
/// The number of share cannot be less than or equal to zero.
/// </summary>
/// <summary>Gets or sets the number of shares of the company.</summary>
/// <remarks>Number of shares of the company must not be less than zero.</remarks>
[XmlElement("NumberOfShares")]
public int NumberOfShares
{
get
{
return numberOfShares;
}
get => _numberOfShares;
set
{
if (value < 0)
{
throw new Exception("Number of Shares cannot be less than zero!");
throw new Exception("Number of shares of the company must not be less than zero!");
}
else
{
numberOfShares = value;
_numberOfShares = value;
}
}
}
Expand Down
72 changes: 25 additions & 47 deletions Source/Oligopoly.Game/Code/Event.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,105 +2,83 @@

public class Event
{
private int effect;
private string target;
private string title;
private string content;
private int _effect;
private string _target;
private string _title;
private string _content;

/// <summary>
/// Gets or sets the effect of the event.
/// That is, the value by which the price of the <see cref="Company.SharePrice"/> should change.
/// The effect cannot be equal to zero.
/// </summary>
/// <summary>Gets or sets the effect of the event, represented as a percentage.</summary>
/// <remarks>Effect of the event must be a non-zero integer.</remarks>
[XmlElement("Effect")]
public int Effect
{
get
{
return effect;
}
get => _effect;
set
{
if (value == 0)
{
throw new Exception("Effect cannot be equal to zero!");
throw new Exception("Effect of the event must be a non-zero integer!");
}
else
{
effect = value;
_effect = value;
}
}
}

/// <summary>
/// Gets or sets the target of the event.
/// That is, the company to which the <see cref="Event.Effect"/> will be applied.
/// The target cannot be null or whitespace.
/// </summary>
/// <summary>Gets or sets the target company of the event.</summary>
/// <remarks>Target company of the event must not be null or whitespace.</remarks>
[XmlElement("Target")]
public string Target
{
get
{
return target;
}
get => _target;
set
{
if (string.IsNullOrWhiteSpace(value))
{
throw new Exception("Target cannot be null or whitespace!");
throw new Exception("Target company of the event must not be null or whitespace!");
}
else
{
target = value;
_target = value;
}
}
}

/// <summary>
/// Gets or sets the title of the event.
/// The title cannot be null or whitespace.
/// </summary>
/// <summary>Gets or sets the title of the event.</summary>
/// <remarks>Title of the event must not be null or whitespace.</remarks>
[XmlElement("Title")]
public string Title
{
get
{
return title;
}
get => _title;
set
{
if (string.IsNullOrEmpty(value))
if (string.IsNullOrWhiteSpace(value))
{
throw new Exception("Title cannot be null or whitespace!");
throw new Exception("Title of the event must not be null or whitespace!");
}
else
{
title = value;
_title = value;
}
}
}

/// <summary>
/// Gets or sets the content of the event.
/// The content cannot be null or whitespace.
/// </summary>
/// <summary>Gets or sets the content of the event.</summary>
/// <remarks>Content of the event must not be null or whitespace.</remarks>
[XmlElement("Content")]
public string Content
{
get
{
return content;
}
get => _content;
set
{
if (string.IsNullOrWhiteSpace(value))
{
throw new Exception("Content cannot be null or whitespace!");
throw new Exception("Content of the event must not be null or whitespace!");
}
else
{
content = value;
_content = value;
}
}
}
Expand Down
Loading

0 comments on commit 024eccd

Please sign in to comment.