8. Software Sales A software company sells a package that retails for $99. Quant
ID: 3846859 • Letter: 8
Question
8. Software Sales A software company sells a package that retails for $99. Quantity discounts are given according to the following table: Quantity Discount 10-19 20% 20-49 30% 50-99 40% 100 or more 50% Write a program that asks the user to enter the number of packages purchased. The pro- gram should then display the amount of the discount (if any) and the total amount of the purchase after the discount. For instance, to calculate 20% of a value N, you can use the formula: (20 / 100.0) * N (or 0.2 * N). SAMPLE RUN #8: java SoftwareSales
What I have -
import java.util.Scanner;
public class SoftwareSales
{
public static void main( String[] args )
{
Scanner in = new Scanner( System.in );
System.out.println( "Enter number of packages purchased: " );
int count = in.nextInt();
float discount = ( 0 / 100 );
if( count < 10 )
{
// no discount
}
else if( count <20 )
{
discount = ( 20 / 100 );
}
else if( count < 50 )
{
discount = ( 30 / 100 );
}
else if( count < 100 )
{
discount = ( 40 / 100 );
}
else
{
discount = ( 50 / 100 );
}
float costBeforeDiscount = count * 99;
float $amountOfDiscount = costBeforeDiscount * discount;
float $finalCost = costBeforeDiscount - $amountOfDiscount;
System.out.println( "Your discount is:" + $amountOfDiscount );
System.out.println( "Your total is:" + $finalCost );
}
}
Error message I'm getting -
Interactive Session Hide Invisibles Enter number .o packages p urchase d:50 Your discount is $1980.00 Your total is: $2970.00- Highlight: None Show Highlighted OnlyExplanation / Answer
Hi, I have fixed the issue.
import java.util.Scanner;
public class SoftwareSales
{
public static void main( String[] args )
{
Scanner in = new Scanner( System.in );
System.out.println( "Enter number of packages purchased: " );
int count = in.nextInt();
in.close();
double discount = 0;
if( count < 10 )
{
// no discount
}
else if( count <20 )
{
discount = ( 20 / 100.0 );
}
else if( count < 50 )
{
discount = ( 30 / 100.0 );
}
else if( count < 100 )
{
discount = ( 40 / 100.0 );
}
else
{
discount = ( 50 / 100.0 );
}
double costBeforeDiscount = count * 99;
double $amountOfDiscount = costBeforeDiscount * discount;
double $finalCost = costBeforeDiscount - $amountOfDiscount;
System.out.printf("Your discount is: %.2f ", $amountOfDiscount);
System.out.printf("Your total is: %.2f ", $finalCost);
}
}
/*
Sample run:
Enter number of packages purchased:
72
Your discount is: 2851.20
Your total is: 4276.80
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.