Skip to main content

Practice Set: After MTE



1. Write a program to define a class Employee with attributes name, employee_id and salary and also provide a parameterized constructor to initialize all the attributes.
Create an appropriate collection to store the Employee objects such that the non-duplicate objects are stored in descending order of their salary. Use Iterator to display the names and salary of all the employees.


2. WAP to create a class Student with attributes name and cgpa. Add at least 5 Student objects in an appropriate collection such that they are sorted in descending order on the basis of their cgpa. Display the names of all the students who are eligible for Verizon placement drive.  (Eligibility: cgpa >=7.5 )


3. Write a program which prompts the user to enter N integers and store them in an arraylist. Now implement a method which accepts an arraylist containing duplicate values and returns a Collection having unique elements only.
                        public Collection removeDuplicate(ArrayList<T extends Number> al)
Display all the integer values after removing the duplicates.


4. Write a program which prompts the user to enter a String. Now implement a method to check whether the String is palindrome or not?  public boolean isPalindrome(String str)
Invoke the isPalindrome method and if the String is not palindrome then throw a user defined exception NOT_PALINDROME_EXCEPTION which displays “String is not palindrome” when the exception object is printed. Handle the exception using try-catch blocks.


5. Write a program to define a class Car having attributes name, mileage and price. Create 5 Car objects and store them in a file named as Cars.txt.
Write a method public void getCars(int amt) which displays the name, mileage and price of all the cars having price less than amt. [Use Object Input/Output Stream]



6. Write a program which reads the name of two files f1 and f2 using the command-line arguments. Now append the contents of f1 into f2.
Now read a message from the console using Scanner and append at the end of File f2 and display the contents of f2 on console.




7. Write a program which reads two integers from the command-line argument and handle the possible exceptions using try-catch and if exception occurs, ask to re-enter the numbers and read using Scanner. Now invoke the public int divide(int a, int b) method and display the result of dividing a by b. Handle the exception in division also. Demonstrate the importance of finally block in this program.


8. Write a program to create an interface Demo with a static method testStatic(), a default method testDefault() and an abstract method testAbstract().
Define two interfaces X and Y with an abstract method void test() in each of them.
Define an abstract class MyAbstract which inherits X and Y.
Implement a class MyClass which inherits MyAbstract, Demo and X. Create an object of MyClass and invoke testStatic, testDefault, testAbstract and test methods.


9. WAP in which define an abstract class A containing a non-abstract method demo() and an integer variable x initialized to 10. Define an interface B containing a default method void demo() and a double variable x initialized  with 20.0. Now create a class Test which inherits A and B and override the demo method. Invoke the demo() method of Interface and the class Test both and print the value of x.


10. Write a program to define an interface Person containing abstract method VoterId getVoterID().
Create a class Employee which inherits Person and contains an inner class VoterId with attributes id and name. Implement the getVoterId method such that it reads the name and automatically assigns a unique id to each Employee Object and return the VoterId object.
Create a Main class and create two Employee objects and display their Voter Ids.

Comments

  1. from where i will get these answere ?

    ReplyDelete
  2. What we will do with these questions.If we were able to solve these questions by our own,
    then we will be able to perform the same in exams also.

    ReplyDelete
  3. What about the solutions to these questions?

    ReplyDelete
  4. Plzz give also the solutions atleast littlebit hints,,, plzzz

    ReplyDelete
  5. Nice blog..! I really loved reading through this article... Thanks for sharing such an amazing post with us and keep blogging...Java Training in Chennai
    Java Training Institute in Chennai

    ReplyDelete
  6. Thanks for sharing this valuable information i like it. This is very useful for Freshers. I Can share this with my friend circle. Keep Updates for Useful Information...
    Java Training in Delhi

    ReplyDelete
  7. It is amazing and wonderful to visit your site. Thanks for sharing information; this is useful to us....

    MERN Stack Training in Delhi

    ReplyDelete

Post a Comment

Popular posts from this blog

Practice MCQs

  1. What will be the Output of the following code? class X{                  static int x = 1;                        static class Y {                              static int y = x++;                                static class Z                                                                       {                                                                                         static int z = ++y;                                                                        }                                               }                }   class MainClass{     public static void main(String[] rk)    {                             System.out.print(X.x);                                             System.out.print(X.Y.y);                             System.out.print(X.Y.Z.z);         } } A. 113 B. 123 C. 111 D. None of These Ans: A 2.  Which of the following statement is TRUE about t he following code? public class Outer  {    private i

Practice Set

1. Write a program to create a class Voter which contains attributes name, date_of_birth and voter_id and voter has a Voter_Card. Provide appropriate constructor to initialize all the attributes of the Voter but voter id must be assigned automatically only when the age of the voter is greater than or equal to 18 years. VoterCard is a nested class with attributes voter_id and Voter_name. Make sure that voter card is created only when user is a valid voter and if it is already created then must not be assigned the new voter id. 2. Write a program to define two interfaces UGC and AICTE both having a default method int getAdmission() to take the admission and an abstract method String payFee(). getAdmission() in UGC must ask the percentage in qualifying exam and if the percentage >= 60 then generate the registration number and return. getAdmission() is AICTE must ask the user to join the counseling after 5 days and display the date of counseling and return the counseling token numb

Mock Test - 1

1. Which of the following is a byte stream class? A. ObjectInputStream B. Writer C. PrintWriter D. Scanner Ans: A 2. Which exception is thrown by read() method in InputStream class? A. IOException B. InterruptedException C. FileNotFoundException D. None of These Ans: A 3. Which of the following class is subclass of FilterInputStream? A. InputStream B. ObjectOutputStream C. FileInputStream D. BufferedInputStream  Ans: D 4. Which of these class contains the print() and println() methods? A. System B. out C. PrintStream D. BUfferedOutputStream Ans: C 5. Which of these is a method to clear all the data present in output buffer without terminating the stream? A. clear() B. fflush() C. flush() D. close() Ans: C 6. Which of these classes defined in java.io and used for file-handling are abstract? (i) InputStream        (ii) PrintStream    (iii) Reader        (iv) FileInputStream A. Only i     B. i and ii    C. Only iii    D. i and iii Ans: D 7. What is the output of this program? class MyE