-
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
26 changed files
with
395 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,33 @@ | ||
namespace Mobil; | ||
|
||
public class Car | ||
{ | ||
public Engine engine; | ||
public string? brand; | ||
public string? tire; | ||
public int topSpeed; | ||
|
||
public Car(Engine engine, string brand, string tire) | ||
{ | ||
this.engine = engine; | ||
this.brand = brand; | ||
this.tire = tire; | ||
} | ||
|
||
public Car(Engine engine, string tire, int topSpeed) | ||
{ | ||
this.engine = engine; | ||
this.tire = tire; | ||
this.topSpeed = topSpeed; | ||
} | ||
|
||
public Engine EngineCheck() | ||
{ | ||
return engine; | ||
} | ||
|
||
public int TopSpeedCheck() | ||
{ | ||
return topSpeed; | ||
} | ||
} |
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,8 @@ | ||
<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,14 @@ | ||
namespace Mobil; | ||
|
||
public class Engine | ||
{ | ||
public string? engineType; | ||
public int horsePower; | ||
public int torque; | ||
public Engine(string engineType, int horsePower, int torque) | ||
{ | ||
this.engineType = engineType; | ||
this.horsePower = horsePower; | ||
this.torque = torque; | ||
} | ||
} |
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,15 @@ | ||
using Mobil; | ||
class Program | ||
{ | ||
static void Main() | ||
{ | ||
Engine engine = new Engine("v8", 495, 470); | ||
|
||
Car honda = new Car(engine, "bridgestone", 300); | ||
|
||
Console.WriteLine(honda.EngineCheck().engineType); | ||
Console.WriteLine(honda.EngineCheck().horsePower); | ||
Console.WriteLine(honda.EngineCheck().torque); | ||
Console.WriteLine(honda.TopSpeedCheck()); | ||
} | ||
} |
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,33 @@ | ||
namespace Constructor; | ||
|
||
public class Car | ||
{ | ||
public string? engine; | ||
public string? brand; | ||
public string? tire; | ||
public int topSpeed; | ||
|
||
public Car(string engine, string brand, string tire) | ||
{ | ||
this.engine = engine; | ||
this.brand = brand; | ||
this.tire = tire; | ||
} | ||
|
||
public Car(string engine, string tire, int topSpeed) | ||
{ | ||
this.engine = engine; | ||
this.tire = tire; | ||
this.topSpeed = topSpeed; | ||
} | ||
|
||
public string? EngineCheck() | ||
{ | ||
return engine; | ||
} | ||
|
||
public int TopSpeedCheck() | ||
{ | ||
return topSpeed; | ||
} | ||
} |
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,8 @@ | ||
<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,15 @@ | ||
using Constructor; | ||
|
||
class Program | ||
{ | ||
static void Main() | ||
{ | ||
Car mobil1 = new Car("v8", "honda", "bridgestone"); | ||
Console.WriteLine(mobil1.EngineCheck()); | ||
|
||
Car mobil2 = new Car("v8", "michelin", 300); | ||
Console.WriteLine(mobil2.TopSpeedCheck()); | ||
|
||
|
||
} | ||
} |
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,23 @@ | ||
namespace Hewan; | ||
|
||
public class Animal | ||
{ | ||
protected string? _name; | ||
protected int _age; | ||
|
||
public Animal(string name, int age) | ||
{ | ||
_name = name; | ||
_age = age; | ||
} | ||
|
||
public string? GetName() | ||
{ | ||
return _name; | ||
} | ||
|
||
public int GetAge() | ||
{ | ||
return _age; | ||
} | ||
} |
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,9 @@ | ||
namespace Hewan; | ||
|
||
public class Cat : Animal | ||
{ | ||
public Cat(string name, int age) : base(name, age) | ||
{ | ||
Console.WriteLine($"Cat with name {name} and age {age} years old has been created."); | ||
} | ||
} |
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,8 @@ | ||
<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,10 @@ | ||
using Hewan; | ||
class Program | ||
{ | ||
static void Main() | ||
{ | ||
Cat kucing = new Cat("Cibi", 12); | ||
Console.WriteLine(kucing.GetName()); | ||
Console.WriteLine(kucing.GetAge()); | ||
} | ||
} |
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,22 @@ | ||
namespace Hewan; | ||
|
||
public class Animal | ||
{ | ||
public string? name; | ||
public int age; | ||
|
||
public Animal(string name, int age) | ||
{ | ||
Console.WriteLine($"Animal with name {name} and age {age} years old has been created."); | ||
} | ||
|
||
public Animal() | ||
{ | ||
// default constructor | ||
} | ||
|
||
public void Eat() | ||
{ | ||
Console.WriteLine($"{name} has eaten."); | ||
} | ||
} |
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,16 @@ | ||
namespace Hewan; | ||
|
||
public class Bird : Animal | ||
{ | ||
public Bird(string name, int age) : base(name, age) | ||
{ | ||
this.name = name; | ||
this.age = age; | ||
Console.WriteLine($"Bird with name {name} and age {age} has been created."); | ||
} | ||
|
||
public void Fly() | ||
{ | ||
Console.WriteLine($"{name} is flying happily."); | ||
} | ||
} |
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,16 @@ | ||
namespace Hewan; | ||
|
||
public class Cat : Animal | ||
{ | ||
public Cat(string name, int age) : base(name, age) | ||
{ | ||
this.name = name; | ||
this.age = age; | ||
Console.WriteLine($"Cat with name {name} and age {age} has been created."); | ||
} | ||
|
||
public void Meow() | ||
{ | ||
Console.WriteLine($"{name} is meowing calmly."); | ||
} | ||
} |
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,15 @@ | ||
namespace Hewan; | ||
|
||
public class Dog : Animal | ||
{ | ||
public Dog(string name, int age) : base(name, age) | ||
{ | ||
this.name = name; | ||
this.age = age; | ||
Console.WriteLine($"Dog with name {name} and age {age} has been created."); | ||
} | ||
|
||
public void Bark() { | ||
Console.WriteLine($"{name} is barking very loud."); | ||
} | ||
} |
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,16 @@ | ||
namespace Hewan; | ||
|
||
public class Fish : Animal | ||
{ | ||
public Fish(string name, int age) : base(name, age) | ||
{ | ||
this.name = name; | ||
this.age = age; | ||
Console.WriteLine($"Fish with name {name} and age {age} has been created."); | ||
} | ||
|
||
public void Swim() | ||
{ | ||
Console.WriteLine($"{name} is swimming happily."); | ||
} | ||
} |
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,8 @@ | ||
<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,14 @@ | ||
using Hewan; | ||
class Program | ||
{ | ||
static void Main() | ||
{ | ||
Cat cat = new Cat("Cibi", 1); | ||
cat.Meow(); | ||
cat.Eat(); | ||
|
||
Dog dog = new Dog("Gukguk", 2); | ||
dog.Bark(); | ||
dog.Eat(); | ||
} | ||
} |
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,15 @@ | ||
namespace Mobil; | ||
|
||
public class Car | ||
{ | ||
public IEngine? engine; | ||
public Car(IEngine engine) | ||
{ | ||
this.engine = engine; | ||
} | ||
|
||
public void RunEngine() | ||
{ | ||
engine?.RunEngine(); | ||
} | ||
} |
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,9 @@ | ||
namespace Mobil; | ||
|
||
public class DieselEngine : IEngine | ||
{ | ||
public void RunEngine() | ||
{ | ||
Console.WriteLine("Diesel Engine is running."); | ||
} | ||
} |
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,9 @@ | ||
namespace Mobil; | ||
|
||
public class ElectricEngine : IEngine | ||
{ | ||
public void RunEngine() | ||
{ | ||
Console.WriteLine("Electric Engine is running."); | ||
} | ||
} |
Oops, something went wrong.