Lab Experiments Java-1
Lab Experiments Java-1
operators
arrays
nested for
4 Programs illustr
Method overriding
Method overloading
Implement program to
demonstrate multithreading
7
and inter thread
communication.
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.
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.
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.
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.