Java Practice Exercise – Interface

  • Write a program to create interface method named customer. In this keep the methods called information(), show() and also maintain the tax rate. Implement this interface in employee class and calculate the tax of the employee based on their income.
Income
Tax percentage
Male
Female
>=1,90,000
Nil
Nil
>=2,00,000
10%
Nil
>=5,00,000
20%
10%
<5,00,000
25%
20%
  • Define an interface using Java program that contains a method to calculate the perimeter of object. Define two classes – circle and rectangle with suitable fields and methods. Implement the interface “perimeter” in these classes. Write the appropriate main() method to create object of each class and test all methods.
  • Design a Java interface for ADT Stack. Implement this interface using array. Provide necessary exception handling in both the implementations
  • Create a Java console application using interface concepts for abstract data type Stack. Implement Stack operations PUSH, POP and Display using Array along with exception handling techniques
  • Define an interface “QueueOperations” which declares methods for a static queue. Define a class “MyQueue” which contains an array and front and rear as data members and implements the above interface. Initialize the queue using a constructor. Write the code to perform operations on a queue object.
  • Create an interface “CreditCardInterface” with methods to viewCreditAmount, viewPin, changePin and payBalance. Create a class Customer (name, card number, pin, creditAmount – initialized to 0). Implement methods of the interface “CreditCardInterface” in Customer class. Create an array of customer objects and perform the following actions.
    • Pay Balance
    • Change Pin