Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions week-1/day-2/exercise-1/Circle/Circle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,22 @@ namespace Circle
internal class Circle
{
// Implement the Circle class here
public double Radius { get; private set; }

public Circle(double radius)
{
Radius = radius;
}

public double GetArea()
{
return Math.PI * Math.Pow(Radius, 2);
}

public double GetCircumference()
{
return 2 * Math.PI * Radius;
}

}
}
12 changes: 11 additions & 1 deletion week-1/day-2/exercise-1/Circle/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@ internal class Program
{
static void Main(string[] args)
{
// Create a Circle object and display its area and circumference
// Create a Circle object with a given radius
double radius = 5.0;
Circle circle = new Circle(radius);

// Calculate and display the area
double area = circle.GetArea();
Console.WriteLine($"Area of the circle with radius {radius}: {area}");

// Calculate and display the circumference
double circumference = circle.GetCircumference();
Console.WriteLine($"Circumference of the circle with radius {radius}: {circumference}");
}
}
}
90 changes: 85 additions & 5 deletions week-1/day-2/exercise-2/BankAccount/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,90 @@
namespace BankAccount
using System;

public abstract class BankAccount
{
internal class Program
public string AccountNumber { get; protected set; }
public double Balance { get; protected set; }

public BankAccount(string accountNumber, double initialBalance)
{
static void Main(string[] args)
AccountNumber = accountNumber;
Balance = initialBalance;
}

public abstract void Deposit(double amount);
public abstract void Withdraw(double amount);
}

public class SavingsAccount : BankAccount
{
public double InterestRate { get; private set; }

public SavingsAccount(string accountNumber, double initialBalance, double interestRate)
: base(accountNumber, initialBalance)
{
InterestRate = interestRate;
}

public override void Deposit(double amount)
{
Balance += amount;
}

public override void Withdraw(double amount)
{
if (Balance >= amount)
{
Balance -= amount;
}
else
{
// Create SavingsAccount and CheckingAccount objects and perform operations
Console.WriteLine("Insufficient balance.");
}
}
}
}

public class CheckingAccount : BankAccount
{
public double OverdraftLimit { get; private set; }

public CheckingAccount(string accountNumber, double initialBalance, double overdraftLimit)
: base(accountNumber, initialBalance)
{
OverdraftLimit = overdraftLimit;
}

public override void Deposit(double amount)
{
Balance += amount;
}

public override void Withdraw(double amount)
{
if (Balance + OverdraftLimit >= amount)
{
Balance -= amount;
}
else
{
Console.WriteLine("Insufficient balance.");
}
}
}

class Program
{
static void Main(string[] args)
{
SavingsAccount savingsAccount = new SavingsAccount("SA123", 1000, 0.05);
CheckingAccount checkingAccount = new CheckingAccount("CA456", 500, 200);

savingsAccount.Deposit(500);
savingsAccount.Withdraw(200);

checkingAccount.Deposit(300);
checkingAccount.Withdraw(800);

Console.WriteLine($"Savings Account Balance: {savingsAccount.Balance}");
Console.WriteLine($"Checking Account Balance: {checkingAccount.Balance}");
}
}
66 changes: 61 additions & 5 deletions week-1/day-2/exercise-3/AnimalExercise/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,66 @@
namespace AnimalExercise
using System;
using System.Collections.Generic;

public abstract class Animal
{
internal class Program
public string Name { get; set; }
public int Age { get; set; }

public abstract void MakeSound();
}

public class Dog : Animal, IMovable
{
public override void MakeSound()
{
Console.WriteLine("Woof");
}

public void Move()
{
static void Main(string[] args)
Console.WriteLine("Dog is running.");
}
}

public class Cat : Animal, IMovable
{
public override void MakeSound()
{
Console.WriteLine("Meow");
}

public void Move()
{
Console.WriteLine("Cat is sneaking.");
}
}

public interface IMovable
{
void Move();
}

class Program
{
static void Main(string[] args)
{
List<Animal> animals = new List<Animal>
{
new Dog { Name = "Buddy", Age = 3 },
new Cat { Name = "Whiskers", Age = 2 }
};

foreach (var animal in animals)
{
// Create a list of Animal objects, add Dog and Cat instances, and call their methods
Console.WriteLine($"Name: {animal.Name}, Age: {animal.Age}");
animal.MakeSound();

if (animal is IMovable movableAnimal)
{
movableAnimal.Move();
}

Console.WriteLine();
}
}
}
}
Loading