Hello, I'm having trouble with my SoftwareSales.java program that involves another demo part. I have it running but my output seems off, something tells me its a simple fix but I'm having trouble again. Thanks for any tips/suggestions.
SoftwareSales.java
package chapter4; public class SoftwareSales { private double retailCostPerUnit = 99.00; private double costBeforeDiscount; private double costAfterDiscount; private double discount; private double unitsSold; private double cost; public SoftwareSales(int units) { unitsSold = units; } public void setUnitsSold(int units) { unitsSold = units; } public double getDiscount() { costBeforeDiscount = retailCostPerUnit * unitsSold; if (unitsSold >= 100) { discount = costBeforeDiscount * 0.5; } else if(unitsSold >= 50) { discount = costBeforeDiscount * 0.4; } else if(unitsSold >= 20) { discount = costBeforeDiscount * 0.3; } else if (unitsSold >= 10) { discount = costBeforeDiscount * 0.2; } else { discount = 0; } costAfterDiscount = costBeforeDiscount - discount; return discount; } public double getUnitsSold() { return unitsSold; } public double getCost() { cost = retailCostPerUnit - discount; return cost; } }
SoftwareSalesDemo.java
package chapter4; import java.text.DecimalFormat; import java.util.Scanner; public class SoftwareSalesDemo { public static void main(String[] args) { int units; // Create a Scanner object for keyboard input. Scanner keyboard = new Scanner(System.in); // Get the units sold. System.out.print("Enter the units sold: "); units = keyboard.nextInt(); // Create a SoftwareSales object. SoftwareSales sales = new SoftwareSales(units); // Display purchase info. DecimalFormat dollar = new DecimalFormat("#, ## 0.00"); System.out.println("Units sold: " + sales.getUnitsSold()); System.out.println("Discount: $" + dollar.format(sales.getDiscount())); System.out.println("Cost: $" + dollar.format(sales.getCost())); keyboard.close(); } }