Java Practicle List-1
Java Practicle List-1
"
2. Write a Java Program to perform Arithmetic Operations such as +,-,/,\* on 2 entered Numbers.
3. Write a Java Program to find the Greatest Number of the 3 entered Numbers.
4. Write a Java Program to find the Lowest Number of the 3 entered Numbers.
5. Write a Java Program to check whether the entered Number is Odd or Even.
7. Write a Java Program to convert Temperature from Celsius to Fahrenheit or Vice Versa.
9. Write a Java program that reads two floating-point numbers and tests whether they are the same.
10. 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.
11. Write a Java program that takes a year from the user and prints whether it is a leap year or not.
13. Write a Java program to display the multiplication table of a given integer.
14. Write a program in Java to make such a pattern like a right angle triangle with a number which
repeats a number in a row.
The pattern is as follows :
1
22
333
4444
15. Write a Java program to make such a pattern like a right angle triangle with the number increased
by 1.
The pattern like :
1
23
456
7 8 9 10
16. Write a java program to add two numbers using class and object.
17. Write a Java program to create class Student. The class should have attributes student ID, student
name, marks for 3 subjects and the member functions are setdata() and displaydata(). Calculate the
average marks for student.
18. Create a class Person with attributes name and age. Derive a class Employee from Person with
additional attributes employeeId and salary. Create objects of both classes and demonstrate how
inheritance works in accessing the attributes of the base class.
19. Design a class hierarchy for a shape. Create a base class Shape with methods area() and perimeter().
Derive classes Circle, Rectangle, and Triangle from Shape. Implement the necessary methods in each
derived class. Create objects of each class and calculate the area and perimeter for each.
20. Develop a simple online shopping system. Create a base class Product with attributes productId,
productName, and price. Derive classes Electronics, Clothing, and Books from Product. Add specific
attributes for each product type. Create objects for each class and demonstrate polymorphism by
displaying product details.
21. Write a Java program to create a base class BankAccount with methods deposit() and withdraw().
Create two subclasses SavingsAccount and CheckingAccount. Override the withdraw() method in each
subclass to impose different withdrawal limits and fees.