-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
namespace OperatorOverloading; | ||
|
||
public class DragonBall | ||
{ | ||
private string? _characterName; | ||
private int _characterHeight; | ||
private int _characterWeight; | ||
private int _characterPower; | ||
|
||
public DragonBall(string characterName, int characterHeight, int characterWeight, int characterPower) | ||
{ | ||
_characterName = characterName; | ||
_characterHeight = characterHeight; | ||
_characterWeight = characterWeight; | ||
_characterPower = characterPower; | ||
} | ||
|
||
public static DragonBall operator +(DragonBall characterA, DragonBall characterB) | ||
{ | ||
Random random = new Random(); | ||
string newName = characterA.CharacterName + characterB.CharacterName; | ||
int newHeight = random.Next(Math.Min(characterA.CharacterHeight, characterB.CharacterHeight), Math.Max(characterA.CharacterHeight, characterB.CharacterHeight)); | ||
int newWeight = random.Next(Math.Min(characterA.CharacterWeight, characterB.CharacterWeight), Math.Max(characterA.CharacterWeight, characterB.CharacterWeight)); | ||
int newPower = random.Next(Math.Min(characterA.CharacterPower, characterB.CharacterPower), Math.Max(characterA.CharacterPower, characterB.CharacterPower)); | ||
return new DragonBall(newName, newHeight, newWeight, newPower); | ||
} | ||
|
||
public static void PrintCharacterInfo(DragonBall character) | ||
{ | ||
Console.WriteLine(); | ||
Console.WriteLine($"Character's name: {character.CharacterName}"); | ||
Console.WriteLine($"Character's height: {character.CharacterHeight}"); | ||
Console.WriteLine($"Character's weight: {character.CharacterWeight}"); | ||
Console.WriteLine($"Character's power: {character.CharacterPower}"); | ||
} | ||
|
||
public string? CharacterName | ||
{ | ||
get => _characterName; | ||
} | ||
|
||
public int CharacterHeight | ||
{ | ||
get => _characterHeight; | ||
set => _characterHeight = value; | ||
} | ||
|
||
public int CharacterWeight | ||
{ | ||
get => _characterWeight; | ||
set => _characterWeight = value; | ||
} | ||
|
||
public int CharacterPower | ||
{ | ||
get => _characterPower; | ||
set => _characterPower = value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using OperatorOverloading; | ||
|
||
public class Program | ||
{ | ||
static void Main() | ||
{ | ||
DragonBall goku = new("Goku", 175, 62, 999); | ||
DragonBall vegeta = new("Vegeta", 164, 56, 899); | ||
|
||
DragonBall fusionedCharacters = goku + vegeta; | ||
|
||
DragonBall.PrintCharacterInfo(goku); | ||
DragonBall.PrintCharacterInfo(vegeta); | ||
DragonBall.PrintCharacterInfo(fusionedCharacters); | ||
|
||
} | ||
} |