Interface Exercise 1| Programming Using Java | Infosys Springboard

Interface Exercise 1| Programming Using Java | Infosys Springboard

Introduction to Interface Exercise 1

Overview of the Problem Statement

  • Shreyas introduces the video, focusing on solving an interface exercise related to tax calculations for an e-commerce company.
  • The task involves implementing an application that calculates taxes based on customer purchases and seller locations, as per a provided class diagram.

Understanding the Tax Interface

  • The problem includes a Tax interface with two implementing classes: PurchaseDetails and Seller.
  • The calculateTax method is central to both classes, which will determine tax rates based on payment types and seller locations.

Implementation Steps in Eclipse IDE

Creating the PurchaseDetails Class

  • In the PurchaseDetails class, three variables are declared: purchaseId, paymentType, and taxPercentage.
  • A parameterized constructor initializes these variables. Getter and setter methods are also generated for encapsulation.

Tax Calculation Logic for Purchases

  • The logic in the calculateTax method sets tax percentages based on payment type:
  • Debit card: 2%
  • Credit card: 3%
  • Other payment methods: 4%
  • The method returns the total amount after applying tax using the formula: price + (price * taxPercentage / 100).

Creating the Seller Class

  • Similar to PurchaseDetails, the Seller class has two variables: location and taxPercentage.
  • A parameterized constructor initializes these variables, followed by getter and setter methods.

Tax Calculation Logic for Sellers

Implementing Location-Based Tax Rates

  • In the seller's calculateTax method, different tax percentages are assigned based on location:
  • Canada: 22%
  • Middle East: 15%
  • Japan: 12%
  • Europe: 25%

Finalizing Implementation

  • Both classes return amounts after applying their respective taxes using similar formulas as in purchase calculations.

Testing the Implementation

Running Test Cases

  • A tester class creates objects of both PurchaseDetails and Seller, invoking their respective calculate methods.
  • [] (No specific timestamp provided here; general execution note.) Results are printed with two decimal precision to verify correctness before running test cases online.
Video description

Check this👇 Full Playlist Link: https://youtube.com/playlist?list=PLox-t2Mz_nvu-jZNegtVMK1YaptJXGCEw Note- Sometimes all testcases will not pass or sometimes verify button will not work. But don't panic, just focus on getting right output without doing changes in the Tester class. Our priority is learning concepts in detail. Stay Curious, Keep Learning👍 Problem Statement- An e-commerce company has made it mandatory for all the customers to pay tax on every purchase and also for all the sellers to pay a certain amount of tax based on their location. You need to help the e-commerce company by implementing an application for paying tax based on the class diagram and description given. #interface #java #infosys