0% found this document useful (0 votes)
26 views

LabAssignment#1 (HUSNAIN)

The document outlines 3 activities on object-oriented programming concepts: 1. Create a Car class with variables to store data and display functions, then create objects and display data in a runner class. 2. Modify a bank account class to support procedural and OOP approaches, adding withdraw and deposit functions and testing with multiple account objects. 3. Create an Employee class with data variables and functions to assign values and check tenure, then create objects and check tenure in a runner class.

Uploaded by

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

LabAssignment#1 (HUSNAIN)

The document outlines 3 activities on object-oriented programming concepts: 1. Create a Car class with variables to store data and display functions, then create objects and display data in a runner class. 2. Modify a bank account class to support procedural and OOP approaches, adding withdraw and deposit functions and testing with multiple account objects. 3. Create an Employee class with data variables and functions to assign values and check tenure, then create objects and check tenure in a runner class.

Uploaded by

Ehtisham Javed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

COMSATS University Islamabad, Wah Campus

Lab Assignment # 1
Department of Computer Science

Program/Class: BSSE 3A & 3B Date: 18 September 2023


Subject: Object Oriented Programming Instructor: Ayesha Naeem
Name : Muhammad Husnain Shehnsha Reg No : FA22-BSE-024
_______________________________________________________________________

Object Oriented approached to programming [CLO1]


Activity 1:
Write a program that has variables to store Car data like; CarModel, CarName, CarPrice and
CarOwner. The program should include functions to assign user defined values to the above
mentioned variable and a display function to show the values . Write a main that calls these
functions.
Now write another runner class that declares three Car objects and displays the data of all
three.
Solution:
Main file (File name = labAssignment1):
Class file (File name = Car):
Output:

Activity 2:
Procedural Approach Object Oriented Approach
public class Account{ public class Account{
static double balance; double balance;
public static void setBalance(double b) public void setBalance(double b)
{ balance = b;} { balance = b;}
public static void showBalance() public void showBalance()
{ {
System.out.println(“Balance is”+ balance); System.out.println(“Balance is”+
} balance);
public static void main() }
{ }
setBalance (5000); public class runner
showBalance (); // output would be 5000 {
} public static void main()
} {
Account a1= new Account ();
a1.setBalance(2500);
a1.showBalance();

//output would be2500; it belongs to a1

Account a2= new Account ();


a2.setBalance(5000);
a2.showBalance();

//output would be 5000; it belongs to a2

Modify the above activity and include functions of withdraw and deposit.
Test these methods in main for procedural approach. For Object Oriented approach, modify the
runner class and call withdraw and deposit functions for two objects.
Solution for Procedural Approach:
Output:
Solution for OOP:
Output:

Activity 3:
Write a program that contains variables to hold employee data like; employeeCode,
employeeName and date Of Joining. Write a function that assigns the user defined values to
these variables. Write another function that asks the user to enter current date and then
checks if the employee tenure is more than three years or not. Call the functions in main.
Now write a runner class that declares two employee objects and check their tenure periods

Solution:
Output:

You might also like