Skip to content
16 changes: 16 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,21 @@ namespace Circle
internal class Circle
{
// Implement the Circle class here
double Radius;

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

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

public double GetCircumference()
{
return 2 * Math.PI * Radius;
}
}
}
7 changes: 7 additions & 0 deletions week-1/day-2/exercise-1/Circle/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ internal class Program
static void Main(string[] args)
{
// Create a Circle object and display its area and circumference
Console.WriteLine("Enter the radius of the circle: ");
double radius = Convert.ToDouble(Console.ReadLine());
Circle myCircle = new Circle(radius);

Console.WriteLine($"Area: {myCircle.GetArea()}");

Console.WriteLine($"Circumference: {myCircle.GetCircumference()}");
}
}
}
117 changes: 117 additions & 0 deletions week-1/day-2/exercise-2/BankAccount/BankAccount.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BankAccount
{
public abstract class BankAccount
{
public Int32 AccountNumber;
public double Balance;

public BankAccount(Int32 accountNumber, double initBalance)
{
AccountNumber = accountNumber;
Balance = initBalance;
}

public abstract void Deposit(double amt);
public abstract void Withdraw(double amt);

public virtual void DisplayInfo()
{
Console.WriteLine($"Account Number: {AccountNumber}");
Console.WriteLine($"Balance: {Balance}");
}
}

public class SavingsAccount : BankAccount
{
public double InterestRate;
public SavingsAccount(Int32 accountNumber, double initBalance, double interestRate) : base(accountNumber, initBalance)
{
InterestRate = interestRate;
AccountNumber = accountNumber;
Balance = initBalance;
}

public override void Deposit(double amt)
{
if (amt > 0)
{
Balance += amt;
Console.WriteLine($"Deposited: {amt}");
Console.WriteLine($"Current Balance: {Balance}");
}
else
{
Console.WriteLine($"Invalid Deposit amount");
}
}

public override void Withdraw(double amt)
{
if (amt > Balance || amt < 0)
{
Console.WriteLine($"Invalid Withdraw amount");

}
else
{
Balance -= amt;
Console.WriteLine($"Withdraw: {amt}");
Console.WriteLine($"Current Balance: {Balance}");
}
}

public override void DisplayInfo()
{
base.DisplayInfo();
Console.WriteLine($"InterestRate: {InterestRate}");
}
}

class CheckingAccount : BankAccount
{
public double OverdraftLimit;
public CheckingAccount(Int32 accountNumber, double initBalance, double overdraftLimit) : base(accountNumber, initBalance)
{
OverdraftLimit = overdraftLimit;
}
public override void Deposit(double amt)
{
if (amt > 0)
{
Balance += amt;
Console.WriteLine($"Deposited: {amt}");
Console.WriteLine($"Current Balance: {Balance}");
}
else
{
Console.WriteLine($"Invalid Deposit amount");
}
}

public override void Withdraw(double amt)
{
if (amt > Balance || amt < 0)
{
Balance -= amt;
Console.WriteLine($"Withdraw: {amt}");
Console.WriteLine($"Current Balance: {Balance}");

}
else
{
Console.WriteLine("Invalid withdraw amount");
}
}
public override void DisplayInfo()
{
base.DisplayInfo();
Console.WriteLine($"Overdraft Limit: {OverdraftLimit}");
}
}
}
14 changes: 14 additions & 0 deletions week-1/day-2/exercise-2/BankAccount/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ internal class Program
static void Main(string[] args)
{
// Create SavingsAccount and CheckingAccount objects and perform operations
SavingsAccount savingsAccount = new SavingsAccount(1234, 14.00, 10.00);
CheckingAccount checkingAccount = new CheckingAccount(789012, 1500.00, 500.00);

savingsAccount.DisplayInfo();
savingsAccount.Deposit(200.00);
savingsAccount.Withdraw(300.00);
Console.WriteLine();

checkingAccount.DisplayInfo();
checkingAccount.Deposit(300.00);
checkingAccount.Withdraw(200.00);
checkingAccount.Withdraw(1800.00);

Console.ReadLine();
}
}
}
44 changes: 44 additions & 0 deletions week-1/day-2/exercise-3/AnimalExercise/Animal.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AnimalExercise
{
internal abstract class Animal
{
public string Name;
public int Age;

public abstract void MakeSound();
}
class Dog : Animal, IMovable
{
public override void MakeSound()
{
Console.WriteLine($"{Name} the dog make sound is: Woof!");
}
public void Move()
{
Console.WriteLine($"{Name} the dog is running.");
}
}

class Cat : Animal, IMovable
{
public override void MakeSound()
{
Console.WriteLine($"{Name} the cat make sound is: Meow!");
}
public void Move()
{
Console.WriteLine($"{Name} the cat is climbing.");
}
}

interface IMovable
{
void Move();
}
}
30 changes: 30 additions & 0 deletions week-1/day-2/exercise-3/AnimalExercise/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,36 @@ internal class Program
static void Main(string[] args)
{
// Create a list of Animal objects, add Dog and Cat instances, and call their methods

List<Animal> animals = new List<Animal>();

Console.WriteLine("animals", animals);
Dog dog = new Dog
{
Name = "Daisy",
Age = 1
};

Cat cat = new Cat
{
Name = "Bela",
Age = 1
};

animals.Add(dog);
animals.Add(cat);


foreach (var animal in animals)
{
animal.MakeSound();
if (animal is IMovable movableAnimal)
{
movableAnimal.Move();
}
Console.WriteLine("Name:" + animal.Name + ", Age:" + animal.Age);
}
Console.ReadLine();
}
}
}
24 changes: 24 additions & 0 deletions week-1/day-2/exercise-4/VehicleManagementSystem/IRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VehicleManagementSystem
{
public interface IRepository<T>
{
T GetById(int id);
IEnumerable<T> GetAll();
void Add(T entity);
void Update(T entity);
void Delete(T entity);
}

public class Entity
{
public int Id;
public string Name;
}
}

