This document outlines 7 Java programming assignments involving classes, objects, and constructors:
1. Create an Employee class with attributes like ID, name, department, salary, and designation. Include methods to input and display employee details including gross salary which is the sum of basic salary plus DA and HRA percentages.
2. Create a Book class with attributes like title, publisher, authors, price, and pages. Include methods to input book object data, display it, and compare two book objects.
3. Create a Time class with hour, minute, second attributes. Include methods to input and display time, and a method to add two time objects and display the sum.
4. Create a Rectangle
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
15 views
Java Assignment-6
This document outlines 7 Java programming assignments involving classes, objects, and constructors:
1. Create an Employee class with attributes like ID, name, department, salary, and designation. Include methods to input and display employee details including gross salary which is the sum of basic salary plus DA and HRA percentages.
2. Create a Book class with attributes like title, publisher, authors, price, and pages. Include methods to input book object data, display it, and compare two book objects.
3. Create a Time class with hour, minute, second attributes. Include methods to input and display time, and a method to add two time objects and display the sum.
4. Create a Rectangle
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3
Java Programming Assignment
(Class, Object and Constructor)
1. Create a class called Employee having data members emp_id, name, department, basic_salary and designation. Use methods input() and display() to get the data and view the details of an employee including gross salary. The gross salary of the employee is the sum of basic_salary along with DA and HRA. DA is 20% and HRA is 16% of the basic_salary 2. Write a program in Java to declare a class called Book with data members as title, publisher, authors, price and number_of_pages. Define member methods (as per your convenience) to input the data from user interface for the Book object and display it. Also you need to write a method to compare two Book objects and display whether they are the same books or different one. (Note: Use method which returns a boolean data type and also pass object as parameter to the method for comparing two book objects). 3. Define a class called Time with attributes hour, minute and second along with methods like get_time() and show_time() to input and display the time respectively. Also define a method add_time() which takes two time objects as input and returns a time object. Display the added time in terms of hour, minute and second using the same show_time(). 4. Create a class Rectangle with two attributes length and width, each of which is initialized to 0.There are methods to calculate perimeter and area of the rectangle. It has get() ad set() for both the attributes, however the set() should verify that the length and width are greater than 0 and less than 20. 5. Define a class Fruit having instance variable name, colour and taste. Use constructor to initialize the members if provided at the time of object creation as parameter otherwise the default name is banana, colour is yellow and taste is sweet. Define a separate class to create objects of Fruit class and display the attributes. 6. Declare a class Account having data members like account_number, name, address and balance. The data members need to be initialized using constructors and there are methods like deposit(), withdraw(), balance_enquiry() and summery_display(). You are required to prepare the class along with the required methods for the said purpose and write a menu driven Java program for the various operations on the account object. (Assume standard banking activities for various operations). 7. Write a menu driven program in java to perform the operations like add, subtract and multiply two complex numbers. Use constructor overloading to initialize the data members real and imaginary of the class Complex. (one default and another parameterized constructor). Also define and use the appropriate methods for usual activities.