Core Java Programming Lab Assignments: Introduction To Java (Day 1,2)
Core Java Programming Lab Assignments: Introduction To Java (Day 1,2)
Core Java Programming Lab Assignments: Introduction To Java (Day 1,2)
1, 2, 3, 6, 11, 20 ,........
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
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.
Create another class TwoBHK which has all the properties and behaviour of OneBHK
and a new instance variable room2Area.
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 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
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.
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 ”
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.
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.
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
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 ).