Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Core Java Programming Lab Assignments: Introduction To Java (Day 1,2)

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

Core Java Programming Lab Assignments

Introduction to Java(Day 1,2)

1. Write any ten features of java


2. What is Unicode and Byte Code?
3. How java is platform independent?
4. What is JDK and JRE? Differentiate?
5. What is the task of Class Loader, Verifier, JIT Compiler in JRE.
6. Write/compile/execute Hello World program in Java

Java Data types, Operators and IF - ELSE (Day 3,4)

7. Program to find area and circumference of circle


8. Program to calculate sum of 5 subjects & find percentage.
9. Program to find the simple interest.
10. Write a program which accepts days(eg. 670 days) as integer and display total number
of years, months and days in it.
11. Program to convert temperature from Fahrenheit to Celsius as C= 5*(f-32)/9
12. Program to swap two no’s without using third variable.
13. Find the result of following (accept values for variables used in right side of
expression)
a. y=x2+3x-7 (print value of Z)
b. y=x++ + ++x (print value of x and y)
c. z= x++ - --y - --x + x++ (print value of x ,y and z)
d. z = x && y || !(x||y) (print value of Z)
14. Program to reverse a given number.
15. In a company an employee is paid as under:
If his basic salary is less than Rs. 1500, then HRA = 10% of basic salary
and DA = 90% of basic salary.
If his salary is either equal to or above Rs. 1500, then HRA = Rs. 500
and DA = 98% of basic salary.
If the employee's salary is input by the user write a program to find his gross salary.
GS=Basic+DA+HRA

16. Program to find greatest in 3 numbers.


17. Program to check that entered year is leap year or not.
18. Accept person age(int), gender(int 1 for male and 0 for female), then check whether
person is eligible for marriage or not.

Loops and arrays (Day 5, 6)


19. Program to print a table of any number.
20. Program to reverse a given number
21. Program to check whether number is prime or not
22. Calculate series : 12+22+32+42+.........+n2
23. Calculate sum of Lucas series (up to 10 terms) :

1, 2, 3, 6, 11, 20 ,........

24. Print all prime numbers between two given numbers;


25. Program to show sum and average of 10 element array. Accept array elements from
user.
26. Sort a ten element array in descending order.
27. Create a array of 17 elements in 5 rows. And calculate sum of all elements.
28. Program to find multiplication of two 3X3 matrices.
29. Program to print transpose of a matrix.

Object Oriented Programming , Classes, Objects ,Methods, Constructor (Day 7, 8,9)

30. Create a class to calculate Area of circle with one data member to store the radius and
another to store area value.
Create method members
1. init - to input radius from user
2. calc - to calculate area
3. display- to display area

31. Create a class MathOperation with two data member X and Y to store the operand and
third data member R to store result of operation.
Create method members
● init - to input X and Y from user
● add - to add X and Y and store in R
● multiply - to multiply X and Y and store in R
● power - to calculate X Y and store in R
● display- to display Result R

32. Create a class MathOperation containing method ‘multiply’ to calculate multiplication


of following arguments.
a. two integers
b. three float
c. all elements of array
d. one double and one integer
33. Create a class Person with properties (name and age) with following features.
a. Default age of person should be 18;
b. A person object can be initialized with name and age;
c. Method to display name and age of person
34. Create and use copy constructor for above problem.

35. Create a class Employee with(empNo ,salary and totalSalary) ) with following features.
a. Only parameterized constructor;
b. totalSalary always represent total of all the salaries of all employees created.
c. empNo should be auto incremented.
d. display total employees and totalSalary using class method.

36. Create class Product (pid, price, quantity) with parameterized constructor.

Create a main function in different class (say XYZ) and perform following task:
a. Accept five product information from user and store in an array
b. Find Pid of product with highest price.
c. Create method (with array of product’s object as argument) in XYZ class to
calculate and return total amount spent on all products. (amount spent on
single product=price of product * quantity of product)
37. Make list of Students having name, roll no., age, score. Write a program to accept 10
students record and arrange the Students based on the score group
[0-50],[50-65],[65-80],[80-100].

