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

Lab Experiments Java-1

Uploaded by

hostcb001
Copyright
© © All Rights Reserved
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Lab Experiments Java-1

Uploaded by

hostcb001
Copyright
© © All Rights Reserved
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Write simple Java pr

operators

decision makind and control


structures

arrays

nested for

scenario based questions

scenario based questions


Programs using Static, final
2 and this keyword,classes and
objects

Demonstrate the concepts of


3
inheritance

4 Programs illustr

Method overriding

Method overloading

Programs to use packages and


5
Interfaces in Java.
Implement exception
6 handling and creation of user
defined exception.

Implement program to
demonstrate multithreading
7
and inter thread
communication.

Write a program to perform


8
file operations.

Develop applications using


9
swing layouts
Write simple Java programs using operators, arrays and control

Perform Addition Operation Without Using Operator

Find the Prime numbers from 1 to n.

Write a java program to find whether the given matrix is identity matrix or not

You have been hired as a software developer by a finance company called MoneyMatters, Inc. They want to
enhance
Print the their existing financial management system to accommodate more precise calculations. Currently,
Pattern:
the
**** system only handles integers for monetary values, but they now wish to support decimal values as well.
***
Your
** task is to modify the existing code in the IntegerToDoubleConverter class to create a more versatile
converter
* that can handle both integer and double inputs. The updated converter should prompt the user for
input and detect whether the provided value is an integer or a double. Depending on the input type, it should
appropriately convert the value and display the original input and the converted value.
Input Format
The input consists of a single integer.
Output Format
The first line of the output displays the original integer.
The second
Alice, a mathline displays
teacher, the converted
is creating double. exercise to help her students practice multiplying all the odd
a programming
digits of a given integer. She wants to create a simple program that takes a positive integer input and finds the
Refer
productto of
theitssample output for the formatting specifications.
odd digits.
Constraints
1<=number<=99999
Help Alice to complete the program using the 'while' loop.
Sample
Input 1 Input
Format
20
The input consists of a single positive integer N.
Sample 1 Output
Output Format
Original
The outputInteger: 20 the product of odd digits in the given integer N.
displays
Converted
If Double:
no odd digits 20.0 in N, display "No odd digits found".
are found
Sample 2 Input
53
Refer to the sample output for formatting specifications.
Sample 2 Output
Constraints
Original Integer:the
In this scenario, 53 test cases fall under the following constraints:
Converted
1 ≤ N ≤ 106Double: 53.0
Sample Input Sample Output
732
21
Sample Input Sample Output
2468
No odd digits found
Sample Input Sample Output
467
7
Time Limit: - ms Memory Limit: - kb Code Size: - kb
Imagine you are building a text analysis tool. One of the tasks your program needs to perform is counting how
many times a specific character occurs in a given text. Input Format The first line contains the input string
containing printable ASCII characters (including spaces, letters, numbers, and special characters). The second
line contains a single character target to count in the string (including spaces, letters, numbers, and special
characters). Output Format The output consists of an integer representing the number of times the character
c appears in the string s. Constraints The input string input will have at most length 100. The character target
can be any printable ASCII character. Sample 1 Input Hello, how are you doing today? o Sample 1 Output 5
Sample 2 Input Abracadabra

Create a class named 'Rectangle' with two data members 'length' and 'breadth' and two
methods to print the area and perimeter of the rectangle respectively. Its constructor having
parameters for length and breadth is used to initialize length and breadth of the rectangle. Let
class 'Square' inherit the 'Rectangle' class with its constructor having a parameter for its side
(suppose s) calling the constructor of its parent class as 'super(s,s)'. Print the area and perimeter
of a rectangle and a square.

Programs illustrating overloading and overriding methods i

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

Create a Java program to demonstrate method overloading with method ambiguity and resolution using
casting

Write a Java programming to create a banking system with three classes - Bank, Account, SavingsAccount, and
CurrentAccount. The bank should have a list of accounts and methods for adding them. Accounts should be
an interface with methods to deposit, withdraw, calculate interest, and view balances. SavingsAccount and
CurrentAccount should implement the Account interface and have their own unique methods.
Write a program to validate the email address and display suitable exceptions if there is a mistake.

Create 3 custom exception classes as below.


1. DotException
2. AtTheRateException
3. DomainException

A typical email address should have a " . " character, and a "@" character, and also the domain name should
be valid. Valid domain names for practice are 'in', 'com', 'net', or 'biz'.

Display Invalid Dot usage, Invalid @ usage, or Invalid Domain message based on the email id.

Get the email address from the user, validate the email by checking the above-mentioned criteria, and print
the validity status of the input email address.
Input Format
The first line of input contains the email to be validated.
Output Format
The output prints a Valid email address or Invalid email address along with the suitable exception.

write a Java program to see how the synchronization technique can solve the bank problem. Two classes are
designed to simulate a bank system:

BankingThread class: Acting as an ATM machine, taking deposit or withdraw transaction requests from
customers, and asking the BankingMain class to perform the transactions.
BankingMain class: Acting as the control center, managing instances of the BankingThread class, and
performing transactions coming from each BankingThread instance.

Write a program to copy one file to another file.

Create a Application to store bio data of a student


erators, arrays and control statement

Perform Modulo Operation Without Using % Operator

Find Palindrome Numbers Between 10 and 1000 and Count


Them

Write a java program to find matrix multiplication.

Printare
You thetasked
Pattern: with creating a Java program called
*
Tickettypes that accepts a single-character input
**
representing a ticket type and outputs the corresponding
*** category or informs the user if the input is not
ticket
****
recognized. The program should be case-insensitive when
***
determining the ticket type.
**
Eminem
* program
The is a billiard
shouldplayer
recognizewhoand enjoys
handleplaying
the billiards
followingand
also likes solving mathematical
ticket types, regardless of case: puzzles. He notices that the
billiard
'e' or 'E'balls on the
for Early table
Bird are arranged in a grid, and he is
Ticket
curious
'd' or 'D'toforfind the sum
Discount of the numbers written on each ball.
Ticket
'v' or 'V' for VIP Ticket
Write a program
's' or 'S' for Standard to find the sum of all the numbers written
Ticket
on each
'c' or ballChildren's
'C' for in the grid.Ticket
Input Format should print "Invalid Ticket Type" if the input
The program
The
doesfirst
notlinematch of input
any ofconsists of an integer
the recognized ticketN,types.
representing
the number
Input Format of rows.
The
The second line consists
input consists of ancharacter
of a single integer M, representing
representing the
a ticket
number
type ('e',of 'E',columns.
'd', 'D', 'v', 'V', 's', 'S', 'c', or 'C').
The
Outputfollowing
Formatlines N lines consist of M space-separated
integers,
The output representing the numbers written
prints the corresponding on each ball.
ticket category or
Output Format
"Invalid Ticket Type" if the input does not match any
The output ticket
recognized prints type.
an integer representing the sum of all the
numbers
Constraints written on each ball.
The input is a single character.
Refer to the
The input sample represents
character output for the formatting
a specific ticketspecifications.
type (e.g., 'e'
Constraints
for Early Bird, 'd' for Discount, etc.).
1 ≤ M, N ≤ 10
Sample Input Sample Output
3
3
123
456
789
45
Sample Input Sample Output
3
2
11 2
12 3
13 4
45
projects.
Your task is to create a program that takes the dimensions of
a room (length and
width) as input and calculates the room's area using a
predefined Rectangle class.
Input Format
The input consists of two decimal numbers separated by
spaces: length (the length
You areroom)
of the implementing
and width. a Car Rental System program in Java.
The program
Output Format involves two classes: Vehicle and Car. The Car
class is a subclass
The output shouldofprint
the aVehicle
single class.
decimalEach car has its
number
maximum
representing speed, which
the area ofcan
the be set during the car's
room,
initialization.
rounded to two Thedecimal
Vehiclepoints.
class has an attribute maxSpeed,
which
Refer to is set
the to 120 by
sample default.
output forThe Car specifications.
format class extends the
Vehicle
Constraintsclass and has its attribute maxSpeed, which is set by
the
The length and width are positive real numbers. is to
user during the car's initialization. Your task
implement
Sample 1 Input the program, where the user provides the
maximum
5.0 4.0 speed of the car they want to rent. The program
then
Samplecreates a Car object with the given maximum speed,
1 Output
using
20.00 the super() keyword to call the default constructor of
the base2class
Sample InputVehicle. It then displays both the maximum
speed
10.2 7.8 from the base class Vehicle using super.maxSpeed and
the maximum
Sample 2 Output speed from the subclass Car using maxSpeed.
Input
79.56 format : The input consists of an integer. Output
g and overriding methods in Javaprints the maximum speed from the
format : The output
base class (Vehicle), followed by the maximum speed from
the subclass (Car). Refer to the sample output for formatting
specifications.
Write a Java programSamplethattest creates
cases : Input
a class1 hierarchy
: 12 Outputfor1 :
Maximum Speed
employees from Base
of a company. Theclass (Vehicle):
base 120 Maximum
class should be
Speed fromwith
Employee, Subclass (Car): Manager,
subclasses 12 Developer, and
Programmer. Each subclass should have properties such as
name, address, salary, and job title. Implement methods for
calculating bonuses, generating performance reports, and
managing projects.

Write a Java program to demonstrate method overloading


with primitive data types and their wrappers

Write a Java program to create an interface Shape with the


getArea() method. Create three classes Rectangle, Circle, and
Triangle that implement the Shape interface. Implement the
getArea() method for each of the three classes.
Write a program to read the Register Number and Mobile
Number of a student. Create a user-defined exception and
handle the following:

1. If the Register Number does not contain exactly 9


characters in the specified format (2 numbers followed by 3
characters followed by 4 numbers) or if the Mobile Number
does not contain exactly 10 characters, throw an
IllegalArgumentException.
2. If the Mobile Number contains any character other than
a digit, raise a NumberFormatException.
3. If the Register Number contains any character other
than digits and alphabets, throw a NoSuchElementException.
4. If they are valid, print the message "valid", otherwise
"invalid".

Write a Java program to create a producer-consumer


scenario using the wait() and notify() methods for thread
synchronization.

Write a program to Removing spaces from file content

Create a Application to search books in a Library baesd on


various parameters
Write a program to calculate the sum of the first and the
second last digit of a 5 digit.

Check if a Number is Perfect or Not

Write a program to remove duplicates elemens in an


array.

Anil is fascinated by the concept of perfect numbers. A


perfect number is a positive integer that is equal to the
sum
Printof itsPattern:
the proper divisors, excluding itself. For example,
28 is
* * * *a perfect number because its divisors (excluding
itself)
* are
* 1, 2, 4, 7, and 14, and their sum is 28.
* *
Anil
* * wants
* * to create a program that determines whether
a given positive integer is a perfect number or not. He
needs your help to design and implement this program.
Input Format
The input consists of a single positive integer, n, on a
single line.
Output Format
If the input number n is a perfect number, the program
should output "n is a perfect number."
If the input number n is not a perfect number, the
program should output "n is not a perfect number."

Refer to the sample output for formatting specifications.


Constraints
1 <= n <= 105
Sample 1 Input
50
Sample 1 Output
50 is not
Ashok a perfect
is given number
a string consisting of some words
Sample 2 Input
separated by spaces. He wants to return thelength of
28
the last word in the string. The word is a maximal
Sample 2 Output
substring consisting of non-space characters only.
28 is a perfect number
NumberConverter to
perform the conversions.
The source and destination bases are converted from
characters to integers based
on the following:
'B' (binary) should be converted to 2.
'D' (decimal) should be converted to 10.
'O' (octal) should be converted to 8.
'H' (hexadecimal) should be converted to 16.
Example:
The source base (sBase) is 'B,' which corresponds to
binary (base 2). The
destination base (dBase) is 'D,' which corresponds to
decimal (base 10). The input
number is "1101," which is a binary number. The result is
"13" in decimal.
Note :
● D for Decimal, B for Binary, O for Octal, and H for
Create a Products class in a shop.Caculate the purchase
Hexadecimal.
bill of a customer
● The input . will be a valid number in the source
number
number system.
● The input number will not exceed the representational
limits of the data type used.
● You do not need to handle negative numbers.
Input Format
The first line contains a single character (D, B, O, or H)
representing the source
number system
Write a Java program to create a class known as
"BankAccount" with methods called deposit() and
withdraw(). Create a subclass called SavingsAccount that
overrides the withdraw() method to prevent
withdrawals if the account balance falls below one
hundred.

Write a Java program to demonstrate method


overloading with methods that have different parameter
modifiers, including final and non-final

Write a Java program to create an interface Sortable


with a method sort() that sorts an array of integers in
ascending order. Create two classes BubbleSort and
SelectionSort that implement the Sortable interface and
provide their own implementations of the sort() method.
Create a class Student with attributes roll no, name, age,
and course. Initialize values through the parameterized
constructor.

If the age of a student is not between 15 and 21, then


generate the user-defined exception
"AgeNotWithinRangeException". If the name contains
numbers or special symbols, raise the exception
"NameNotValidException". Define the two exception
classes to display the message as shown in the sample
output.

Write a Java program that creates three threads and


ensures that each thread starts only after the previous
one has finished, using Thread.join().

Write a program to remove duplicate characters in a file.

Create a Application to book a trainticket based on


availability of seats.

You might also like