0% found this document useful (0 votes)
3 views5 pages

Programming Practice

The document outlines various programming tasks in Java, including creating interfaces, implementing inheritance, and developing algorithms for string manipulation and array operations. It covers topics such as calculating interest for different account types, designing a transportation management system, and performing operations on arrays and strings. Additionally, it includes exercises on multilevel inheritance, constructor chaining, and calculating geometric properties.

Uploaded by

siddharthrwt001
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)
3 views5 pages

Programming Practice

The document outlines various programming tasks in Java, including creating interfaces, implementing inheritance, and developing algorithms for string manipulation and array operations. It covers topics such as calculating interest for different account types, designing a transportation management system, and performing operations on arrays and strings. Additionally, it includes exercises on multilevel inheritance, constructor chaining, and calculating geometric properties.

Uploaded by

siddharthrwt001
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

1.

Create an interface Interest that contains:

 An abstract method double calculateInterest()


 A method void displayDetails() to display principal, rate, time, and calculated interest

Create three classes:

 SavingsAccount
 FixedDeposit
 RecurringDeposit

Each class should:

 Implement the Interest interface


 Store required data members (principal, rate, time, etc.)
 Implement calculateInterest() using different formulas:

o Implement displayDetails() to show all inputs and computed interest

In the main class:


o Accept user input using Scanner
o Use a menu-driven program to select account type
o Store objects in an array of interface type (Interest[])
o Display all account details using runtime polymorphism

Additionally:
o Calculate and display the total interest earned across all accounts
o Show which account type gives the maximum interest
Programming Practice
1. Design a Smart Transportation Management System using inheritance.
Class Structure
Class: Vehicle (Base Class)
Data Members:
VehicleId, brand, speed
Methods:
 void start()
 void stop()
 double calculateFare(double distance)

Class: Bus (Derived from Vehicle)


Additional Data Members:
NumberOfSeats, farePerKm
Methods:
 Override calculateFare()

Class: Taxi (Derived from Vehicle)


Additional Data Members:
BaseFare, farePerKm
Methods:
 Override calculateFare()
Create a complete java program to Create objects of Bus and Taxi, Accept travel distance from
user, Calculate fare using overridden method
2. Write a Java program to remove duplicate characters from a string.
3. Write a Java program that prints the following number pattern for n = 5.
1
12
123
1234
12345
1234
123
12
1
4. Implement multilevel inheritance for banking operations.
Class Structure
Class: Account
AccountNumber, balance
Methods:
 deposit()
 withdraw()
Class: SavingsAccount extends Account
Additional Member:
 interestRate
Method:
 calculateInterest()

Class: PremiumSavings extends SavingsAccount


Additional Member:
 bonusInterest
Method:
 Override calculateInterest()

Create a complete java program to Deposit and withdraw money, Calculate interest for premium
accounts, Show multi-level inheritance behavior
5. Write a Java program to check whether a given string is a palindrome or not.
6. Write a Java program that prints all prime numbers between two given numbers using loops.
7. Move all Zeroes to the End of the Array
int [] arr = {1, 0, 2, 0, 3, 0, 4, 0};
Array after moving zeroes: [1, 2, 3, 4, 0, 0, 0, 0]
8. Write a Java program to create a class named LibraryMember with the following data
members:
(i) Member Name(ii) Address (iii) Membership ID (iv) Number of Books Borrowed
Use a constructor to initialize the member details and automatically generate a unique
Membership ID starting from 5001.
Include methods to:
1. Display member details. 2. Borrow a book (increase count).
2. Return a book (decrease count). 4. Update the address of the member.
After creating the class:
 Enter details of n members (n entered by the user).
 Display details of any member.
 Perform borrow, return, and address update operations, and show the updated details.
9. Write a Java program to create a class known as Person with methods called getFirstName() and
getLastName(). Create a subclass called Employee that adds a new method named
getEmployeeId() and overrides the getLastName() method to include the employee's job title.
10. Write a Java program to create an array of N numbers and display the output array where:
output[i] = product of all elements except arr[i]
InputArray = [1,2,3,4] OutputArray = [24,12,8,6]
Note Array length and Array elements should be entered from user.
11. Write a Java program to remove duplicate characters from a string.
12. Create a Java program to implement Multi-Level Inheritance using the following class definitions
Class Person: Data Members – name, age
 Methods to input and display
Class Staff (inherits Person): Data Member- staffId, salary
 Methods to input and display
Doctor (inherits Staff): Data Members – specialization, consultationFee
 Methods to input and display
Patient (inherits Person): Data Members – patientId, disease, treatmentCost
 Methods to input and display
Create and implement all necessary methods to calculate the billing cost and display all values
including doctor’s information.
13. Write a Java program to create an array of N numbers and display the reverse of an array without
using another array:
Input Array: 1 2 3 4 5 Output Array: 5 4 3 2 1
Note: Array length and Array elements should be entered from user.
14. Write a Java program to check whether a given string is a palindrome or not.
15. Create a java program to implement Multi-Level Inheritance using following class definitions
Class Person: Data Members – name, age
 Create a parameterized constructor
 displayPerson()
Class Student (inherits Person) Data Member- rollno, course
 Create a parameterized constructor, use constructor chaining
 displayStudent()
Class GraduateStudent (inherits Student) Data Members – specialization, research topic
 Create a parameterized constructor using constructor chaining
 displayStudent()
Create and implement all necessary methods to complete the program including main method.
16. Write a Java program to demonstrate constructor chaining.
Create a class Person with three constructors:
a default constructor,
a constructor with one parameter (name),
a constructor with two parameters (name and age).
Create an object in the main method to show constructor chaining.
17. Write a Java program to calculate the perimeter of a rectangle, a square, and a circle.
Create an abstract class Shape with three abstract methods:
rectanglePerimeter() taking two parameters (length and breadth),
squarePerimeter() taking one parameter (side),
circlePerimeter() taking one parameter (radius).
Now create another class Perimeter that extends the Shape class and implements all three
methods:
rectanglePerimeter() to print the perimeter of a rectangle,
squarePerimeter() to print the perimeter of a square,
circlePerimeter() to print the perimeter of a circle.
Finally, create an object of class Perimeter in the main method and call all three methods to
display the results.
18. The problem to rearrange positive and negative numbers in an array. Method: This approach
moves all
elements of the array: negative numbers to the beginning and positive numbers to the end but
changes the order of appearance of the elements of the array.
Test case: • Input: 1 -1 2 -2 3 -3 • Output: -1 -2 -3 1 3 2

You might also like