Skip to content
15 changes: 14 additions & 1 deletion week-1/day-2/exercise-1/Circle/Circle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,21 @@

namespace Circle
{
internal class Circle
public class Circle
{
// Implement the Circle class here
private readonly double _radius;
public Circle(double Radius)
{
_radius = Radius;
}
public double GetArea()
{
return Math.Round(Math.PI * Math.Pow(_radius, 2), 4);
}
public double GetCircumference()
{
return Math.Round(2 * Math.PI + _radius, 4);
}
}
}
29 changes: 28 additions & 1 deletion week-1/day-2/exercise-1/Circle/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,37 @@
namespace Circle
{
internal class Program
public class Program
{
static void Main(string[] args)
{
// Create a Circle object and display its area and circumference
double Radius;
bool FirstIteration = true;
do
{
if(!FirstIteration)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Please enter valid number !!!\n");
Console.ForegroundColor = ConsoleColor.White;
}
Console.Write("Please Enter radius : ");
FirstIteration = false;

} while (!double.TryParse(Console.ReadLine(), out Radius));

// Create instance of Circle class
Circle circleObj = new(Radius);

// call GetArea() method that calculate area
double Area = circleObj.GetArea();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"Area of Circle is : {Area}");

// call GetArea() method that calculate circumference
double Circumference = circleObj.GetCircumference();
Console.WriteLine($"Circumference of Cirxle is : {Circumference}");
Console.ForegroundColor = ConsoleColor.White;
}
}
}
98 changes: 98 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,98 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BankAccount
{
public abstract class BankAccount
{
protected Int64 _accountNumber { get; set; }
protected double _balance { get; set; }
public abstract void Deposit(double amount);
public abstract void Withdraw(double amount);
}
public class SavingsAccount : BankAccount
{
public double InterestRate { get; private set; }
public SavingsAccount(Int64 accountNumber, double initialBalance, double interestRate)
{
_accountNumber = accountNumber;
_balance = initialBalance;
InterestRate = interestRate;
}
public override void Deposit(double amount)
{
_balance += amount;
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"Successfully Deposited {amount} into Savings Account.");
Console.WriteLine($"Current balance : {_balance}");
Console.ForegroundColor = ConsoleColor.White;
}



public override void Withdraw(double amount)
{
if (amount > _balance)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Insufficient balance in Saving Account.");
Console.ForegroundColor = ConsoleColor.White;
}
else
{
Console.ForegroundColor = ConsoleColor.Green;
_balance -= amount;
Console.WriteLine($"Your Account number is : {_accountNumber}");
Console.WriteLine($"{amount} is withdrawn from {_accountNumber}");
Console.WriteLine($"Your current balance is : {_balance}");
Console.ForegroundColor = ConsoleColor.White;
}
}
}
public class CheckingAccount : BankAccount
{
public double OverdraftLimit { get; private set; }

public CheckingAccount(Int64 accountNumber, double initialBalance, double overdraftLimit)
{
_accountNumber = accountNumber;
_balance = initialBalance;
OverdraftLimit = overdraftLimit;
}
public override void Deposit(double amount)
{
_balance += amount;
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"Successfully Deposited {amount} into Checking Account.");
Console.WriteLine($"Current balance: {_balance}");
Console.ForegroundColor = ConsoleColor.White;
}

