Sunday, 12 March 2023

Unit 2 java Programs


1. Write a program to sort the elements of one dimensional array. Read value of array elements through command line argument. 


2. Write a program to create an array to store 5 integer values. Also initialize the array with 5 numbers and display the array Elements in reverse order. 


3. Write a program to find sum of two matrices of 3 x3.


4. Write program to create an array of company name and another array of price quoted by the company. Fetch the company name who has quoted the lowest amount. 


5. Write an interface called numbers, with a method in Process(int x, int y). Write a class called Sum, in which the method Process finds the sum of two numbers and returns an int value. Write another class called Average, in which the Process method finds the average of the two numbers and returns an int. 


6. Create a class called NumberData that accept any array of the five numbers. Create a sub class called Numplay which provides methods for followings: 1. Display numbers entered. 2. Sum of the number. 3. Average of the numbers. 4. Maximum of the numbers. 5. Minimum of the numbers. Create a class that provides menu for above methods. Give choice from the command-line argument. 


7. Declare an abstract class Vehicle with an abstract method named numWheels( ).provide subclasses Car and Truck that each implements this method. Create instance of these subclasses and demonstrate the use of this method 


8. Write an interface called Exam with a method Pass(int mark) that returns a Boolean. Write another interface called Classify with a method Division(int average) which returns a string. Write a class called Result which implements both Exam and Classify. The pass method should return true if the marks is greater than or equal to 35 else false. The division method must return “First” when the parameter average is 60 or more, “second” when average is 50 or more but below 60, “no division” when average is less than 50. 


9. Create class calculation with an abstract method area( ). Create Rectangle and Triangle subclasses of calculation and find area of rectangle and triangle. 


10. The abstract Vegetable class has four subclasses named cabbage, carrot and potato. Write an application that demonstrates how to establish this class hierarchy. Declare one instance variable of type string that indicates the color of a vegetable. Create and display instances of these object. Override the toString() method of object to return a string with the name of the vegetable and its color.


No comments:

Post a Comment

python programs

1. sum of two number