Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Driver
- package asdfghjkl;
- import java.util.ArrayList;
- public class Driver
- {
- public static ArrayList<SaleCalculator> revenueList = new ArrayList<SaleCalculator>();
- public static float totalRevenue = 0.0f;
- public static void main(String[] args)
- {
- ALSalesCalculator alabamaSales = new ALSalesCalculator();
- revenueList.add(alabamaSales);
- AKSalesCalculator alaskaSales = new AKSalesCalculator();
- revenueList.add(alaskaSales);
- for (int i = 0; i < revenueList.size(); i++)
- {
- revenueList.get(i).Calculate();
- totalRevenue += revenueList.get(i).revenue;
- }
- System.out.println("Total revenue: $" + (totalRevenue));
- }
- }
- //Sale Calculator
- package asdfghjkl;
- public abstract class SaleCalculator
- {
- float salesTax;
- float unitPrice = 50.0f;
- float unitsSold = 10000.0f;
- String stateName;
- public float revenue;
- public void Calculate()
- {
- revenue = (int)unitsSold * (unitPrice + (salesTax * unitPrice));
- System.out.println("Revenue in " + stateName + ": $" + revenue);
- }
- }
- //State specific calculators
- package asdfghjkl;
- public class AKSalesCalculator extends SaleCalculator
- {
- public AKSalesCalculator()
- {
- salesTax = 0.04f;
- stateName = "Alaska";
- }
- }
- package asdfghjkl;
- public class ALSalesCalculator extends SaleCalculator
- {
- public ALSalesCalculator()
- {
- salesTax = 0.04f;
- stateName = "Alabama";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement