0% found this document useful (0 votes)
274 views3 pages

OOP Exercises for Java Applications

The document provides multiple exercises to design and implement object-oriented programs to model real-world scenarios such as a bookstore, bank customer registration, student grade calculation, and more. Students are instructed to create classes to represent entities like books, customers, and students, and write methods to set attributes, calculate values, and sort or retrieve objects based on certain criteria. Tests are provided to validate the class implementations through sample code and data.

Uploaded by

mohsin asma
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)
274 views3 pages

OOP Exercises for Java Applications

The document provides multiple exercises to design and implement object-oriented programs to model real-world scenarios such as a bookstore, bank customer registration, student grade calculation, and more. Students are instructed to create classes to represent entities like books, customers, and students, and write methods to set attributes, calculate values, and sort or retrieve objects based on certain criteria. Tests are provided to validate the class implementations through sample code and data.

Uploaded by

mohsin asma
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

Assignment 5

Design and implement applications using basic OOP paradigms.

Write a program as below guideline:

2. Write a program, which creates an instance of employee class and sets the values
for all the attributes.

• While setting value for empName, setEmpName() method should check for
NullPointer and display appropriate error message.

• While setting value for empDesig, the designation must have any of the following
values:

developer, tester, Lead or manager. If none of these values is matching then setter
method should display 'Invalid designation' error message.

• While setting value for empDept, the department must have any of the following
values: TTH, RCM, Digital, DevOps. If none of these values is matching then
setter method should display 'Invalid Dept' error message.

Exercise: Design and implement applications using basic OOP paradigms.

Develop a program that assists bookstore employees. For each book, the program
should track the book’s title, its price, its year of publication, and the author’s
name. . . . Develop an appropriate Java Class. Create instances of the class to
represent these three books:

• Daniel Defoe, Robinson Crusoe, $15.50, 1719; · Joseph Conrad, Heart of


Darkness, $12.80, 1902; · Pat Conroy, Beach Music, $9.50, 1996.

Exercise: Design and implement applications using basic OOP paradigms.

XYZ bank wants to maintain customer details. It will register the customer details
whenever a person opens an account with the bank. Below is the customer class
diagram:

At times, the customer registration process changes, here are the guidelines:

1. Admin may register customer by filling only ID, name and address details 2.
Admin may register customer by filling only ID and name

3. Admin may register customer by filling all the details.


Write an application which implements above scenario. Write main method in
separate class, which creates different customer objects and invokes appropriate
constructors, here is sample code:

Note: When other data members which are not initialized through constructors
should have appropriate default values.

Exercise: Design and implement applications using basic OOP paradigms.

Exercise: Design and implement applications using basic OOP paradigms.

Objective:

Given a class diagram for a problem, use the method and constructor overloading
concepts to solve the problem and test using a set of values in an IDE.

Problem Description: The admin of a pre-university college wants to calculate the


marks of students in a particular course based on some criteria. Write a Java
program to implement the below given class diagram.

Student

-studentId: int

-studentName: String

-marks: float

-secondChance: boolean

+Student(int,String,String)

+getStudentId(): int +getStudentName(): String +getMarks(): float


+getSecondChance(): Boolean +identifyMarks(float): void +identifyMarks(float,
float): void

Student Class:

Constructor: Initializes studentId, studentName and secondChance.

identifyMarks(float) method:

This method is used to set the marks of the student if the student has cleared in the
first chance itself, i.e. second chance is false. This method accepts the marks
scored by the student which must be set in the marks instance variable.
identifyMarks (float, float) method:

This method is used to set the marks of the student if the student has taken the
second chance i.e. second chance is true. This method accepts the marks scored by
the student in the first chance and second chance. The maximum of both these
marks must be identified and set in the marks instance variable.

Starter Class:

Write a starter class named Demo,

Step1: Create an object of Student class by passing appropriate values to the


constructor. Step2: Based on the value used for second chance instance variable,
invoke the appropriate identifyMarks() method.

Step3: Invoke the getter methods and display all the instance variable values of the
Student object created. Create one more object (use different value for second
chance) by repeating steps 1 to 3 and test your program.

Exercise 34: Design and implement applications using basic OOP paradigms.

Create menu driven program to implement following scenario:

1. Create Student Record

2. Display Student Names in sorted order based on branch (alphabetical order) 3.


Display Student ID in ascending sorted order

Exercise: Design and implement applications using basic OOP paradigms.

Create a method which accepts array of ‘Student’ objects and returns Student
object who has scored highest marks.

Note: Each Student object should have following values:

• ID

• Name

• Branch

• Score

Common questions

Powered by AI

Method overloading is used in the 'identifyMarks' method to determine a student's marks based on whether they passed on their first or second attempt. If the 'secondChance' is false, a single float argument method sets the marks. If 'secondChance' is true, a two-float arguments method computes the maximum of first and second chances' marks to set the final score .

The program should handle setting the 'empDesig' attribute by checking if the given designation matches one of the predefined values: developer, tester, Lead, or manager. If the designation does not match any of these values, the setter method should display an 'Invalid designation' error message .

A method should iterate through an array of Student objects, comparing their scores using a loop or sorting technique. The student with the highest score should be returned by the method, ensuring efficient data processing within the program .

The Java program should check the 'secondChance' boolean variable. If it is false, the program should invoke the 'identifyMarks(float)' method. If true, it should invoke 'identifyMarks(float, float)' method to process and set the marks based on both attempts .

The 'empDept' setter should verify if the input matches allowed department values: TTH, RCM, Digital, or DevOps. If none of these values are matched, the setter should display an 'Invalid Dept' error message, ensuring that only valid department codes are accepted .

An admin can register a customer by filling either: only ID, name, and address; only ID and name; or all details. When not all data members are initialized through constructors, appropriate default values should be set for these uninitialized fields to maintain data integrity .

Handling null pointers is crucial to prevent runtime exceptions and ensure program stability. For 'empName', the 'setEmpName()' method should include a null check, and if null is encountered, an appropriate error message should be displayed to notify about the issue .

Constructor overloading allows for different initialization paths when registering customers. By providing multiple constructors with varying parameters, the system can accommodate different amounts of customer information, such as ID only, ID and name, or ID, name, and address, enhancing flexibility in customer data handling .

The program should consider tracking each book's title, price, year of publication, and author's name. Instances should be created for specific books like 'Robinson Crusoe' by Daniel Defoe, 'Heart of Darkness' by Joseph Conrad, and 'Beach Music' by Pat Conroy, with their respective details . The program should also ensure accurate data representation and retrieval functionalities for the bookstore's inventory management.

The menu-driven program should include functionalities to create student records, display student names sorted alphabetically by branch, and display student IDs in ascending order. These functionalities ensure efficient organization and retrieval of student data .

You might also like