0% found this document useful (0 votes)
15 views4 pages

Csharp Oop Assignment

The document outlines an assignment for Object-Oriented Programming in C# at the University of Ghana's Department of Computer Science. It includes six questions requiring the implementation of various classes and concepts such as encapsulation, inheritance, polymorphism, and interfaces, focusing on real-world applications like banking, student grading, and payment processing. Students are instructed to submit their work in PDF format with clear comments explaining their code implementations.

Uploaded by

robertkaidoo6
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views4 pages

Csharp Oop Assignment

The document outlines an assignment for Object-Oriented Programming in C# at the University of Ghana's Department of Computer Science. It includes six questions requiring the implementation of various classes and concepts such as encapsulation, inheritance, polymorphism, and interfaces, focusing on real-world applications like banking, student grading, and payment processing. Students are instructed to submit their work in PDF format with clear comments explaining their code implementations.

Uploaded by

robertkaidoo6
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

UNIVERSITY OF GHANA

Department of Computer Science

Assignment: Object-Oriented Programming in C#

Instructions
• Answer all questions.
• Use Object-Oriented Programming (OOP) principles such as encapsulation, inheritance,
polymorphism, abstraction, and interfaces where appropriate.
• Submit your work PDF containing all C# source files with clear comments explaining
your implementation.

Question 1 – BankAccount Class


Design a class called BankAccount with the following requirements.

Private Fields:

• accountNumber (string)
• accountHolderName (string)
• balance (double)

Public Methods:

• Deposit(double amount)
• Withdraw(double amount)
• GetBalance()
• GetAccountNumber()

Constraints:

• Balance must not be directly accessible outside the class.


• Prevent withdrawals when there are insufficient funds.
• Prevent depositing negative amounts.
• Display appropriate error messages when invalid operations occur.

Tasks:

• Implement the BankAccount class in C#.


• Write a test program demonstrating a valid deposit, an invalid deposit, a valid
withdrawal, and an invalid withdrawal.

Question 2 – Student Class


Create a class called Student with the following fields:

Private Fields:

• studentId
• name
• score

Requirements:

• Provide appropriate getters and setters using properties or methods.


• Ensure the score must be between 0 and 100.

Create a method GetGrade() that returns the student’s grade


according to the following scale:

Score Range Grade

70–100 A

60–69 B

50–59 C

45–49 D

Below 45 F

Tasks:

• Implement the class using proper encapsulation.


• Demonstrate how invalid scores are prevented.

Question 3 – Employee Inheritance


Create a superclass called Employee.

Fields:

• name
• salary
Method:

• CalculateAnnualSalary()

Create two subclasses:

• FullTimeEmployee – includes an additional field bonus and overrides


CalculateAnnualSalary().
• PartTimeEmployee – includes fields hoursWorked and hourlyRate and overrides
CalculateAnnualSalary().

Tasks:

• Implement all classes using inheritance.


• Create objects for both subclasses.
• Demonstrate how annual salary is calculated differently for each employee type.

Question 4 – Vehicle Method Overriding


Create a superclass called Vehicle.

Field:

• brand

Method:

• StartEngine()

Create the following subclasses:

• Car
• Motorcycle

Tasks:

• Override the StartEngine() method in both subclasses.


• Demonstrate method overriding.
• Show the use of the base keyword where appropriate.

Question 5 – Abstract Class and Polymorphism


Create an abstract class called Payment with a method ProcessPayment(double amount).

Create the following subclasses:


• CreditCardPayment
• MobileMoneyPayment
• BankTransferPayment

Tasks:

• Store all payment objects in a List<Payment> or array.


• Use a loop to process the payments.
• Demonstrate runtime polymorphism.

Question 6 – Interface Implementation


Create an interface called IATMOperations with the following methods:

• Withdraw(double amount)
• Deposit(double amount)
• CheckBalance()

Create a class BankATM that implements this interface.

Tasks:

• Implement all interface methods.


• Ensure the system hides internal implementation details.
• Demonstrate ATM operations through a test program.

You might also like