public override void Withdraw(double amount)
{
if (amount > _balance)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Insufficient balance in Checking Account.");
Console.ForegroundColor = ConsoleColor.White;
}
else if (amount > OverdraftLimit)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"You can't withdraw more than {OverdraftLimit} from Checking Account.");
Console.ForegroundColor = ConsoleColor.White;
}
else
{
_balance -= amount;
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"Withdrew {amount} from Checking Account.");
Console.WriteLine($"Current balance: {_balance}");
Console.ForegroundColor = ConsoleColor.White;
}
}
}
}
114 changes: 113 additions & 1 deletion week-1/day-2/exercise-2/BankAccount/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,122 @@
namespace BankAccount
{
internal class Program

public class Program
{
static void Main(string[] args)
{
// Create SavingsAccount and CheckingAccount objects and perform operations
Console.WriteLine("Enter 1 => Saving Account");
Console.WriteLine("Enter 2 => Checking Account");
bool isFirstIteration = true;
int YourChoice = 0;
do
{
if (!isFirstIteration && YourChoice != 1 && YourChoice != 2)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("Please Enter Valid Account Choice !!!\n");
Console.ForegroundColor = ConsoleColor.White;
}
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("Please Your Account Choice : ");
Console.ForegroundColor = ConsoleColor.White;

isFirstIteration = false;

} while (!int.TryParse(Console.ReadLine(), out YourChoice) || (YourChoice != 1 && YourChoice != 2));

if (YourChoice == 1)
{
SavingsAccount savingsAccount = new(782378, 5000, 0.05);
Console.WriteLine("Enter 1 => Deposit");
Console.WriteLine("Enter 2 => Withdraw");

int Choice = TansactionChoiceInput();
double Amount = TakeInputAmount();
if (Choice == 1)
{
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine("Please wait ......");
Thread.Sleep(2000);
Console.ForegroundColor = ConsoleColor.White;
savingsAccount.Deposit(Amount);
}
else
{
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine("Please wait ......");
Thread.Sleep(2000);
Console.ForegroundColor = ConsoleColor.White;
savingsAccount.Withdraw(Amount);
}
}
else
{
CheckingAccount checkingAccount = new(782378, 5000, 3000);
Console.WriteLine("Enter 1 => Deposit");
Console.WriteLine("Enter 2 => Withdraw");

int Choice = TansactionChoiceInput();
double Amount = TakeInputAmount();
if (Choice == 1)
{
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine("Please wait ......");
Thread.Sleep(2000);
Console.ForegroundColor = ConsoleColor.White;
checkingAccount.Deposit(Amount);
}
else
{
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine("Please wait ......");
Thread.Sleep(2000);
Console.ForegroundColor = ConsoleColor.White;
checkingAccount.Withdraw(Amount);
}
}
}
private static double TakeInputAmount()
{
double amount = 0;
bool isFirstIteration = true;
do
{
if (!isFirstIteration && amount == 0)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("Please Enter Correct amount !!!\n");
Console.ForegroundColor = ConsoleColor.White;
}
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("Please Enter Amount : ");
Console.ForegroundColor = ConsoleColor.White;
isFirstIteration = false;

} while (!double.TryParse(Console.ReadLine(), out amount));
return amount;
}

private static int TansactionChoiceInput()
{
int TransactionChoice = 0;
bool isFirstIteration = true;
do
{
if (!isFirstIteration && TransactionChoice != 1 && TransactionChoice != 2)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("Please Enter Valid Transaction Choice !!!\n");
Console.ForegroundColor = ConsoleColor.White;
}
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("Please Enter Transaction Choice : ");
Console.ForegroundColor = ConsoleColor.White;
isFirstIteration = false;

} while (!int.TryParse(Console.ReadLine(), out TransactionChoice) || (TransactionChoice != 1 && TransactionChoice != 2));
return TransactionChoice;
}
}
}
42 changes: 42 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,42 @@
using AnimalExercise.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AnimalExercise
{
public abstract class Animal
{
public string? Name { get; set; }
public int Age { get; set; }

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

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

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

public void Move()
{
Console.WriteLine("Dog is moving.");
}
}
}
13 changes: 13 additions & 0 deletions week-1/day-2/exercise-3/AnimalExercise/Interfaces/IMovable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AnimalExercise.Interfaces
{
public interface IMovable
{
void Move();
}
}
12 changes: 11 additions & 1 deletion week-1/day-2/exercise-3/AnimalExercise/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
namespace AnimalExercise
{
internal class Program
public 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>
{
new Dog { Name = "Tommy", Age = 5 },
new Cat { Name = "Jelly", Age = 2 }
};
foreach (var animal in animals)
{
Console.WriteLine($"Name: {animal.Name}, Age: {animal.Age}");
animal.MakeSound();
}
}
}
}
18 changes: 18 additions & 0 deletions week-1/day-2/exercise-4/VehicleManagementSystem/Car.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VehicleManagementSystem.Interfaces;
using VehicleManagementSystem.Models;

namespace VehicleManagementSystem
{
public class Car : Vehicle, IVehicle
{
public void Drive()
{
Console.WriteLine("Car is Moving");
}
}
}
Loading