# Class ShippingCostCalculator

java.lang.Object
com.university.bookstore.visitor.ShippingCostCalculator

All Implemented Interfaces:
  `MaterialVisitor`

public class ShippingCostCalculator extends Object implements MaterialVisitor
Concrete visitor implementation for calculating shipping costs. Demonstrates the Visitor pattern by providing different shipping cost calculations based on material type.

Shipping costs vary by material type: - Physical items: $0.50 per 100g - Digital items: $0 (instant download) - Magazines: $2 flat rate

Since:
  2024-09-15
Version:
  2.0
Author:
  Navid Mohaghegh

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ShippingCostCalculator()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `double`
  `calculateShippingCost(Material material)`
  Calculates shipping cost for a single material.
  `double`
  `getTotalShippingCost()`
  Gets the total shipping cost calculated so far.
  `void`
  `reset()`
  Resets the shipping cost calculator for a new calculation.
  `void`
  `visit(AudioBook audioBook)`
  Calculates shipping cost for audio books.
  `void`
  `visit(EBook ebook)`
  Calculates shipping cost for e-books.
  `void`
  `visit(Magazine magazine)`
  Calculates flat rate shipping cost for magazines.
  `void`
  `visit(PrintedBook book)`
  Calculates shipping cost for a printed book based on weight.
  `void`
  `visit(VideoMaterial video)`
  Calculates shipping cost for video materials.

  ### Methods inherited from class java.lang.Object

  `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### ShippingCostCalculator

    public ShippingCostCalculator()

- ## Method Details

  - ### visit

    public void visit(PrintedBook book)
    Calculates shipping cost for a printed book based on weight. Assumes average book weight of 500g.
    Specified by:
      `visit` in interface `MaterialVisitor`
    Parameters:
      `book` - the printed book

  - ### visit

    public void visit(Magazine magazine)
    Calculates flat rate shipping cost for magazines.
    Specified by:
      `visit` in interface `MaterialVisitor`
    Parameters:
      `magazine` - the magazine

  - ### visit

    public void visit(AudioBook audioBook)
    Calculates shipping cost for audio books. Physical CDs: weight-based, Digital: free
    Specified by:
      `visit` in interface `MaterialVisitor`
    Parameters:
      `audioBook` - the audio book

  - ### visit

    public void visit(VideoMaterial video)
    Calculates shipping cost for video materials. Physical DVDs: weight-based, Digital: free
    Specified by:
      `visit` in interface `MaterialVisitor`
    Parameters:
      `video` - the video material

  - ### visit

    public void visit(EBook ebook)
    Calculates shipping cost for e-books. E-books are always digital downloads with no shipping cost.
    Specified by:
      `visit` in interface `MaterialVisitor`
    Parameters:
      `ebook` - the e-book

  - ### getTotalShippingCost

    public double getTotalShippingCost()
    Gets the total shipping cost calculated so far.
    Returns:
      the total shipping cost

  - ### reset

    public void reset()
    Resets the shipping cost calculator for a new calculation.

  - ### calculateShippingCost

    public double calculateShippingCost(Material material)
    Calculates shipping cost for a single material.
    Parameters:
      `material` - the material to calculate shipping for
    Returns:
      the shipping cost for this material