Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * This class simulates the sale of a retail item
- *
- * @author Adrian Sieroslawski
- * @version 1.0
- */
- public class CashRegister{
- public static final double TAX_RATE = 0.06;
- private RetailItem item;
- private int quantitySold;
- // Constructors
- public CashRegister() {
- item = new RetailItem();
- }
- public CashRegister(String newItem, int newQuantitySold) {
- setItemSold(newItem);
- setQuantitySold(newQuantitySold);
- item = new RetailItem(newItem, newQuantitySold);
- newQuantitySold = quantitySold;
- }
- public CashRegister(RetailItem itemSold) {
- item = itemSold;
- }
- //Accessors aka Getters
- public RetailItem getItemSold() {
- return item;
- }
- public int getQuantitySold() {
- return quantitySold;
- }
- //Mutators aka Setters
- public void setQuantitySold(int quantity) {
- if(quantity >= 0 && quantity <= item.getNumberOfUnitsInStock()) {
- quantitySold = quantity;
- }
- }
- public void setItemSold(String itemSold) {
- if(itemSold != null) {
- item = itemSold;
- } else {
- item = new RetailItem();
- }
- }
- // Calculation Methods
- public double calculateSubtotal() {
- double subTotal = getQuantitySold() * item.getItemPriceInCAD();
- return subTotal;
- }
- public double calculateTax() {
- double totalTax = TAX_RATE * calculateSubtotal();
- return totalTax;
- }
- public double calculateTotal() {
- double total = calculateSubtotal() + calculateTax();
- return total;
- }
- public void printSalesReceipt() {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement