C# Projects

C# Projects

Parking Garage Charges Calculator

For this project, I developed a C# program to calculate the parking fees for a garage based on a given set of rules. The garage charges a base fee of $8.00 for up to 3 hours of parking. Beyond that, an additional $1.00 is charged for every hour or part of an hour, up to a maximum daily charge of $20.00. The program ensures no car is parked for more than 24 hours at a time.

Key Features and Implementation

User Input Handling: The program begins by prompting the user to enter the number of hours parked. This input is then read from the console and converted to a double data type to handle fractional hours.

Charge Calculation Method: A method called CalculateCharges was created to compute the total parking fee based on the hours parked. The method uses conditional logic to determine whether the parked time exceeds 3 hours and applies the appropriate additional charges, capped at $20.00.

Use of Math.Ceiling: I utilized the Math.Ceiling function to ensure that any partial hour is rounded up, reflecting the policy of charging for any part of an hour.

Lessons Learned

This project helped me solidify several foundational C# programming skills:

Reading and Validating User Input: Gained experience in handling and parsing user input, an essential aspect of creating interactive console applications.

Using Conditional Logic: Applied conditional statements (if and else) to manage multiple scenarios, such as when parking time exceeds the base limit.

Modular Code Organization: By creating a separate method (CalculateCharges), I practiced breaking down a program into smaller, reusable components, improving both readability and maintainability.

Mathematical Functions in C#: Learned how to leverage built-in C# methods like Math.Ceiling to handle real-world mathematical requirements.

Overall, this project enhanced my ability to develop user-friendly applications by applying logical conditions, modular coding practices, and precise calculations.

Sports Team Class Implementation

In this project, I created a C# class that could be used in a business setting, specifically for managing sports teams. The SportsTeam class represents a sports team with various attributes and methods to manage team data efficiently. The goal was to practice creating a class with multiple constructors, private attributes, and public methods.

Key Features and Implementation

Class Design with Private Attributes: The SportsTeam class has three private attributes: teamName (name of the team), sport (type of sport), and numberOfPlayers (number of players in the team). These attributes ensure data encapsulation, a fundamental concept in object-oriented programming (OOP).

Constructors for Flexible Object Creation: The class includes a default constructor and three overloaded constructors, allowing for flexible object creation:

The default constructor initializes attributes to default values ("Unnamed Team", "Unspecified Sport", and 0 players).

Additional constructors allow specifying one, two, or all three attributes, providing flexibility to create a SportsTeam object with varying levels of detail.

Public Methods for Interaction: The class includes two public methods:

SetNumberOfPlayers(int players): Allows setting or updating the number of players on the team.

DisplayTeamInfo(): Outputs the team's information to the console, making it easy to review the current state of the object.

Instantiation and Method Usage: In the Main method of the Program class, I instantiated an instance of SportsTeam with all attributes specified. I demonstrated the use of public methods to display team information and update the number of players.

Lessons Learned

Through this project, I deepened my understanding of several OOP concepts in C#:

Encapsulation and Data Protection: By using private attributes, I learned how to protect data integrity while providing controlled access through public methods.

Overloading Constructors: Implementing multiple constructors with different parameters allowed me to explore how overloading can offer flexibility in object instantiation.

Practical Application of OOP Principles: This project reinforced the importance of classes, objects, and methods, helping me understand how these concepts can be applied to solve real-world business problems.

Overall, this project was an excellent exercise in object-oriented design, demonstrating how to create modular, maintainable code that effectively models real-world entities.

Employee and Supervisor Class Hierarchy

In this project, I created a simple class hierarchy to manage employee data in a business context. The project involved building two object classes: Employee and Supervisor, where Supervisor inherits from Employee. The focus was on demonstrating inheritance, method overriding, and object-oriented design principles in C#.

Key Features and Implementation

Base Class: Employee

The Employee class has three string attributes: FirstName, LastName, and HireDate, representing the basic details of an employee.

A constructor method initializes these attributes with values provided during object creation.

The class overrides the ToString() method to return a string that concatenates the three attributes, separated by commas. This method provides a convenient way to display employee information in a standardized format.

Derived Class: Supervisor

The Supervisor class inherits from the Employee class and introduces an additional attribute, EmployeesSupervised, to represent the number of employees managed by the supervisor.

A constructor method initializes all inherited attributes (FirstName, LastName, HireDate) along with the new EmployeesSupervised attribute. This constructor uses the base keyword to call the parent class (Employee) constructor, ensuring proper initialization.

The ToString() method is overridden in the Supervisor class to call the base class's ToString() method and then append the EmployeesSupervised information. This demonstrates how derived classes can extend or modify the behavior of base classes.

Testing the Classes

In the Test class, I instantiated a Supervisor object with all required attributes. The ToString() method was called implicitly when the object was passed to Console.WriteLine(), which outputs all the details about the supervisor to the console.

Lessons Learned

This project provided valuable experience in using inheritance and method overriding in C#:

Understanding Inheritance: I learned how to create a base class (Employee) and a derived class (Supervisor), which inherits properties and methods, showcasing code reuse and extension.

Method Overriding: Overriding the ToString() method in both classes taught me how to customize object representation and ensure that subclasses enhance or refine base class functionality.

Object-Oriented Design Practices: The project reinforced the importance of modular code and the power of inheritance in reducing redundancy, making the code easier to maintain and extend.

Overall, this project deepened my understanding of object-oriented principles, particularly inheritance and polymorphism, by demonstrating how they can be applied to real-world business scenarios.