Very Complicating Programming Homework?

i am having trouble while trying to code this number in part b
5. “Internet Delicatessen”
a) 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.
Sample output:
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
b) Update the above code to reach the following: Sam and Ella decided to provide different discount percentages depending on the delivery day. Your program should ask (in addition to the above information) the desired delivery day as integer (0: for Monday, 1: for Tuesday, 2: for Wednesday, and so). Discounts are calculated based on the following information:
Monday 10% Tuesday 9% Wednesday 7% Thursday 8% Friday 10% Saturday 9% Sunday 8%
Sample output:
Enter the item: Tuna Salad
Enter the price: 4.50
Overnight delivery (0==no, 1==yes): 1
Enter the delivery day: 0
Invoice:
Tuna Salad 4.50
shipping 7.00
total 11.50
Discount: 1.15
Final Price: 10.35
it displays some errors while using the total again in another “if” i don’t know what to do please help
PS: it’s on netbeans

Both comments and pings are currently closed.

One Response to “Very Complicating Programming Homework?”

  1. Drew says:

    okay first thing I would start with is to use a switch statement for the discounts – makes the code a little more readable than all those if statements. Also when you enter the item you wrote code that would only read one word:
    System.out.println(“Enter The Item:”);
    item = scan.next();
    this will not accept two words like Tuna Salad and result in an error. so change it to
    item = scan.nextLine();
    this way it will accept the whole item you enter.
    You have not clearly explained your problem or error so I cannot help you much with that, for future reference if you want someones help be extremely clear and also show us the error you receive. For the variable not initialized part is because you said for example int i; and then use the var i in an if statement which is all fine and dandy but the compiler wants to know what the value of i is if it doesn’t make the if statement. you can see in the code below I resolved that problem by setting a few variables to default values such as discount = 0.0
    Here is your code revised with the above mentions. Please do not just copy it and submit it. Try to understand it, rewrite it yourself and if you do not understand what is going on or have questions please send me some mail. Thanks have a good one.
    import java.util.Scanner;
    import java.text.*;
    public class invoiceExample {
    public static void main(String [] args) {
    double price,shipping,subTotal,discount,total;
    int overnight,deliveryDay;
    String item;
    //for formatting the output to currency.
    NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance();
    Scanner scan = new Scanner (System.in);
    System.out.println(“Enter The Item:”);
    item = scan.nextLine();
    System.out.println(“Enter the Price:”);
    price = scan.nextDouble();
    System.out.println(“Overnight delivery (0==no, 1==yes):”);
    overnight = scan.nextInt();
    System.out.println(“Enter the delivery day:”);
    deliveryDay = scan.nextInt();
    shipping = 0.00;
    if(price < 10.00){ shipping = 2.00; if(overnight == 1.00){ shipping = 7.00; } } if(price >=10){
    shipping = 3.00;
    if(overnight == 1){
    shipping = 8.00;
    }
    }
    discount = 0.0;
    subTotal = price + shipping;
    switch (deliveryDay) {
    case 0: discount = (subTotal*.10);
    break;
    case 1: discount = (subTotal*.09);
    break;
    case 2: discount = (subTotal*.07);
    break;
    case 3: discount = (subTotal*.08);
    break;
    case 4: discount = (subTotal*.10);
    break;
    case 5: discount = (subTotal*.09);
    break;
    case 6: discount = (subTotal*.08);
    break;
    }
    total = (subTotal – discount);
    System.out.println(item + “: ” + currencyFormatter.format(price));
    System.out.println(“Shipping: “+ currencyFormatter.format(shipping));
    System.out.println(“Sub Total: ” + currencyFormatter.format(subTotal));
    System.out.println(“Discount: ” + currencyFormatter.format(discount));
    System.out.println(“Total: ” + currencyFormatter.format(total));
    }
    }

Powered by WordPress | Designed by: free css template | Thanks to hostgator coupon and web hosting reviews