Advertisement
Purianite

Untitled

Nov 7th, 2012
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.42 KB | None | 0 0
  1. //Driver
  2.     package asdfghjkl;
  3.    
  4.     import java.util.ArrayList;
  5.    
  6.     public class Driver
  7.     {
  8.         public static ArrayList<SaleCalculator> revenueList = new ArrayList<SaleCalculator>();
  9.         public static float totalRevenue = 0.0f;
  10.         public static void main(String[] args)
  11.         {
  12.             ALSalesCalculator alabamaSales = new ALSalesCalculator();
  13.             revenueList.add(alabamaSales);
  14.             AKSalesCalculator alaskaSales = new AKSalesCalculator();
  15.             revenueList.add(alaskaSales);
  16.            
  17.             for (int i = 0; i < revenueList.size(); i++)
  18.             {
  19.                 revenueList.get(i).Calculate();
  20.                 totalRevenue += revenueList.get(i).revenue;
  21.             }
  22.             System.out.println("Total revenue: $" + (totalRevenue));
  23.         }
  24.    
  25.     }
  26.  
  27. //Sale Calculator
  28. package asdfghjkl;
  29.  
  30. public abstract class SaleCalculator
  31. {
  32.     float salesTax;
  33.     float unitPrice = 50.0f;
  34.     float unitsSold = 10000.0f;
  35.     String stateName;
  36.     public float revenue;
  37.    
  38.     public void Calculate()
  39.     {
  40.         revenue = (int)unitsSold * (unitPrice + (salesTax * unitPrice));
  41.         System.out.println("Revenue in " + stateName + ": $" + revenue);
  42.     }
  43. }
  44.  
  45. //State specific calculators
  46.     package asdfghjkl;
  47.    
  48.     public class AKSalesCalculator extends SaleCalculator
  49.     {
  50.         public AKSalesCalculator()
  51.         {
  52.             salesTax = 0.04f;
  53.             stateName = "Alaska";
  54.         }
  55.     }
  56.  
  57.  
  58. package asdfghjkl;
  59.  
  60. public class ALSalesCalculator extends SaleCalculator
  61. {
  62.     public ALSalesCalculator()
  63.     {
  64.         salesTax = 0.04f;
  65.         stateName = "Alabama";
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement