0% found this document useful (0 votes)
29 views12 pages

OOPM Assi 1to6

The document outlines a series of practical assignments for a course on Object Oriented Programming Methodology for FY CS/IT Sem - 2. Each assignment focuses on different aspects of OOP, including hierarchical inheritance, multilevel inheritance, exception handling, data hiding, and working with classes and objects. The assignments require students to implement various functionalities in Java, such as account management and exception handling, while adhering to specific guidelines and requirements.

Uploaded by

pandyaj036
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)
29 views12 pages

OOPM Assi 1to6

The document outlines a series of practical assignments for a course on Object Oriented Programming Methodology for FY CS/IT Sem - 2. Each assignment focuses on different aspects of OOP, including hierarchical inheritance, multilevel inheritance, exception handling, data hiding, and working with classes and objects. The assignments require students to implement various functionalities in Java, such as account management and exception handling, while adhering to specific guidelines and requirements.

Uploaded by

pandyaj036
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
You are on page 1/ 12

‭MAJOR-2 : Object Oriented Programming Methodology‬

‭P ractical Assignments‬
‭FY CS / IT Sem - 2‬

‭PRACTICAL ASSIGNMENT - 6‬
‭Week : 3rd - 8th March,2025‬
‭Aim :‬‭Implementing Hierarchical Inheritance‬

‭Create following classes and relationships with their respective data members.‬

‭ .‬ ‭Create objects of Savings A/c and Current A/c.‬


1
‭2.‬ ‭Deposit Rs 5000 in Savings A/c.‬
‭3.‬ ‭Deposit Rs 10000 in Current A/c.‬
‭4.‬ ‭Find Monthly interest received based on Interest rate 10% on Savings A/c.‬
‭5.‬ ‭Find Monthly interest received based on Interest rate 15% on Current A/c.‬
‭6.‬ ‭Withdraw from Savings A/c (the amount taken from the user). Do not allow withdrawal if‬
‭account balance is less than Rs. 1000.‬
‭7.‬ ‭Withdraw from Current A/c (the amount taken from the user). Do not allow withdrawal if‬
‭account balance is less than Rs. 10000.‬

‭Prepared by: Prof. Lavleena Stephens‬


‭MAJOR-2 : Object Oriented Programming Methodology‬
‭P ractical Assignments‬
‭FY CS / IT Sem - 2‬

‭PRACTICAL ASSIGNMENT - 5‬
‭Week : 24th Feb - 1st March,2025‬
‭Aim :‬‭Implementing Multilevel Inheritance‬

‭1.‬ ‭Implement the following inheritance :‬

‭2.‬ ‭Using an array of objects, add and display data of at least 3 Under Graduate Students.‬
‭Input the values of student’s name, phone number, email address, enrollment number,‬
‭course and total marks scored.‬
‭[NOTE : CGPA should not be input, but must be calculated using calcCGPA]‬
‭[CGPA = TotalMarks x 10 / 500 , TotalMarks should be from 0 to 500 only]‬

‭Prepared by: Prof. Lavleena Stephens‬


‭MAJOR-2 : Object Oriented Programming Methodology‬
‭P ractical Assignments‬
‭FY CS / IT Sem - 2‬

‭PRACTICAL ASSIGNMENT - 4‬
‭Week : 3rd-15th February,2025‬
‭Aim :‬‭Implementing Simple Inheritance‬

‭NOTE: Create MENU DRIVEN application‬

‭SIMPLE‬

‭Implement OOP in Java using the following information.‬

‭Create the class called‬‭“Customer”‬‭as follows with‬‭given accessibility for its members‬‭:‬

‭(NOTE: +‬‭indicates‬‭Private, *‬‭indicates‬‭Public)‬


‭Class: Customer‬

‭ ata member:‬
D
‭+‬‭Name‬
‭+‬‭Age‬
‭+‬‭Contact‬

‭Note: Create a constructor to initialize the data members‬

‭MODERATE‬

‭Extend the above program to add the following functionalities:‬

