Program Specification: A online retailer has hired you to write a program to cal
ID: 3639078 • Letter: P
Question
Program Specification:A online retailer has hired you to write a program to calculate the total cost of a customer's order. First, the retailer must enter the name and the price per unit for two different candies. Then, the customer is allowed to order as many units of each of the two candies as they would like. Lastly, an invoice (report) is generated (displayed to the screen) under the following rules:
* All units up to and including the 10th are sold at full price.
* All unit in excess of 10 are sold at a 10% discount.
* For each candy there must be a separate line indicating:
1. Its name
2. Its full unit price
3. How many units are being sold at full unit price
4. The resulting sub total
And if applicable, another line indicating:
1. Candy name
2. Discounted unit price
3. How many units are being sold at discounted unit price
4. The resulting sub total
* There must be final line indicating the grand total of the order.
Write a Java program that satisfies the above description.
Requirements:
1. All values obtained from the user must be stored in an appropriately typed variable.
Sample run(s):
Welcome to the CS201 Online Store
---------------------------------
Retailer ...................
Please enter the name of first Candy: Red-Hots
Please enter the price (per unit) of Red-Hots $1.50
Please enter the name of second Candy: Mike-N-Ikes
Please enter the price (per unit) of Mike-N-Ikes $2.00
Consumer ...................
Enter number of units of Red-Hots to purchase: 10
Enter number of units of Mike-N-Ikes to purchase: 15
Order Summary ..............
Candy Units Price/Unit cost
----------------------------------------------
Red-Hots 10 $1.5 $15.0
Mike-N-Ikes 10 $2.0 $20.0
Mike-N-Ikes 5 $1.8 $9.0
----------------------------------------------
Total order cost $44.0
Explanation / Answer
please rate - thanks
if any problems please message me before rating-thanks
import java.util.*;
public class store
{public static void main(String[] args)
{String name1,name2;
double price1,price2,t1,t2,total;
int amount1,amount2;
Scanner in=new Scanner(System.in);
System.out.println("Welcome to the CS201 Online Store");
System.out.println("--------------------------------- ");
System.out.println("Retailer ................... ");
System.out.print("Please enter the name of first Candy: ");
name1=in.next();
System.out.print("Please enter the price (per unit) of "+name1+" $");
price1=in.nextDouble();
System.out.print("Please enter the name of second Candy: ");
name2=in.next();
System.out.print("Please enter the price (per unit) of "+name2+" $");
price2=in.nextDouble();
System.out.println(" Consumer ................... ");
System.out.print("Enter number of units of "+name1+" to purchase: ");
amount1=in.nextInt();
System.out.print("Enter number of units of "+name2+" to purchase: ");
amount2=in.nextInt();
System.out.println(" Order Summary ................... ");
System.out.println("Candy Units Price/Unit cost ");
System.out.println("--------------------------------- ");
t1=output(name1,amount1,price1);
t2=output(name2,amount2,price2);
total=t1+t2;
System.out.println("--------------------------------- ");
System.out.println("Total order cost $"+total);
}
public static double output(String name,int amount,double price)
{double total=0,discount=0,cost,disPrice;
if(amount<=10)
{
cost=amount*price;
System.out.println(name+" "+amount+" "+price+" $"+cost);
}
else
{cost=10*price;
disPrice=price*.9;
discount=(amount-10)*disPrice;
System.out.println(name+" "+amount+" "+price+" $"+cost);
System.out.println(name+" "+(amount-10)+" "+disPrice+" $"+discount);
}
total=cost+discount;
return total;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.