Ex.
No:01 The Quick Drive Distance Check
Aim:
Write a quick Java program to calculate and show the distance covered during this speedy drive
Algorithm:
Step 1:Start the process
Step 2: Prompt the user to input the speed in meters and the time spent driving in Seconds.
Step 3: Read the input values for speed and time from the user.
Step 4: Multiply the speed by the time to calculate the distance covered during the drive.
Step 5: Distance = speed * time
Step 6: Display the calculated distance covered during the drive.
Step 7: Stop the process
.
Ex.No:02 School Grading System
Aim:
Create a Java program that automates the grading process for a student's final exam score.
Algorithm:
Step1:Start the process
Step2 : Prompt the user to input the total score obtained by the student.
Step 3 :Read the total score entered by the user.
Step 4 :Pass the total score to a function calculateGrade() to determine the letter grade based on
the grading criteria.
Step 5 :Within the calculateGrade() function, check the total score against predefined ranges for
each grade (A, B, C, D, F).
Step 6 : Based on where the total score falls within these ranges, assign the corresponding letter
grade.
Step 7 : Display the calculated letter grade for the student.
Step 8:Stop the process
Ex.No:03 Geometric sum
Aim:
Write a Java program to calculate the geometric sum of n terms in the given series using
recursion & print that result up to 6 decimal places.
Algorithm:
Step 1: Start the process.
Step 2: Prompt the user to input the value of 'n', representing the number of terms in the geometric
series.
Step 3: Read the value of 'n' entered by the user.
Step 4:Calculate Geometric Sum Recursively
Step 5:Call the calculateGeometricSum(n) function with the input value of 'n'.
Step 6:Print the calculated geometric sum up to 6 decimal places using printf() formatting
specifier %.6f.
Step 7:Display the geometric sum of 'n' terms calculated from the given series.
Step 8:Stop the process.
Ex.No:04 Basics of Class and Object
Aim:
Create a class to represent an agent. Imagine yourself as the chief developer, and your task is
to design a basic class named Agent.
Algorithm:
Step 1:Start the process.
Step 2:Design a class named Agent with the following attributes: name (String), age (int),codename
Step 3:Implement a method named introduce() that prints a message introducing the agent,including
their name, age, and codename.
Step 4:Create an instance of the Agent class named topAgent in the main method.
Step 5:Utilize user input within the main method to set the attributes of topAgent (name, age,
codename, and isUndercover).
Step 6:Invoke the introduce() method on topAgent to introduce this top agent to the team.
Step 7:Stop the process.
Ex.No:05 Movie Catalog System
Aim:
Developing a Movie Catalog System, tasked with designing the Movie class. This class is
intended to represent individual movies within the system and should have attributes title and release
Year.
Algorithm:
Step 1:Start the process
Step 2:Represents the title of the movie.
Step 3:This represents the year the movie was released.
Step 4: Returns the title of the movie.
Step 5: Returns the release year of the movie.
Step 6: Sets the title of the movie.
Step 7: Sets the release year of the movie.
Step 8:Stop the process.
Ex.no :6 Constructor Overloading
Aim:
Write a Java program that demonstrates constructor overloading in a class named Book
Algorithm:
Step 1: start the process
Step 2 : Define the Book class with attributes title, author, and pageCount.
Step 3:Implement multiple constructors with different parameter lists.
Step 4:Inside each constructor, initialize the attributes accordingly.
Step 5:Demonstrate the use of constructor overloading by creating objects of the Book class using
different constructors.
Step 6: Stop the process
Ex.no 7: Area's of given geometric shapes by using Function Overloading
Aim:
Write Java program to calculate area of triangle, square & circle using function overloading.
Function parameter accept from user (Use function Overloading concepts and Inheritance)
Algorithm:
Step 1:Start the process
Step 2:Define a superclass Shape with an abstract method calculateArea().
Step 3:Define subclasses Triangle, Square, and Circle inheriting from the Shape class.
Step 4:Implement the calculateArea() method in each subclass to calculate the area of the respective
shape.
Step 5:Create overloaded methods to accept user input for the parameters required to calculate the
area of each shape.
Step 6:Use these overloaded methods to calculate the area of the triangle, square, and circle.
Step 7: Stop the process
Ex.no :8 Find prime numbers and check for palindromes
Aim:
Write a Java program that finds prime numbers and checks for palindromes in two separate lists of
N inputs . Use function overloading in super and sub-classes, following these instructions:
Algorithum:
Step 1:Start the process
Step 2:Create a superclass called NumberProcessor.
Step 3:Declare two overloaded methods processNumbers() to handle prime numbers and
palindromes separately.
Step 4:Implement a method in the superclass to check if a number is prime.
Step 5:This method should take an integer parameter and return true if the number is prime,
falseotherwise.
Step 6:Use a loop to check divisibility of the number by integers up to its square root.
Step 7:Stop the process
Ex.no :9 Student Grade Calculator - Single Inheritance
Aim:
Write a Java program with two classes, Student and GradeCalculator, to manage student
information and calculate the average grade for three subjects.
Algorithm:
Step 1: Start the process
Step 2: Create a class named Student with the following attribute
Step 3: A String variable name to store the student's name.An array, subjects, of integers to
storemarks for three subjects.
Step 4: Implement a method named inputStudentInfo() to take user input for the student's name and
marks for each of the three subjects.
Step 5: Create a class named GradeCalculator that extends Student.
Step 6: Include a float variable averageGrade to store the calculated average.
Step 7: Implement a method named calculateAverageGrade() that calculates and prints the average
grade for the student.
Step 8: Stop the process.
.
Ex.no:10 Addition and Multiplication using Inheritance.
Aim:
Creating a simple calculator application that performs addition and multiplication operations.
Algorithm:
Step 1: Start the process
Step 2: A base class Calculation with a constructor that takes two parameters.
Step 3: The two lines of the input are integers.
Step 4: The first line is the integer representing the result of the addition operation.
Step 5: Create a child class My_Calculation that inherits from the Calculation class.
Step 6:The child class, implement a method multiplication that returns the product of the two
parameters that are inherited from the base class.
Step 7: The second line is the integer representing the result of the multiplication operation.
Step 8: Stop the process.
Ex.no:11 Person's name and age - Single Inheritance
Aim:
Creating a simple calculator application that performs addition and multiplication
operations.
Algorithm:
Step 1:Start the process.
Step 2:Define a base class Calculation with a constructor that takes two parameters.
Step 3:Implement a method addition in the Calculation class.
Step 4:Create a child class My_Calculation that inherits from the Calculation class.
Step 5: Implement a method multiplication that returns the product of the two parameters
that are inherited from the base class.
Step 5:Stop the process
Ex.no:12 Music Player Application
Aim:
Could you guide him through the process of crafting this simple yet effective music player
application
Algorithm:
Step 1:Start the process.
Step 2:Define an interface named Playable with a method play() for playing audio.
Step 3:Implement two classes, MP3Player and WAVPlayer, that implement
the Playable interface.
Step 4:implement the play() method with appropriate audio play logic.
Step 5:Create a class named MusicPlayer with a method playAudio(Playable audio) that
plays any compatible audio object.
Step 6:Stop the process
Ex.no:13 Vehicle Fuel Efficiency
Aim:
Creating a simple concrete method named displayDetails() that displays
information about the vehicle, including its model and fuel efficiency.
Algorithm:
Step 1:Start the process
Step 2:Create an abstract class called Vehicle.
Step 3:Declare an abstract method of type double: calculateFuelEfficiency(). This method
will be implemented by subclasses.
Step 4:Implement a concrete method named displayDetails() that displays information
about the vehicle, including its model and fuel efficiency.
Step 5:create two subclasses called Car and Motorcycle that extend the Vehicle class
Step 6:Implement the calculateFuelEfficiency() method in the Car class
Step 7:Calculate and display the fuel efficiency in kilometers per liter (KPL).
Step 8:Stop the process
Ex.no:14 Payment method
Aim:
Create an interface PaymentMethod that defines the standard methods for processing
payments and displaying receipts. One of the payment methods you want to support is
credit card payments.
Algorithm:
Step 1: Start the process
Step 2:Create an interface named PaymentMethod with the following methods:
processPayment()
Step 3:Implement the PaymentMethod interface in a class
named CreditCardPayment.The CreditCardPayment class should have private attributes
for storing credit card number (String), expiration date (String), and payment amount
(double).
Step 4:Implement the processPayment() method to take user input for credit card details
(card number, expiration date, and payment amount).
Step 5:Implement the displayReceipt() method to display a receipt with the credit card
number, expiration date, and the amount paid.
Step 6:Stop the process.
Ex.no:15 Package and Inheritance
Aim:
Create a package pkg1, which contain a public class Pkg1Class, which have integer
variables of type private, default, public, protected each one for each.
Algorithm:
Step 1:Start the process.
Step 2:Write another package pkg2, which have a class Pkg2Class. Pkg2Class
Step 3:Extends the Pkg1Class of pkg1 package. Pkg2Class also have main function.
Step 4:Try to access all the variables declared in Pkg1Class in the main function
of Pkg2Class with the object of Pkg1Class and Pkg2Class
Step 5:Observe the result.
Step 6:Stop the process
Ex.No:16 Arithmetic operations using packages
Aim:
To create a user-defined package called "data" and implement Arithmetic operations
(addition, subtraction, multiplication, division) using packages in Java.
Algorithm:
Step 1:Start the process.
Step 2:Create a package named "data".
Step 3:Inside the "data" package, create a Java class named "Arithmetic".
Step 4:Implement methods for addition, subtraction, multiplication, and division within
the "Arithmetic" class.
Step 5:Import the "Arithmetic" class in the main program.
Step 6:Perform arithmetic operations using methods from the "Arithmetic" class.
Step 7:Stop the process.
Ex.No:17 Synchronization
Aim:
To implement the concept of synchronized methods in Java to find the sum of the first N
natural numbers concurrently using two threads.
Algorithm:
Step 1:Start the process.
Step 2:Define a class named "SumCalculator" with a synchronized method to calculate the
sum of the first N natural numbers.
Step 3:Create two threads, each responsible for calculating the sum of a specific range of
natural numbers.
Step 4:Instantiate objects of the "SumCalculator" class for each thread.
Step 5:Start both threads to run concurrently.
Step 6:Wait for both threads to complete their execution.
Step 7:Retrieve the calculated sums from both threads and display the results.
Step 8:Stop the process.
Ex.No:18 Multithreading
Aim:
To simulate a restaurant scenario with multiple chefs and waiters using multithreading in
Java. The simulation will allow the user to specify the number of chefs and waiters, where
each chef will randomly prepare an order for a random amount of time, and each waiter
will randomly deliver an order for a random amount of time. Messages will be printed
indicating which chef has finished preparing an order and which waiter has delivered an
order.
Algorithm:
Step 1:Start the process
Step 2:Define a class named "Chef" representing a chef in the restaurant. This class will
implement the Runnable interface.
Step 3:Inside the "Chef" class, implement the run() method to simulate preparing an order
for a random amount of time.
Step 4:Define a class named "Waiter" representing a waiter in the restaurant. This class
will also implement the Runnable interface.
Step 5:Inside the "Waiter" class, implement the run() method to simulate delivering an
order for a random amount of time.
Step 6:Prompt the user to enter the number of chefs and waiters.
Step 7:Create and start a thread for each chef and waiter.
Step 8:Each chef and waiter thread will execute their respective tasks concurrently.
Step 9:Stop the process
Ex.No:19 Handling exceptions - String to integer
Aim:
To develop a Java program that takes a string from the user, attempts to convert it
to an integer, displays twice the integer if successful, and handles a
NumberFormatException if the string is not a valid integer.
Algorithm:
Step 1:Start the process
Step 2:Prompt the user to enter a string.
Step 3:Use the Integer.parseInt() method to convert the user-input string to an integer.
Step 4:Calculate twice the integer value.
Step 5:Display the result.
Step 6:Stop the process
Ex.No:20 Customized Exception
Aim:
To develop a Java program that takes the age as input from the user, validates it, and
throws a custom exception called "InvalidAgeException" when the age is not within the
valid range of 0 to 150 years.
Algorithm:
Step 1:Start the process
Step 2:Define a custom exception class named "InvalidAgeException" that extends the
Java built-in "Exception" class.
Step 3:Implement a method to take user input for age.
Step 4:Validate the input age to ensure it falls within the range of 0 to 150 years.
If the age is not within the valid range, throw an "InvalidAgeException"
.
Step 5:Catch the "InvalidAgeException" and handle it appropriately by displaying an error
message.
Step 6:If the age is valid, proceed with the program execution.
Step 7:Stop the process
Ex.No:21 Customized Exception - Employee and Salary
Aim:
Write a Java program to manage Employee information using custom exceptions.
Algorithm:
Step 1: Start the process
Step 2: Create a custom exception class EE that extends Exception.
Step 3: Implement a method checkSal(double sal) that throws EE if the salary is
below 2000.
Step 4: Create an instance of Scanner to take user input.
Step 5: Call the checkSal(double sal) method of the Employee object to validate the
salary.
Step 6: Print the employee's name and salary after input and validation.
Step 7: Stop the process
Ex.No:22 Using collections with array list
Aim:
Write a Java program to enter an arraylist with n elements and show. Max Value,Min
Value,Sorted List.
Algorithm:
Step 1: Start the process.
Step 2: Initialize an empty ArrayList to store integers.
Step 3: Create a Scanner object to read input from the user.
Step 4: Use a loop to iterate n times:
a. Inside the loop, read an integer from the user and add it to the ArrayList.
Step 5: Find the greatest element in the list using the Collections.max() method and
display it.
Step 6: Find the smallest element in the list using the Collections.min() method and
display it.
Step 7:Stop the process.
Ex.No:23 Searching and Sorting using Packages and Array List Collections
Aim:
Write a Java program to searching and Sorting using Packages and Array List Collections.
Algorithm:
Step 1: start the program
Step 2: Prompt the user to enter the number of elements they want to input.
Step 3: Create an ArrayList to store the integers.
Step 4: Sort the ArrayList using a linear sort algorithm.
Display the sorted list of numbers.
Step 5: Read the element to search for from the user.
Step 6: Use linear search to find the element in the sorted list:
a. If the element is found, display a message indicating its presence.
b. If the element is not found, display a message indicating its absence.
Step 7: Stop the process
Ex.No:24 Intersection of two lists
Aim:
Write a Java program that utilizes collections to find the common elements intersection
between two lists of integers input by the user.
Algorithm :
Step 1: Start the program
Step 2: Create an ArrayList to store the elements of the first list.
Use a loop to input the elements into the ArrayList.
Step 3: Create another ArrayList to store the elements of the second list.
Use a loop to input the elements into the second ArrayList.
Step 4: Convert both ArrayLists to HashSet to remove duplicates and ease the intersection
operation.
Step 5: Use the retainAll() method to find the intersection of the two sets.
Store the result in one of the sets.
Step 6: Print the elements of the set containing the intersection.
Step 7: Stop the process
Ex.No:25 Understanding TreeSet
Aim:
Write a program to understand how to insert and delete elements in a TreeSet using the
methods add and remove.
Algorithm:
Step 1: start the program
Step 2: Create a TreeSet to store strings.
Step 3: Use a Scanner object to input names from the user.
Add the names to the TreeSet.
Step 4: Print the TreeSet containing the entered names.
Step 5: Input two names to remove from the TreeSet.
Step 6: Check if each name is present in the TreeSet.
If a name is found, remove it from the TreeSet.
Step 7: Print the TreeSet after removing the specified names.
Step 8: Stop the process
Ex.No: 26 Priority Queue using java.util.PriorityQueue class.
Aim:
Write a java program to implement Priority Queue using a min-heap using
java.util.PriorityQueue class.
Algorithm:
Step 1: Start the process
Step 2: Create a PriorityQueue to store integers.
Step 3: Create a loop to continuously prompt the user for operations. Display
options: Enqueue, Dequeue, Display, Exit.
Step 4: If the user chooses to enqueue:
Prompt the user to enter an integer element.
Add the entered element to the PriorityQueue using the add() method.
Step 5: If the user chooses to dequeue:
check if the PriorityQueue is not empty.
Step 6: If the user chooses to display: Print
the elements of the PriorityQueue.
Step 7:Stop the process
Ex.No:27 Search phone number using contact name using Hash Map
Aim:
Write a Java program to search phone number using contact name using Hash Map.
Algorithm:
Step 1: Start the process
Step 2: Create a HashMap to store contacts (name-phone number pairs).
Step 3: Initialize variables to store user input for contact name, phone number, and choice.
Step 4: Create a loop to continuously prompt the user for operations.
Display options: Add contact, Search contact, Quit.
Step 5: If the user chooses to add a contact:
Prompt the user to enter the contact name and phone number.
Step 6: If the user chooses to search for a contact:
Prompt the user to enter the contact name to search.
Step 7:If the user chooses to quit:
Terminate the program using System.exit(0).
Step 8:If the user enters an invalid choice, print a message indicating the invalid choice.
Step 9: Stop the process
Ex.No:28 Frequency of the word
Aim:
Write a Java program that takes a List of strings as input and prints the frequency
of each word using a Map.
Algorithm :
Step 1: Start the process
Step 2: Prompt the user to enter the number of strings
in the list. Read and store the number of strings.
Step 3: Create a list to store the strings.
Step 4: Create a HashMap to store word
frequencies. Iterate over the list of strings.
Step 5: For each word in the list:
Check if the word is already present in the
frequency map. If present, increment its
frequency count by 1.
If not present, add the word to the map with a frequency count of 1.
Step 6: Iterate over the entries of the
frequency map. For each entry, print the
word and its frequency
Step 7: Stop the process