oopj_practical__2_
oopj_practical__2_
EXAM
List of Program
(Aim: To implement fundamental concept of JAVA)
1. Write a Java Program that displays “Hello World”.
2. Write a Java Program that will display Factorial of the given number (number
given by command prompt).
3. Write a Java Program that will display 25 Prime nos.
4. Write a Java Program that will accept command-line arguments and display the
same.
5. Write an application that creates a two dimension array with int values. The first,
second and third elements should be arrays with one, two and three numbers
respectively. Display the length of each dimension.
6. Write a program to convert rupees to dollar. 60 rupees=1 dollar.
7. Write a program that calculate percentage marks of the student if marks of
6 subjects are given.
8. Write a program to enter two numbers and perform mathematical
operations on them.
Define main to instantiate an array for objects of class student to process data
of n students to be given as command line arguments.
7. Design a class named Fan to represent a fan. The class contains:
Three constants named SLOW, MEDIUM and FAST with values 1,2 and 3 to
denote the fan speed.
An int data field named speed that specifies the speed of the fan (default
SLOW).
A boolean data field named f_on that specifies whether the fan is on(default
false).
A double data field named radius that specifies the radius of the fan (default
4).
A data field named color that specifies the color of the fan (default blue).
A no-arg constructor that creates a default fan.
A parameterized constructor initializes the fan objects to given values.
A method named display() will display description for the fan. If the fan is on,
the display() method displays speed, color and radius. If the fan is not on, the
method returns fan color and radius along with the message “fan is off”.
Write a test program that creates two Fan objects. One with default values and
the other with medium speed, radius 6, color brown, and turned on status true.
Display the descriptions for two created Fan objects.
8. Define the Rectangle class that contains:
Two double fields x and y that specify the center of the rectangle
the data field width and height ,
A no-arg constructor that creates the default rectangle with (0,0) for (x,y) and
1 for both width and height.
A parameterized constructor creates a rectangle with the specified x, y, height
and width.
A method getArea() that returns the area of the rectangle.
A method getPerimeter() that returns the perimeter of the rectangle.
A method contains(double x, double y) that returns true if the specified point
(x,y) is inside this rectangle.
Write a test program that creates two rectangle objects. One with default values
and other with user specified values. Test all the methods of the class for both
the objects.
hierarchy. Declare one instance variable of type String that indicates the color of
a vegetable. Create and display instances of these objects. Override the toString()
method of Object to return a string with the name of the vegetable and its color.
Aclass objects. Initialize the elements of the array with a mix of Aclass and Bclass
objects. Execute a program loop to invoke the display() method of each object.
6. Describe abstract class called Shape which has three subclasses say Triangle,
Rectangle and Circle. Define one method area() in the abstract class and override
this area() in these three subclasses to calculate for specific object i.e. area() of
Triangle subclass should calculate area of triangle etc. Same for Rectangle and
Circle.
7. Write a program to define abstract class, with two methods addition() and
subtraction(). addition() is abstract method. Implement the abstract method and
call that method using a program(s).
5 operations for particular class Page, Shape, Point, Line, Arc, Ellipse,
Rectangle, Circle.
3. Prepare a class diagram for given group of classes using multiplicity,
generalization, association concepts. And add at least 5-7 attributes and 3-5
operations for particular class. City, Airport, Airline, Pilot, Flight, Plane,
Seat, Passenger.
4. Categorize the following relationships into generalization, aggregation or
association.
[A] A country has a capital city
[B] A dining philosopher uses a fork
[C] A file is an ordinary file or a directory file
[D] Files contains records
[E] A polygon is composed of an ordered set of points
[F] A drawing object is text, a geometrical object, or a group
[G] A person uses a computer language on a object
[H] Modems and keyboards are input/output devices
[I] Classes may have several attributes
[J] A person plays for a team in a certain year
[K] A route connects two cities
[L] A student takes a course from a professor
5. Prepare a state diagram for an interactive diagram editor for selecting and
dragging objects
6. Prepare a use case diagram and sequence diagram for a computer email
system.
7. Prepare an activity diagram for computing a restaurant bill, there should
be charge for each delivered item. The total amount should be subject to
tax and service charge of 18% for group of six and more. For smaller
groups there should be a blank entry. Any coupons or gift certificates
submitted by the customer should be subtracted .
8. Prepare a sequence diagram for issuing a book in the library management
system.