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
22 changes: 20 additions & 2 deletions week-1/day-2/exercise-1/Circle/Circle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,26 @@

namespace Circle
{
internal class Circle
public class Circle
{
// Implement the Circle class here
private double Radius;
// Constructor for the Circle class, initializes the radius
public Circle(double radius)
{
Radius = radius;
}

// Method to calculate and return the area of the circle
public double GetArea()
{
return Math.Round(Math.PI * Radius * Radius); // Calculate and round the area
// Alternative: return Math.PI * Math.Pow(Radius, 2);
}

// Method to calculate and return the circumference of the circle
public double GetCircumference()
{
return Math.Round(2 * Math.PI * Radius); // Calculate and round the circumference
}
}
}
11 changes: 9 additions & 2 deletions week-1/day-2/exercise-1/Circle/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
namespace Circle
{
internal class Program
public class Program
{
// Entry point of the program
static void Main(string[] args)
{
// Create a Circle object and display its area and circumference
double radius = 5.5; // Define the radius of the circle

Circle areaObj = new Circle(radius); // Create a Circle object with the given radius

// Print the calculated area and circumference of the circle
Console.WriteLine("The Area of Circle is " + areaObj.GetArea());
Console.WriteLine("The Circumference of Circle is " + areaObj.GetCircumference());
}
}
}
86 changes: 86 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,86 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BankAccount
{
// Abstract class
public abstract class BankAccount
{
// Properties
public long AccountNumber; // The account number associated with the bank account.
public double Balance; // The current balance in the bank account.

// Methods
public abstract void Deposit(double amount); // Abstract method to deposit money into the account.
public abstract void Withdraw(double amount); // Abstract method to withdraw money from the account.
}

// First Derived class
class SavingsAccount : BankAccount
{
private double InterestRate; // The interest rate for the savings account.

// Constructor to initialize the savings account.
public SavingsAccount(long accountNumber, double balance, double interestRate)
{
AccountNumber = accountNumber;
Balance = balance;
InterestRate = interestRate;
}

// Deposit method for savings account.
public override void Deposit(double amount)
{
Balance += amount;
}

// Withdraw method for savings account.
public override void Withdraw(double amount)
{
if (amount <= Balance)
{
Balance -= amount;
}
else
{
Console.WriteLine($"Insufficient Balance. Your Main Balance is {Balance}");
}
}
}

// Second Derived class
class CheckingAccount : BankAccount
{
private double OverdraftLimit; // The overdraft limit for the checking account.

// Constructor to initialize the checking account.
public CheckingAccount(long accountNumber, double balance, double overdraftLimit)
{
AccountNumber = accountNumber;
Balance = balance;
OverdraftLimit = overdraftLimit;
}

// Deposit method for checking account.
public override void Deposit(double amount)
{
Balance += amount;
}

// Withdraw method for checking account.
public override void Withdraw(double amount)
{
if (amount <= OverdraftLimit + Balance)
{
Balance -= amount;
}
else
{
Console.WriteLine("Exceed the limit of withdrawn for existing balance and overdraft limit.");
}
}
}
}
16 changes: 14 additions & 2 deletions week-1/day-2/exercise-2/BankAccount/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
namespace BankAccount
{
internal class Program
public class Program
{
static void Main(string[] args)
{
// Create SavingsAccount and CheckingAccount objects and perform operations
// Creating instances of SavingsAccount and CheckingAccount
SavingsAccount savingsAccount = new SavingsAccount(34572637483, 1000.50, 0.4);
CheckingAccount checkingAccount = new CheckingAccount(34572637483, 200, 400);

// Performing operations on the savings account
savingsAccount.Deposit(1000);
savingsAccount.Withdraw(750);
Console.WriteLine($"SavingsAccount Balance is: {savingsAccount.Balance}");

// Performing operations on the checking account
checkingAccount.Deposit(1000);
checkingAccount.Withdraw(3000);
Console.WriteLine($"CheckingAccount Balance is: {checkingAccount.Balance}");
}
}
}
58 changes: 58 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,58 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AnimalExercise
{
// Abstract class for animals
public abstract class Animal
{
// Properties of an animal
public string? Name; // Name of the animal (can be null)
public int Age; // Age of the animal

// Abstract method for making a sound
// The body of this method must be provided by derived classes
public abstract void MakeSound();
}

// Interface for movable objects
interface IMovable
{
void Move(); // Method to define movement behavior
}

// First derived class: Dog
class Dog : Animal, IMovable
{
public override void MakeSound()
{
// Implementation of the MakeSound method for a dog
Console.WriteLine("Dog Sounds - Woof Woof...");
}

public void Move()
{
// Implementation of the Move method for a dog
Console.WriteLine("This is the Move() method.");
}
}

// Second derived class: Cat
class Cat : Animal, IMovable
{
public override void MakeSound()
{
// Implementation of the MakeSound method for a cat
Console.WriteLine("Cat Sounds - Meow Meow...\n");
}

public void Move()
{
// Implementation of the Move method for a cat
Console.WriteLine("This is the Move() method.");
}
}
}
14 changes: 12 additions & 2 deletions 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
// Create instances of Dog and Cat
Dog dogSound = new Dog();
Cat catSound = new Cat();

// Call the MakeSound method for both objects
dogSound.MakeSound();
catSound.MakeSound();

// Call the Move method for both objects
dogSound.Move();
catSound.Move();
}
}
}
21 changes: 21 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,21 @@
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);
}
}
34 changes: 34 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,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VehicleManagementSystem
{
// Define an interface for vehicles.
public interface IVehicle
{
void Drive();
}

// Define a class representing a Car, which implements the IVehicle interface.
public class Car : IVehicle
{
// Implement the Drive method for the Car class.
public void Drive()
{
Console.WriteLine("Driving Car.");
}
}

// Define a class representing a Truck, which implements the IVehicle interface.
public class Truck : IVehicle
{
// Implement the Drive method for the Truck class.
public void Drive()
{
Console.WriteLine("Driving Truck.");
}
}
}
62 changes: 60 additions & 2 deletions week-1/day-2/exercise-4/VehicleManagementSystem/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,68 @@
namespace VehicleManagementSystem
{
internal class Program
public class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
// Prompt the user to input a vehicle type
Console.WriteLine("1. Factory Design Method.");
Console.Write("Enter a vehicle type car or truck: ");
string? vehicleType = Console.ReadLine();
// Retrieve the appropriate vehicle factory based on user input
VehicleFactory vehicleFactory = GetVehicleFactory(vehicleType);

if (vehicleFactory != null)
{
// Use the factory to create a vehicle and perform a drive action
IVehicle vehicle = vehicleFactory.CreateVehicle();
Console.WriteLine("\nVehicle created:");
vehicle.Drive();
}
else
{
Console.WriteLine("Invalid vehicle type.");
}

Console.WriteLine("\n2.Repository CRUD operation.\n");

// Create instances of VehicleRepository and VehicleLogger
VehicleRepository vehicleRepository = new VehicleRepository();
VehicleLogger vehicleLogger = VehicleLogger.Instance;

// Create a VehicleService and associate it with the repository and logger
VehicleService vehicleService = new VehicleService(vehicleRepository, vehicleLogger);

// Create instances of CarFactory and TruckFactory
CarFactory carFactory = new CarFactory();
TruckFactory truckFactory = new TruckFactory();

// List vehicles and demonstrate adding/removing vehicles
vehicleService.AddVehicle(carFactory);
vehicleService.AddVehicle(carFactory);
vehicleService.AddVehicle(truckFactory);

vehicleService.ListVehicles();
vehicleService.RemoveVehicle(1);
vehicleService.AddVehicle(truckFactory);
vehicleService.ListVehicles();

// Demonstrate performing actions on vehicles
vehicleService.DoSomethingWithVehicle(1);
vehicleService.DoSomethingWithVehicle(2);
}

// Helper function to get the appropriate vehicle factory based on input
static VehicleFactory GetVehicleFactory(string vehicleType)
{
switch (vehicleType.ToLower())
{
case "car":
return new CarFactory();
case "truck":
return new TruckFactory();
default:
return null;
}
}
}
}
Loading