Your program is going to calculate the price of some bags of coffee. You will fi
ID: 3599115 • Letter: Y
Question
Your program is going to calculate the price of some bags of coffee. You will first ask the user; how many bags of coffee do they want. The price per bag is $5.50 each. Your price must also include the shipping of how many boxes this shipment will require. There are three size shipping boxes available. A large box can hold 20 bags, a medium box holds 10 bags, and a small box can hold up to 5 bags. You cannot ship large or medium boxes that are not full. (but small ones can have 1-5 bags in them) The price of shipping per box is large = $1.80, medium = $1.00, and small = $0.60 . You also give a discount on the coffee for large quantities. Use the following chart to calculate the discount off of the coffee price (NOT off the shipping). 0-24 bags - no discount 150-199 bags - 20% discount 25-49 bags – 5% discount 200-299 bags - 25% discount 50-99 bags – 10% discount 300 and up - 30% discount 100-149 bags – 15% discount Discount is not to be used on the boxes. Use if statements or a switch statement to get this done. Figuring out the number of boxes is similar to our change program. See example at bottom for what output should look like. write in java.
Explanation / Answer
import java.util.*;
class coffee
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter number of pouches: ");
int n=sc.nextInt(); //Input the value
System.out.println("Total is "+(discount(n)+boxes(n)));
}
public static double discount(int n)
{
double total=n*5.50;
double amount=0;
if(n<25) //if clause for proper discount as per number of packets of coffee
{
amount=total;
}
else if(n<50)
amount=total-total*(.05);
else if(n<100)
amount=total-total*(.10);
else if(n<150)
amount=total-total*(.15);
else if(n<200)
amount=total-total*(.20);
else if(n<300)
amount=total-total*(.25);
else
amount=total-total*(.30);
return amount; //returning value after discount
}
public static double boxes(int n)
{
double amount=0;
while(n>0) //if clause to decide type of packets
{
if(n>=20)
{
n-=20;
amount+=1.80;
}
else if(n>=10)
{
n-=10;
amount+=1.00;
}
else if(n>=5)
{
n-=5;
amount+=0.60;
}
else
{
amount+=0.60;
n=0;
}
}
return amount; //returning total shipping cost
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.