‭1)‬ ‭Create a class account‬‭“Account ”‬‭which will inherit‬‭the Customer class.‬


‭(Use the keyword‬‭extends‬‭for inheritance.)‬

‭Prepared by: Prof. Lavleena Stephens‬


‭MAJOR-2 : Object Oriented Programming Methodology‬
‭P ractical Assignments‬
‭FY CS / IT Sem - 2‬

‭Class: Customer‬

‭ ata member:‬
D
‭+‬‭Name‬
‭+‬‭Age‬
‭+‬‭Contact‬

‭↑‬
‭Class: Account‬

‭ ata members:‬
D
‭+‬‭Accno‬
‭+‬‭Balance‬

‭ ember functions:‬
M
‭*‬‭deposit(double amt)‬
‭*‬‭withdraw(double amt)‬
‭*‬‭transfer(Account a1, Account a2, double amt)‬
‭*‬‭s howCustomers() : method to display all customers‬

‭Menu options :‬

‭Prepared by: Prof. Lavleena Stephens‬


‭MAJOR-2 : Object Oriented Programming Methodology‬
‭P ractical Assignments‬
‭FY CS / IT Sem - 2‬
‭2)‬ ‭Input and display user details like name, age, contact, accno, and bal for n‬
‭customers.‬‭Implement an array of objects.‬
‭[HINT: Create objects of child class only.]‬
‭Expected Input:‬
‭Welcome! Enter following details:‬
‭Name: Peter Andrews‬
‭Age: 30‬
‭Contact Number: 4478962586‬
‭AccountNo: 111‬
‭Balance: 20000‬
‭(Repeat taking input of n customers)‬

E‭ xpected Output:‬
‭Name‬ ‭Age‬ ‭Contact Number‬ ‭Account Number Balance‬
‭_________________________________________________________________‬
‭Peter Andrews‬ ‭30‬ ‭4478962586‬ ‭111‬ ‭20000‬
‭Emma Stone‬ ‭30‬ ‭3456345675‬ ‭222‬ ‭30000‬
‭(Show details of n customers )‬

‭ADVANCED‬
‭1)‬ ‭Allow the user to‬‭deposit‬‭some amount in the account.‬‭Display the reflected balance in‬
‭the account after the transaction.‬
‭Expected Input:‬
‭Enter AccountNo: 111‬
‭Enter the amount you wish to deposit: 10000‬
‭Expected Output:‬
‭Transaction Successful!‬
‭AccountNo: 111‬
‭Final balance: 30000‬

‭2)‬ ‭Allow the user to‬‭withdraw‬‭some amount from the account;‬‭only if the withdrawal‬
‭amount is less than the account balance‬‭, otherwise‬‭throw an exception. Display the final‬
‭balance in the account after the transaction.‬
‭Expected Input:‬
‭Enter AccountNo: 111‬
‭Enter the amount you wish to withdraw: 40000‬
‭Expected Output:‬
‭Sorry! You don’t have a sufficient balance in your account.‬

‭Prepared by: Prof. Lavleena Stephens‬


‭MAJOR-2 : Object Oriented Programming Methodology‬
‭P ractical Assignments‬
‭FY CS / IT Sem - 2‬

E‭ xpected Input:‬
‭Enter AccountNo: 111‬
‭Enter the amount you wish to withdraw: 10000‬
‭Expected Output:‬
‭Transaction Successful!‬
‭AccountNo: 111‬
‭Final balance: 10000‬

‭3)‬ ‭Allow the user to‬‭transfer‬‭some amount from his account‬‭to another account;‬‭only if the‬
‭transfer amount is less than the account balance‬‭,‬‭otherwise throw an exception. Display‬
‭the final balance of both accounts after the transaction.‬
‭Expected Input:‬
‭Enter your AccountNo: 111‬
‭Enter AccountNo you wish to transfer: 222‬
‭Enter the amount you wish to transfer: 30000‬
‭Expected Output:‬
‭Sorry! You don’t have a sufficient balance in your account.‬

E‭ xpected Input:‬
‭Enter your AccountNo: 111‬
‭Enter AccountNo you wish to transfer: 222‬
‭Enter the amount you wish to transfer: 10000‬
‭Expected Output:‬
‭Transaction Successful!‬
‭AccountNo: 111 Balance: 10000‬
‭AccountNo: 222 Balance: 40000‬

‭Prepared by: Prof. Lavleena Stephens‬


‭MAJOR-2 : Object Oriented Programming Methodology‬
‭P ractical Assignments‬
‭FY CS / IT Sem - 2‬
‭Cases for displaying details :‬

‭Case for Transfer :‬

‭Prepared by: Prof. Lavleena Stephens‬


‭MAJOR-2 : Object Oriented Programming Methodology‬
‭P ractical Assignments‬
‭FY CS / IT Sem - 2‬

‭PRACTICAL ASSIGNMENT - 3‬
‭Week : 27th Jan - 1st Feb,2025‬
‭Aim :‬‭Implementing Exception Handling‬

‭PART 1‬
‭1.‬ ‭Write a program in Java to accept two numbers from the user. Raise the‬
‭ArithmeticException‬‭when the user tries to divide‬‭num1 by num2, and num2 is zero.‬
‭2.‬ ‭Write a java program which accepts the elements of an integer array of size‬‭n‬‭, and displays‬
‭the same. Catch the‬‭ArrayIndexOutOfBoundsException‬‭whenever the user tries to access‬
‭the array outside of its bound (range).‬

‭PART 2‬
‭ reate the following exceptions, with reference to the Student class created in previous‬
C
‭assignments:‬
‭1.‬ ‭If the user tries to input a String value for the s_id, throw the‬‭InputMismatchException‬
‭and print the message‬‭“Invalid Input !”‬‭in the catch‬‭block.‬
‭2.‬ ‭If the user enters total_marks less than zero or greater than 500, throw a user-defined‬
‭exception named‬‭“InvalidMarksException”‬‭.‬
‭3.‬ ‭Finally‬‭, print the message‬‭“Student details entered!”‬‭,‬‭regardless of if any exception is‬
‭raised or not.‬

S‭ ELF REFERENCE‬
‭ rocess of Exception Handling :‬
P

‭Prepared by: Prof. Lavleena Stephens‬


‭MAJOR-2 : Object Oriented Programming Methodology‬
‭P ractical Assignments‬
‭FY CS / IT Sem - 2‬

‭Creating User-defined Exceptions :‬


‭1)‬ ‭Create your Exception class, which inherits the base class‬‭“Exception”‬‭.‬
‭2)‬ ‭Add‬‭constructors‬‭in your custom exception class.‬
‭3)‬ ‭Throw the exception using the‬‭throw‬‭keyword.‬
‭4)‬ ‭Handle the exception using its suitable‬‭catch‬‭block.‬

E‭ xample :‬
‭Suppose you’re writing a program where a user inputs his age to determine the eligibility to vote.‬
‭Throw an exception when his age is under 18.‬

‭Creating Exception class :‬

‭Handling exception :‬

‭Prepared by: Prof. Lavleena Stephens‬


‭MAJOR-2 : Object Oriented Programming Methodology‬
‭P ractical Assignments‬
‭FY CS / IT Sem - 2‬

‭PRACTICAL ASSIGNMENT - 2‬
‭Week : 1st-4th January,2025‬
‭Aim :‬‭Implementing data hiding & getter and setter‬‭methods.‬
‭Working with array of objects.‬

‭PART 1‬
‭1.‬ ‭Implement data hiding for the‬‭Student‬‭class earlier‬‭created in‬‭Assignment-1‬‭.‬
‭[make all attributes private.]‬
‭2.‬ ‭Create respective getter and setter methods for all attributes.‬
‭[make all getter-setter methods public so that attributes can be accessed outside the class.]‬
‭ .‬ ‭Now, initialize the instance variables of objects using the common setter method.‬
3
‭4.‬ ‭Print the student attributes using their respective getter methods.‬‭[in tabular format]‬

