You work for a company that sells widgets. Large widgets sell for $49.99, medium
ID: 3651502 • Letter: Y
Question
You work for a company that sells widgets. Large widgets sell for $49.99, medium widgets for $29.99, and small widgets are $9.99. Additionally, you give discounts for bulk orders. If a customer orders 10-29 widgets (inclusive), you discount 10%. If a customer orders 30-49 widgets, the discount is 20%. If a customer orders 50-69, the discount is 30%. Finally, if the customer orders 70 or more widgets, you give a 40% discount.Write a program that will ask the customer which type of widget they want, how many, and then calculates the bill (including discount), and prints that to the screen.
Explanation / Answer
Please rate...
Program Widgets.java
===============================================
//import scanner
import java.util.Scanner;
public class Widgets
{
//create main method within the class
public static void main(String[] args)
{
//declare variables and strings
double price;
int type;
String name;
//scanner object
Scanner input=new Scanner(System.in);
//Tree type
System.out.print("Widget types 1.Large 2.Medium 3.Small ");
System.out.print("Please enter the type of widget:");
type=input.nextInt();
//if/else statements
if(type==1) { name="Large Widget"; price=49.99; }
else if(type==2) { name="Medium Widget"; price=29.99; }
else if (type==3) { name="Small Widget"; price=9.99; }
else { price=0; name="Invalid"; }
//output
System.out.print("How many do you want of "+name+": ");
int a=input.nextInt();
if(a>=10 && a<=29)price=(price*a)-(0.1*price*a);
if(a>=30 && a<=49)price=(price*a)-(0.2*price*a);
if(a>=50 && a<=69)price=(price*a)-(0.3*price*a);
if(a>=70 )price=(price*a)-(0.4*price*a);
System.out.println("Total cost is: "+price);
}
}
================================================
Sample output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.