Hello,
I mainly wanted some tips and advice on ways to optimize this code, it's actually an exercise from my class' power point file. It says:
Exercise 1
Sam and Ella's Delicatessen wants you to write a program to take orders from the Internet. Your program asks for the item, its price, and if overnight shipping is wanted. 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: 4.50
Overnight delivery (0==no, 1==yes) 1
Invoice:
Tuna Salad 4.50
shipping 7.00
total 11.50
After speaking with my teacher and seeing an example I fixed up my program to look like this:
import java.util.Scanner;
public class Exercise1
{
public static void main(String[] args)
{
double regPrice = 2.00;
double overnightPrice = 0.00;
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter the item: ");
String itemName = keyboard.nextLine();
System.out.println();
System.out.print("Enter the price: ");
double itemPrice = keyboard.nextDouble();
System.out.println();
System.out.print("Overnight delivery (0 == no, 1 == yes): ");
int overnightCheck = keyboard.nextInt();
System.out.println();
if(overnightCheck >= 0 && overnightCheck <= 1)
{
if(overnightCheck == 1)
overnightPrice = 5.00;
}
System.out.println(" Invoice: \n"+
"===================================\n");
System.out.print(itemName);
System.out.printf(" %.2f",itemPrice);
if(itemPrice > 10)
regPrice = 3.00;
System.out.println();
double totalShip = regPrice+ overnightPrice;
System.out.printf("Shipping %.2f",totalShip);
System.out.println();
double totalPrice = itemPrice + totalShip;
System.out.printf("Total %.2f",totalPrice);
}
}