0% found this document useful (0 votes)
18 views2 pages

Assignent 2

The document outlines a series of programming assignments in Java, covering topics such as class creation, method implementation, constructors, inheritance, and interfaces. Each assignment requires the creation of specific classes and methods to perform various tasks, such as displaying information, performing calculations, and implementing object-oriented principles. The deadline for the assignments is set for January 31, 2082.

Uploaded by

punitmeme
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

Assignent 2

The document outlines a series of programming assignments in Java, covering topics such as class creation, method implementation, constructors, inheritance, and interfaces. Each assignment requires the creation of specific classes and methods to perform various tasks, such as displaying information, performing calculations, and implementing object-oriented principles. The deadline for the assignments is set for January 31, 2082.

Uploaded by

punitmeme
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Assignment 2

Deadline: 2082-01-31
1. Create a class named Hello that has a method named sayHi and sayHello that displays Hi
and Hello respectively. Create a class that has main method and call those method from
here.
2. Create a class named Calculator that has for method to add, subtract, multiply and divide.
All these methods must return result. User must be able to enter two integer data and an
operator. The function must be called as per operator and result must be displayed
accordingly.
3. Create a class named Student in Java that has three variables, integer variable rollNumber,
String variable name and String variable faculty. Assign the value of roll number as 20,
that of name as “Ram Bahadur” and faculty as “BCA” creating object of Student. Also
display the assigned value.
4. Write a program that would print the information (name, year of joining, address) of three
employees by creating a class named 'Employee'. All the fields must be private. The output
should be as follows:
Name Year of joining Address
Ram 2056 Kathmandu
Shyam 2062 Biratnagar
Jeevan 2065 Pokhara
Use getters and setters to initialize and retrieve values.
5. Use the concept of constructor to initialize objects of question number 3. Create a default
constructor to initialize the information of employee Ram. For other two create
parameterized constructor.
6. Create a class named person that has private data fields name, address and age. Read the
number of objects that user want to create. Create that number of objects of this class and
use constructors to initialize those objects. Finally display the details of the youngest
person.
7. Create a class that has a method named area that calculates and prints the area of circle,
area of rectangle (with integer value of length and breadth), area of rectangle (with double
value of length and breadth) illustrating the concept method overloading.
8. Create a class named Employee that has private data fields id, name and salary. This class
also has a method called display that displays the details of these fields. Create three child
classes Teacher, Accountant and Coordinator. The class Teacher has a method teach,
Accountant has a method calculate and coordinator has method organize to display their
work/duties. Illustrate the concept of Inheritance in this scenario.
9. Write a Java program to create a class called Employee with methods called work() and
getSalary(). Create a subclass called HRManager that overrides the work() method and
adds a new method called addEmployee().
10. Write a Java program to create an abstract class Shape with abstract methods
calculateArea() and calculatePerimeter(). Create subclasses Circle and Triangle that extend
the Shape class and implement the respective methods to calculate the area and perimeter
of each shape.
11. Create an interface named NumberInterface that has two abstract methods displaySmallest
and displayLargest. Create implementations of the function that displays the smallest
element and largest elements of the array respectively.
12. Create an interface that has two abstract methods checkPrime() and checkArmstrong()
where both the methods receive integer numbers and must return String message after
checking for prime and Armstrong respectively. Disply message accordingly.
13. Create an interface named Shape that has method draw. Create three concrete classes
Circle, Rectangle and Square that implements the Shape interface. In the main class, take
input from user where user is allowed to give string input i.e. circle to draw circle, rectangle
to draw rectangle and square to draw square. As per the user’s input, specific methods must
be called.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy