The document provides 11 Java programming tasks related to arrays and classes. It also provides an algorithm to demonstrate polymorphism by designing a vehicle class hierarchy with abstract and concrete classes for different vehicle types (air, water, land) that can input and display vehicle data. The main method uses a switch case to perform operations on the opted vehicle class and call methods by assigning object values to a reference variable.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
260 views
Java Practice Program
The document provides 11 Java programming tasks related to arrays and classes. It also provides an algorithm to demonstrate polymorphism by designing a vehicle class hierarchy with abstract and concrete classes for different vehicle types (air, water, land) that can input and display vehicle data. The main method uses a switch case to perform operations on the opted vehicle class and call methods by assigning object values to a reference variable.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2
1.
Write a Java method to find the smallest number among
three numbers. 2. Write a program to create a room class, the attributes of this class is room no, room type, room area and AC machine. In this class the member functions are set data and display data 3. Write a Java program to sort a numeric array and a string array 4. Write a Java program to test if an array contains a specific value 5. Write a Java program to get the character at the given index within the String 6. Write a Java program to concatenate a given string to the end of another string 7. Write ass Java program to check whether two String objects contain the same data 8. Write a Java program to calculate the average value of array elements 9. Write a Java program to find the index of an array element. 10. Write a Java program to reverse an array of integer values 11. Design a Vehicle class hierarchy in Java. Write a test program to demonstrate Polymorphism. ALGORITHM STEP 1: Create an abstract class named vehicle with abstract method Display and a concrete method Input. STEP 2: Define the input method by prompting the user to enter the values for name, owner, type, number, engine capacity, seating capacity for the vehicle; all the inputs taken in the form string. STEP 3: Extend three classes namely Air, Water and Land from the base class. STEP 4: Define the method display under the class Air by displaying all the entered values. STEP 5: Repeat step 4 for the class Water. STEP 6: Extend the input method for the class Land by taking in the value of wheeling capacity for the vehicle in the form of string. STEP 7: In the main method create a reference for the abstract class and create a switch case to perform operations on the opted class. STEP 8: Under each class create a switch case to either enter the data or to display the transport report. STEP 9: Repeat the main menu on the user's choice. STEP 10: Create array of objects under each class and call the methods by assigning the values of the created objects to the reference object, to show polymorphism.