‭PART 2‬
‭1.‬ ‭Using the Student class, create and initialize an array of objects of size 2.‬
‭Print the details of all students.‬‭[Use Static values]‬
‭2.‬ ‭Implement another array of objects of size‬‭n‬‭using‬‭user input values.‬
‭Print the details of all students.‬‭[Use Dynamic values]‬

‭Prepared by: Prof. Lavleena Stephens‬


‭MAJOR-2 : Object Oriented Programming Methodology‬
‭P ractical Assignments‬
‭FY CS / IT Sem - 2‬

‭PRACTICAL ASSIGNMENT - 1‬
‭Week : 23rd-28th December,2024‬
‭Aim :‬‭Working with classes, objects and constructors‬

‭1.‬ ‭Implement the following structure :‬

‭Student‬

s‭ _id‬
‭s_name‬
‭dob‬
‭dept‬
‭total_marks‬‭(out of 500)‬
‭perc‬

S‭ tudent() :‬‭the default constructor‬


‭Student() :‬‭a parameterized constructor to initialize‬‭all instance variables; except percentage‬
‭calcPerc() :‬‭to calculate the perc of a student‬
‭isEligibleToEnroll()‬‭:‬‭to print the eligibility message‬
‭getStudentDetails()‬‭:‬‭to print all details of a student‬

I‭f the default constructor is used, then the‬‭dept‬‭value must be set to‬‭“IT”‬‭.‬
‭The‬‭calcPerc()‬‭method is used to calculate the percentage,‬‭based on total_marks input by‬
‭the user.‬
‭The‬‭isEligibleToEnroll()‬‭method will print “‬‭Eligible‬‭”‬‭if the percentage is above 65, else it‬
‭will print “‬‭Not Eligible‬‭”.‬
‭Enter values for at least 3 students and print the details in a tabular form.‬

[‭ Static input will not be considered.]‬


‭Expected Output :‬
‭Id‬ ‭Name‬ ‭DOB‬ ‭Dept‬ ‭ erc‬
P E‭ ligibility‬
‭1‬ ‭Charles‬ ‭17/03/2004‬ ‭IT‬ ‭72‬ ‭Eligible‬
‭2‬ ‭Mark‬ ‭22/08/2003‬ ‭MB‬ ‭55‬ ‭Not Eligible‬
‭3‬ ‭Jacky‬ ‭12/01/2004‬ ‭BT‬ ‭89‬ ‭Eligible‬

‭Prepared by: Prof. Lavleena Stephens‬


‭MAJOR-2 : Object Oriented Programming Methodology‬
‭P ractical Assignments‬
‭FY CS / IT Sem - 2‬

‭PRACTICAL ASSIGNMENT - 0‬
‭Week : 16th-21st December,2024‬
‭Aim :‬‭Introduction to OOP & revisiting Java Fundamentals‬

‭1.‬ ‭Create a user defined class named‬‭Area‬‭. It should‬‭contain the following methods:‬
‭circle() :‬‭to print area of a circle‬
‭square() :‬‭to print area of a square‬
‭triangle() :‬‭to print area of a triangle‬
‭[NOTE :‬‭define PI as a final variable‬‭(‬‭constant‬‭)‬‭in Area class‬‭]‬
‭Create an object, initialize necessary parameters within the concerned methods, and print‬
‭the area of all shapes in output.‬

‭2.‬ ‭Implement the following class structure in the program :‬


‭Pen‬

t‭ ype‬
‭colour‬
‭brand‬
‭price‬

s‭ etPenDetails()‬‭: set all details of a pen‬


‭printPenDetails()‬‭: print all details of a pen‬

‭ reate at least 2 different objects of Pen class, setting different attributes for them and‬
C
‭print their details.‬

‭3.‬ ‭Implement the following class structure in the program :‬


‭ArraySum‬

‭num[]‬

s‭ etElements(int[] array)‬‭: initialize array elements‬


‭printSum()‬‭: prints the sum of array elements‬

‭Create at least 2 different objects of the ArraySum class and print the sum of each.‬

‭Prepared by: Prof. Lavleena Stephens‬

You might also like