38. Create class Tile to store the edge length of a square tile , and create another class
Floor to store length and width of a rectangular floor.
Add method totalTiles(Tile t) in Floor class with Tile as argument to calculate the whole
number of tiles needed to cover the floor completely.

Inheritance , Runtime Polymorphism, instance of (Day 10,11)

39. What are the types of inheritance supported in java.


40. Create class OneBHK with instance variable roomArea , hallArea and price
a. Create default and parameterized constructor;
b. Method show(): to print OneBHK data member information;

Create another class TwoBHK which has all the properties and behaviour of OneBHK
and a new instance variable room2Area.

a. Create default and parameterized constructor;


b. Method show(): to print all data member information;

Write main function in another class(Say XYZ) and store three TwoBHK flat’s
information and print information using show method. Also print total amount of all
flats.

41. Create three classes  
Faculty (facultyid, salary) 
FullTimeFaculty (basic, allowance) inherits class Faculty 
PartTimeFaculty (hour, rate) inherits class Faculty 
 
Create  a  method  for  accepting  input  in  FullTimeFaculty  and 
PartTimeFaculty,  but  salary  should  not  be  accepted.  Salary  is 
calculated on the basis of  (basic+allowance) for FullTimeFaculty and 
(hour*rate) for PartTimeFaculty. Also create method in above classes to 
display faculty data. 
 
Create another class(say XYZ) for main method and store  
2 fulltime 
and 2 parttime faculty information. Also print their details. 
 

42. Create a class Student with two members : rollno and percentage.

Create default and parameterized constructors. Create method show() to display


information.
Create another class CollegeStudent inherits Student class. Add a new member
semester to it. Create default and parameterized constructors. Also override show() method.

Create another class SchoolStudent inherits Student class. Add a new member
classname(eg 12th ,10th etc.) to it. Create default and parameterized constructors. Also
override show() method.

Create a class(say XYZ) with main method that carries out the operation of the project :
-- has array to store objects of any class(Student or CollegeStudent, SchoolStudent)
--create two CollegeStudent and three SchoolStudent record objects and store them
inside the array
-- display all record from the array
-- search record on the basic of rollno and check given rollno is of SchoolStudent or of
CollegeStudent.
--count how many students are having A grade, if for A grade percentage >75

Interface & Abstract class, toString and equals (Day 12,13)

 
43.  What is abstract class?. What is interface? Differentiate 
abstract class and interface;

44. Create an Abstract class Processor with int member variable data and method
showData to display data value. Create abstract method process() to define processing
of member data.
a. Create a class Factorial using abstract class Processor to calculate and print
factorial of a number by overriding the process method.
b. Create a class Circle using abstract class Processor to calculate and print area
of a circle by overriding the process method

Ask user to enter choice (factorial or circle area). Also ask data to work upon; Use
Processor class reference to achieve this mechanism

45. Create Interface Taxable with members salesTax=7% and incomeTax=10.5%. create
abstract method calcTax().
a. Create class Employee(empId,name,salary) and implement Taxable to calculate
incomeTax on yearly salary.
b. Create class Product(pid,price,quantity) and implement Taxable to calculate
salesTax on unit price of product.
c. Create class for main method(Say XYZ), accept employee information and a
product information from user and print income tax and sales tax respectively.

46. Explain the importance of toString() and equals() method of the Object class and
override them on class Employee(empId,name,salary).
a. Create class for main method(say XYZ),and accept five employees information
and store in an array. Also ensure if entered empId already exist or not (use
equals method).
b. Display all employee info using toString method;

47. Create a program that helps banks to maintain records. It should have
following facilities.
o Anybody can create current or saving account with following initial information:
account number, name, balance, and branch.
o display account detail for a particular accounts.
o display total money deposited in bank.
o allow deposit and withdrawal in an account .
o for saving account opening balance and minimum balance must be 5000.
o for current account opening balance and minimum balance must be 1000.
o can not withdraw the amount from the account that makes balance less than
the minimum balance. 

