Writing cash register software is difficult Beyond the requi

Writing cash register software is difficult. Beyond the required accuracy and being able to scan and look up prices, cash registers must calculate the sales taxes owed. But every locality sets its own sales tax rates and every item needs to be placed in a specific category for correct taxation. With both the rates and classifications needing to change, this makes it a perfect place for a Visitor.

the TaxVisitor class which creates the interface our visitors will be implementing.

the DelawareTaxVisitor class.

the the ErieCountyTaxVisitor class, and the the NJTaxVisitor class.

Delaware does not have any sales tax, but New Jersey and Erie County do. The latter two classes should increase the value of sales taxes when each method is called. The comments in each of those classes specify the sales tax to charge.

TaxVisitor class:

package edu.buffalo.cse116;

/**

the DelawareTaxVisitor class:

the ErieCountyTaxVisitor class:

the NJTaxVisitor class:

Solution

DelawareTaxVisitor.java

/**
* This class defines the sales tax rules for Delaware. Growing up in Maryland, the ads touted Delaware as \"your home of
* tax-free shopping.\" Because this is not really needed for reality, implement the class as if Delaware still has a 0%
* tax rate.
*/
public class DelawareTaxVisitor implements TaxVisitor {

   int saleTaxes;
   @Override
   public void salesTaxGrocery(double amount) {
       // TODO Auto-generated method stub
       saleTaxes+=0;
   }

   @Override
   public void salesTaxPreparedFood(double amount) {
       // TODO Auto-generated method stub
       saleTaxes+=0;
   }

   @Override
   public void salesTaxClothing(double amount) {
       // TODO Auto-generated method stub
       saleTaxes+=0;
   }

}

ErieCountyTaxVisitor.java

/**
* This class defines the sales tax rules for Erie County in New York State. New York State is even worse than many
* places, as each county define their own sales tax rates that are included on top of the state sales tax.
*/
public class ErieCountyTaxVisitor implements TaxVisitor {

/** Total of the sales taxes collected during this purchase. */
private double salesTaxes;

/** The sales tax rate charged on all prepared foods and clothing. This does NOT get charged to groceries. */
private static final double ERIE_CO_TAX = 0.0475;

/** The sales tax rate charged on all prepared food. This does NOT get charged to groceries or clothing. */
private static final double NY_STATE_TAX = 0.04;

@Override
public void salesTaxGrocery(double amount) {
   // TODO Auto-generated method stub
   salesTaxes+=0;
  
}

@Override
public void salesTaxPreparedFood(double amount) {
   // TODO Auto-generated method stub
   salesTaxes+=(ERIE_CO_TAX+NY_STATE_TAX)*amount;
  
}

@Override
public void salesTaxClothing(double amount) {
   // TODO Auto-generated method stub
   salesTaxes+=ERIE_CO_TAX*amount;
  
}

public double getSalesTaxes() {
   return salesTaxes;
}

}

NJTaxVisitor.java

/**
* This class defines the sales tax rules for New Jersey. The musical may say \"[e]verything\'s legal in New Jersey\", but
* everything is also taxed at a consistent, relatively high rate. This does those basic calculations.
*/
public class NJTaxVisitor implements TaxVisitor {

/** Total of the sales taxes collected during this purchase. */
private double salesTaxes;

/**
* The state sales tax rate charged on virtuall all purchases in the state. (There are a few, very rare exceptions
* this homework should ignore.)
*/
private static final double STATE_TAX = 0.07;

@Override
public void salesTaxGrocery(double amount) {
   // TODO Auto-generated method stub
   salesTaxes+=STATE_TAX*amount;
}

@Override
public void salesTaxPreparedFood(double amount) {
   // TODO Auto-generated method stub
   salesTaxes+=STATE_TAX*amount;
}

@Override
public void salesTaxClothing(double amount) {
   // TODO Auto-generated method stub
   salesTaxes+=STATE_TAX*amount;
}

public double getSalesTaxes() {
   return salesTaxes;
}
}

Writing cash register software is difficult. Beyond the required accuracy and being able to scan and look up prices, cash registers must calculate the sales tax
Writing cash register software is difficult. Beyond the required accuracy and being able to scan and look up prices, cash registers must calculate the sales tax
Writing cash register software is difficult. Beyond the required accuracy and being able to scan and look up prices, cash registers must calculate the sales tax

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site