28 changes: 28 additions & 0 deletions week-1/day-2/exercise-4/VehicleManagementSystem/IVehicle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VehicleManagementSystem
{
internal interface IVehicle
{
public void Drive();
}
class Car : IVehicle
{
public void Drive()
{
Console.WriteLine("Car contains people.");
}
}

class Truck : IVehicle
{
public void Drive()
{
Console.WriteLine("Truck contains heavy goods.");
}
}
}
65 changes: 65 additions & 0 deletions week-1/day-2/exercise-4/VehicleManagementSystem/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,71 @@ internal class Program
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");

Car myCar = new Car();
Truck myTruck = new Truck();

myCar.Drive();
myTruck.Drive();

VehicleFactory carFactory = new CarFactory();
carFactory.DoSomethingWithVehicle();

VehicleFactory truckFactory = new TruckFactory();
truckFactory.DoSomethingWithVehicle();

IRepository<Entity> repository = new VehicleRepository();
VehicleService vehicleService = new VehicleService(repository, VehicleLogger.GetInstance());

repository.Add(new Entity { Name = "E1" });
repository.Add(new Entity { Name = "E2" });

var allEntities = repository.GetAll();
foreach (var entity in allEntities)
{
Console.WriteLine($"ID: {entity.Id}, Name: {entity.Name}");
}

var entityToUpdate = repository.GetById(1);
if (entityToUpdate != null)
{
entityToUpdate.Name = "Updated E1";
repository.Update(entityToUpdate);
}

var entityToDelete = repository.GetById(2);
if (entityToDelete != null)
{
repository.Delete(entityToDelete);
}

Console.WriteLine("\nAfter Update and Delete:");
foreach (var entity in repository.GetAll())
{
Console.WriteLine($"ID: {entity.Id}, Name: {entity.Name}");
}
Entity car = (Entity)carFactory.CreateVehicle();
car.Id = 1;
car.Name = "Audi";
Entity truck = (Entity)truckFactory.CreateVehicle();
truck.Id = 2;
truck.Name = "Mahindra";

vehicleService.AddVehicle(car);
vehicleService.AddVehicle(truck);

// Listing vehicles
Console.WriteLine("List of vehicles:");
vehicleService.ListVehicles();

// Doing something with a vehicle
Console.WriteLine("\nDoing something with a vehicle:");
vehicleService.DoSomethingWithVehicle(1);


vehicleService.RemoveVehicle(2);

Console.ReadLine();
}
}
}
Loading