Packages, Jar file, String and Wrapper classes (Day 14, 15,16,17,18)

48. Create a following class/package structure in your application. Filled squares are
packages and empty circles are classes.
▪ campus.data
o Person (name, age, address)
▪ campus.academics
o Student(rollno, branch, semester) inherits Person
o Faculty(facultyId, name, salary, branch) inherits Person
▪ campus
o CampusApp- this class contains main method to accept 5 Faculty
information and print total of salaries of all faculties.

49. Add following package to above structure


▪ campus.accounts
o Fees(Student, amount, paymentDate)
▪ campus -
o CampusApp- this class contains main method to accept 4 Students
information with their fees for second semester and print total fees
collected from all 4 students.

Take your assumptions regarding subject, branch and student data. Create this
application as a runnable jar file.

50. Input name of a person and count how many vowels it contains. Use String class
functions.
51. Input data exactly in the following format, and print sum of all integer values.
“67, 89, 23, 67, 12, 55, 66”. (Hint use String class split method and Integer class
parseInt method)

52. Store name of weekdays in an array (starting from “Sunday” at 0 index). Ask day
position from user and print day name. Handle array index out of bound exception and
give proper message if user enter day index outside range (0-6).

53. Create a class Voter(voterId, name, age) with parameterized constructor. The
parameterized constructor should throw a checked exception if age is less than 18. The
message of exception is “invalid age for voter ”

54. Create Interface StudentFee and declare following method.


getFee() throws InvalidFeeException. This method ask fees from user and throws
exception if user enters invalid or negative fees
Create class Student with members (name, fees) and implement the StudentFee
Interface.
AWT and SWING(Day 19-23)

55. Design a AWT/SWING frame as shown below in which when user clicks on button the
number of times user click should be displayed on label.

56. Design a Frame base application as shown below

57. Design following AWT/SWING frame base application

58. Design an AWT/SWING frame as shown below. Implement KeyListener on frame and
when user types in textfield the text should be displayed in text area.
59. Design an AWT/SWING frame as shown below. Implement MouseListener on frame
and when user clicks on frame the position of clicks i.e. (x and y axis) and number of
clicks should appear in text field.

60. Design a SWING frame as shown below. The JFrame should have border layout with a
button at the bottom and two panels. First panel should contain a JComboBox with list
of fruits and second panel should contain a Jlist with list of vegetables. As user clicks on
button , view should toggle.
61. Design an AWT frame as shown below. Implement KeyListener on both the text fields.
Both the text field should not allow the BACKSPACE and DELETE working in the
textfield.

Note: - Use evt.VK_BACK_SPACE and evt.VK_DELETE constants.

62. Design an Applet or JFrame as shown below. Twelve buttons and two label. When
user clicks on digit button the number should display on Number label and when user
press + button the Number should get added to Total. Clear button should make both
the label 0.

63. Design an applet as shown below. Applet consists of ovals. When user clicks anywhere
in the applet the entire circle should move.
Multi Threading (Day 24,25,26)

64. Create a Thread class to print following star(*) pattern on screen with delay of 1
second between each * print. Number of lines in the pattern should be passed to the
constructor of Thread class.
* ****
****
***
**
*
Use this class in main method and ask user to enter number of lines to print.

65. Design a Swing frame in which a label with your name moves from left to right corner
of frame repeatedly.

66. Create a class that checks whether a given number is prime or not using Runnable
interface

67. Develop a stop watch as shown below.

Java IO (Day 27,28)

68. Write a program to count how many times character ‘t’ occurs in a file.
69. Write a program to count no of words in a text file and average word size.
70. Write a program to count number of bytes in a image file(jpeg/png/gif). Also find
how much time it will take to upload the file on server if internet speed is 256 bps(bits
per second).
71. Write a program to store your shopping details in a binary file(shopping.dat) with
information itemName, price, quantity. (Use ObjectOutputStream to store Item class
object ).
72. Write a program to read data from shopping.dat file creted in above problem and find
total money spent on all shopping items. . (Use ObjectInputStream to read Item class
object ).

You might also like