Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A software company sells a package that retails for $99. Quantity discounts are

ID: 3759202 • Letter: A

Question

A software company sells a package that retails for $99. Quantity discounts are given according to the following table:

10–19

20–49

50–99

Design a class that stores the number of units sold and has a method that returns the total cost of the purchase.

The following is the demo file that should execute as required:

import java.text.DecimalFormat;
import java.util.Scanner;

/**
* SoftwareSalesDemo Program
*/

public class SoftwareSalesDemo {
   public static void main(String[] args) {
       int units; // To hold units sold

       // 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()));
   }
}

Quantity Discount

10–19

20%

20–49

30%

50–99

40% 100 or more 50%

Explanation / Answer

import java.util.Scanner;

public class SoftwareSales

{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int quantity = 0;
double retailPrice = 99;
double discountPerc = 0.0, purchaseCost = 0.0, totalDiscount = 0.0, totalCost = 0.0;



purchaseCost = quantity * 99;
totalDiscount = purchaseCost * discountPerc;
totalCost = purchaseCost - totalDiscount;


//Ask user for inputs

System.out.print ("Enter the quantity purchased: ");
quantity = input.nextInt();


//if/else statements

if (quantity >= 10 && quantity <= 19)
{


discountPerc = 0.8;

System.out.println("Discount is 20%");
}

else if (quantity >= 20 && quantity <=49)
{

discountPerc = 0.7;

System.out.println ("Discount is 30%");
}

else if (quantity >= 50 && quantity <= 99)
{

discountPerc = 0.6;

System.out.println ("Discount is 40%");
}

else if (quantity >= 100)
{

discountPerc = 0.5;

System.out.println ("Discount is 50%");
}

else if (quantity >0 && quantity <= 9)
{

discountPerc = 0.0;

System.out.println ("No discount for purchases");
}

else if (quantity <0)
{
System.out.println ("You entered an invalid number");


System.out.println ("The total discount amount is: $" + totalDiscount +
" The purchase amount after the discount is: $" + totalCost);

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote