Java Assignment1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

SNS COLLEGE OF TECHNOLOGY

(An Autonomous Institution)


Approved by AICTE, New Delhi, Affiliated to Anna University, Chennai
Accredited by NAAC-UGC with ‘A++’ Grade (Cycle III) &
Accredited by NBA (B.E - CSE, EEE, ECE, Mech&B.Tech.IT)
COIMBATORE-641 035, TAMIL NADU

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

Faculty Name : Dr.V.Savitha, ASP/ CSE Academic Year : 2024-2025 (Odd)


Year & Branch : II CSE C Semester : III
Course : 23CSB201-Object Oriented Programming

Assignment

S.No Question CO Bloom’ Date of


s Level Submissio
n
1. A positive integer with digits p, q, r, s…, is known as an
Armstrong number of order n if the following condition is
fulfilled.
370 = 3*3*3 + 7*7*7 + 0
= 27 + 343 + 0
= 370
Therefore, 370 is an Armstrong number.
Write a Java program to check whether the given number is
Armstrong number or not
2. Write a Java program to calculate the sum of elements in each
row and each column of the given matrix.
3. An autobiographical number is a number (N) such that the
first digit of N counts how many zeroes are presented in N, the
second digit counts how many ones are presented in N, the
third digit counts how many twos are presented in N, and so on.
Autobiographical Number Example
Suppose, we want to check the number 21200 is an
autobiographical number or not.

First, find the sum of its digits (2+1+2+0+0) i.e. 5, and counts
the number of digits of the given number i.e. 5. We observe
that both are equal. Hence, the number 21200 is an
autobiographical number.
Write a Java program to check whether the given input number
is an autobiographical number or not
4. Write a Java Program to Swap Two Numbers Using Bitwise
Operator

5. Write a Java program to find the duplicate characters in a string

6. Write a Java program that reads two floating-point numbers


and tests whether they are the same up to three decimal places.

Test Data
Input floating-point number: 25.586
Input floating-point another number: 25.589
Expected Output :
They are different

7. Write a Java program that requires the user to enter a single


character from the alphabet. Print Vowel or Consonant,
depending on user input. If the user input is not a letter
(between a and z or A and Z), or is a string of length > 1, print
an error message.
Test Data
Input an alphabet: p
Expected Output :
Input letter is Consonant

8. Implement the following concept using classes and objects and


print the marklist for 20 students. In Compute() method
calculate the total and print the grade of the students

Class : Student

Data members:
• Name
• Register No
• Department
• 5 marks
Methods:
• Readdata()
• Compute()
• Printgrade()
9.
The account class is the base class, and it has three private member
variables: name, accno, and atype. It contains two member
functions: getAccountDetails() to get the account details from the
user and displayDetails() to display the account details.

The current_account class and saving_account class both inherit from


the account class. They have their own private member
variables: balance and sav_balance, respectively, and their own
member
functions: c_deposit(),c_withdraw(),c_display(),s_deposit(),s_withdr
aw(), and s_display() for performing deposit, withdrawal, and
balance checking operations for the current account and saving
account.

The program prompts the user to enter their choice of operation to be


performed on the account, and then calls the corresponding member
function of the respective account object based on the user input.
Finally, the program exits after thanking the user for banking with
them.

10. Overloading Constructors with Different Data Types


Write a Java program to create a class called Point with
instance variables x and y. Implement overloaded constructors:

• One constructor takes int parameters.


• Another constructor takes double parameters.
• Print the values of the variables for each constructor
• Calculate the distance between two points
11. 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 and deposit() method to alert
when the deposit amount exceeds 5lakhs.

12. Write a Java program to implement the concept of method


overloading for finding sum of different numbers

• sum of 2 integer numbers


• sum of 3 integer numbers
• sum of 2 floating point numbers
• sum of 1 floating point and 1 integer

13. Write a Java program to implement the concept of method


overriding in finding the area and perimeter of different shapes
as follows

Base class – Shape

Method – area(), perimeter()

Derived class – Rectangle, Circle, Triangle

14. i) Write a Java program that reads a list of integers from the
user and throws an exception if any numbers are duplicates

ii) Write a Java program that generates an exception when a


number is divided by zero

15. Explain in detail on the life cycle of thread with neat sketch
i) Write a Java program to create and start multiple
threads that increment a shared counter variable
concurrently.

16. Write a program in Java to Copy Content of One File to


Another File

Write a Java program to write content into file using


FileOutputStream and read content using FileInputStream

You might also like