5.3k views
1 vote
• Open your Netbeans IDE and answer the following question

• Create a folder on the desktop. Rename it with your student name and student number
• Save your work in the folder you created.
At a certain store they sell blank CDs with the following discounts:
* 10% for 120 or more
* 5% for 50 or more
* 1% for 15 or more
* no discount for 14 or less
Write a program that asks for a number of discs bought and outputs the correct discount. Use either a switch statement or if..elseif.. ladder statements. Assuming that each blank disk costs N$3.50. The program should then calculate the total amount paid by the buyer for the discs bought.

User Ionut
by
5.4k points

1 Answer

6 votes

Answer:

public static void main(String[] args)

{

int cdCount;

double cdCountAfterDiscount;

DecimalFormat df = new DecimalFormat("$##.##"); // Create a Decimal Formatter for price after discount

System.out.println("Enter the amount of CD's bought");

Scanner cdInput = new Scanner(System.in); // Create a Scanner object

cdCount = Integer.parseInt(cdInput.nextLine()); // Read user input

System.out.println("CD Count is: " + cdCount); // Output user input

if(cdCount <= 14 )

{

System.out.println("There is no discount");

System.out.println("The final price is " + cdCount*3.5);

}

if(cdCount >= 15 && cdCount<=50)

{

System.out.println("You have a 1% discount.");

cdCountAfterDiscount = (cdCount *3.5)-(3.5*.01);

System.out.println("The final price is " + df.format(cdCountAfterDiscount));

}

if(cdCount >= 51 && cdCount<120)

{

System.out.println("You have a 5% discount.");

cdCountAfterDiscount = (cdCount *3.5)-(3.5*.05);

System.out.println("The final price is " + df.format(cdCountAfterDiscount));

}

if(cdCount >= 120)

{

System.out.println("You have a 10% discount.");

cdCountAfterDiscount = (cdCount *3.5)-(3.5*.1);

System.out.println("The final price is " + df.format(cdCountAfterDiscount));

}

}

User Bjnord
by
5.6k points