Help with the Internet Deli Program

Exercise 1 — Internet Delicatessen

You have been asked to write a program for the Sam and Ella Delicatessen. The program takes deli orders from the Internet. It asks for the item, its price in cents, and if overnight shipping is wanted. The program writes out the order and the charges. Regular shipping for items under $10 is $2.00; for items $10 or more shipping is $3.00. For overnight delivery add $5.00.

Enter the item: Tuna Salad
Enter the price: 450  
Overnight delivery (0==no, 1==yes): 1    

Invoice:    
Tuna Salad    4.50    
shipping      7.00    
total         11.50  
deli flowchart

You need 1 String variable (for the name of the food item) and 2 integers (for the price and shipping) to get the input

Declare them first

Use nextLine() to read in Strings

Use nextInt() to read in integers

Use your Echo and Last Chance gas programs for examples of how to get String and integer input.

 

 

 

 

 

if(price >=1000)
   shippingCost = 300;
else
   shippingCost = 200;

 

 

 

 

Notice you need to have a variable named shippingCost already declared before you get to this statement.

 

 

 

 

 

to add $5 to the shipping cost you say
shippingCost = shippingCost + 500;

There is no "else" for this option, shippingCost stays the same if overnight is not selected

 

To print the receipt you have to divide the integers by 100.0 (with a decimal point) so it will show dollars and cents

To line up the numbers on the receipt use \t as a tab