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

JAVA PROGRAMING 2)A store sells candy bars for $1.00 each. If the store owner bu

ID: 639088 • Letter: J

Question

JAVA PROGRAMING

2)A store sells candy bars for $1.00 each. If the store owner buys in bulk from his supplier, she gets a

discount on the bars as shown in the table below

The price per bar is $0.27 when there is no discount.

Write a program that

a) asks for the number of bars to be purchased from the supplier

b) calculates the discount percentage

c) prints the total price, the discount percentage, and the discounted price

d) determines the profit if all of the purchased bars are sold

This is the format professor wants:

import java.util.Scanner;

public class DairyCalculator {

public static void main(String[] args) {

// We use a scanner to read input from the command line

Scanner scn = new Scanner(System.in);

System.out.println("Enter the amount of milk produced:");

double amountProduced = scn.nextDouble();

// Calculate the required values here and print the results

scn.close();

}

}

quantity Purchased Discount <100 None 100-199 10% 200-299 20% 300-399 25% 400 or more 30%

Explanation / Answer

import java.util.Scanner;

public class DairyCalculator {

public static void main(String[] args) {

// We use a scanner to read input from the command line

Scanner scn = new Scanner(System.in);

System.out.println("Enter the amount of milk produced:");

double amountProduced = scn.nextDouble();

double buyPricePerBar=.27;
double sellPricePerBar = 1;
double percentage;

if(amountProduced < 100)
{
percentage = 0;
}
else if(amountProduced <= 199)
{
percentage = 10;
}
else if(amountProduced <= 299)
{
percentage = 20;
}
else if(amountProduced <= 399)
{
percentage = 25;
}
else
{
percentage = 30;
}

double total = sellPricePerBar * amountProduced;

double discount = (percentage*total)/100.0;

double netTotal = total - discount;

double profit = netTotal-(buyPricePerBar * amountProduced);
System.out.println("Total price = $"+total);
System.out.println("Discount percentage = "+percentage+"%");
System.out.println("Net price = $"+netTotal);
System.out.println("Profit = $"+profit);


// Calculate the required values here and print the results

scn.close();

}

}

---------------------

OUTPUT

Enter the amount of milk produced:                                         

222                                                                        

Total price = $222.0                                                       

Discount percentage = 20.0%                                                

Net price = $177.6                                                         

Profit = $117.66