Skip to main content

Practice Set: Inheritance, String, Array and ArrayList

1. WAP to create a class Person with attributes Name, Age and Mobile Number and a method to display the details of a person and an abstract method to assign the designation of the person as per the user input at run time. Create two subclasses of Person as Student and Employee and write the methods to accept the Organization name from the User at runtime and methods to display all the details of Student/Employee. Create the objects of both the subclasses using constructors to initialize the instance variables of the class and then display all the details of both. 

2. WAP to create a class Vehicle having data members Mileage and fuel and methods to add the fuel. Create two sub classes of Vehicle i.e. Bike and Car each having data members Name, and Max_Speed and method to calculate the remaining fuel. From a class Race create the objects of both the subclasses using appropriate constructors to initialize the data members after taking the input from the user. Display the remaining fuel ant time taken by both the vehicles after completion of the race. 

3. WAP in which create a class Account which inherits from Bank class (which contains two methods deposit and withdraw). Overload the deposit method for cash and check. Create a class App which provides you a menu for deposit, withdraw, Account information and Exit. Perform all the above operations on the Account Number entered by the user. 

4. Write a program which prompts the user to enter a String. Now implement the following method public int[] countVowels(String s) which returns the array containing the number of vowels in String s. Where the count of a,e,i,o,u is stored in indexes 0 to 4 respectively.


5. Write a program to implement the following method which inverts the cases of each letter of the String: public String changeCase(String str) Input: HeLP ME Output: hElp me 6. Write a program to create a class Student with attributes name, cgpa and registration_number. Use appropriate constructor to initialize the instance variables of the class. Create a class StudentData which contains an array to store the Student objects. Create at least 3 objects of the Student class and store into array. Implement a method public void findCGPA(String name, int reg) to display the cgpa of the student having that name and registration number. 


7. Write a program to define a class named Employee with attributes name salary and id. Also provide a parameterized constructor to initialize all the attributes. Create a class TestEmployee in which create at least 3 employee objects and Store in an arraylist. Implement a method public void search(int id) which display the name and salary of the employee with given id. 

8. Write a program which prompts the user to enter the number of subjects N and number of CAs M. Read the CA marks of every subject from the user at run time and store in a matrix. Now implement a method double[] averageCA(double [][] marks) which returns the average of CA marks for each subject in an array.
 


9. Write a program to create a class named Employee having attributes emp_name, emp_id and salary. Create a class Emp_Data in which create N Employee objects after taking input from the user. Store all the Employee objects in an array. Implement a method void findEmployee(int id) which displays the name and salary of the employee with argumented id. 

10. Write a program to create a class named Vehicle with attributes price, mileage and fuel and a parameterized constructor to initialize all the instance variables. Vehicle class must have a method int getFuel() which returns the fuel and an abstract method public void addFuel(int f) to add the fuel. Create a subclass of Vehicle named Car with attribute car_name. Implement the addFuel method. Also override the getFuel method in Car class to display the name of the Car and return the available fuel. Create 3 Car objects and store them in an ArrayList. Implement a method getCar() to display the name and price of the Car with maximum mileage. 

11. WAP to create a class Account containing Account Number, Account_Holder_Name and Balance as the data members and methods to deposit and withdraw. Create two subclasses of Account, Saving and Current. Saving must have a method to calculate the interest on the balance for 1 year with ROI 6% per annum and method to display all the details of that account. Current must have a method to change the limit of maximum withdrawl in a day. Use the constructor to create the object of each type and assign the account number automatically in a sequence. 

12. WAP to create a class Result containing two attributes Marks and Grade and a method to display the Grades of the student for any subject. Create two subclasses of Result, Regular and Part-time and override the method correspondingly. From the main class, take the input from the user, name of student, course type and marks in 5 subjects and display all the details of the student and grades in all 5 subjects.

Comments

  1. Good Post! Thank you so much for sharing the post, it was so good to read and useful to improve
    Java Training in Electronic City

    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