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

External Practical_BCSC0186 Java Programming Lab Even Sem. 2024-25

The document outlines various programming tasks in Java, including product price analysis, multilevel inheritance, and working with packages. It provides specific requirements for programs such as calculating average prices, creating classes for banking operations, and analyzing strings and temperature data. Additionally, it discusses exception handling with nested try-catch blocks and includes scenarios for testing understanding of exception hierarchy.

Uploaded by

3919singhadarsh
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)
3 views

External Practical_BCSC0186 Java Programming Lab Even Sem. 2024-25

The document outlines various programming tasks in Java, including product price analysis, multilevel inheritance, and working with packages. It provides specific requirements for programs such as calculating average prices, creating classes for banking operations, and analyzing strings and temperature data. Additionally, it discusses exception handling with nested try-catch blocks and includes scenarios for testing understanding of exception hierarchy.

Uploaded by

3919singhadarsh
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/ 1

University Roll No: University Roll No:

Q1: Product Price Analysis: A store wants to analyze the prices of `n` products. Q1. What is the difference between == and .equals() in Java? Explain with an example
Write a Java program that: involving strings.
- Takes `n` as input (number of products).
- Uses an array to store the prices of `n` products. Q2. Multilevel Inheritance – Person → Student → GraduateStudent
- Calculates and displays the following: The average price. Create a base class Person with:
Example Input: Variable: name
Number of products: 8 Method: displayName()
Enter prices: 120 150 200 180 250 300 100 220 Extend Person in a class Student with:
Example Output: Variable: rollNo
Average Price: 190.0 Method: displayRollNo()
Extend Student in a class GraduateStudent with:
Q2: Working with Packages in Java Variable: degree
Create a package named bankPackage that contains two classes: Method: displayDegree()
1. Account: Methods: deposit(double amount),
withdraw(double amount),displayBalance() Task:
2. Loan: Methods: calculateInterest(double principal, In a main class TestPerson, create an object of GraduateStudent, assign values, and call all
double rate, int years),calculateEMI(double three display methods.
principal, double rate, int years)
Now, create another class called TestBank (outside the package):
 Import the package.
 Create objects of Account and Loan.
 Call the methods using test values.
 Display the account balance and loan details.

University Roll No: University Roll No:


Q1. Write a Java program to check if a given string is a palindrome using string Q1. You are asked to analyze temperatures recorded over n days and find the highest, lowest
methods. Explain how you approach the logic. temperature. How would you design and write this program using arrays?

Q2. Nested Try-Catch Blocks Q2. Exception Hierarchy and Catch Execution
Analyze the following code and explain the output for each of the given scenarios: Analyze the following code and explain the output for each of the given scenarios:
try { try {
System.out.println("Outer Try"); System.out.println("Start of Try");
try { Statement-A;
System.out.println("Inner Try"); Statement-B;
Statement-1; Statement-C;
} catch (ArithmeticException e) { } catch (NullPointerException e) {
System.out.println("Inner Catch: AE"); System.out.println("Caught NPE");
} } catch (RuntimeException e) {
} catch (Exception e) { System.out.println("Caught RuntimeException");
System.out.println("Outer Catch: Exception"); } catch (Exception e) {
} finally { System.out.println("Caught General Exception");
System.out.println("Outer Finally"); } finally {
} System.out.println("Finally Block Executed");
System.out.println("End"); }
Scenarios: System.out.println("End of Code");
(i) If Statement-1 throws ArithmeticException, which catch block handles it? Scenarios:
(iii) What happens if there’s no exception? (i) If Statement-B throws a NullPointerException, which catch block will be executed?
(ii) If Statement-C throws an IllegalArgumentException, what will be the output?

You might also like