0

We've been assigned to make a primitive shopping cart in Java in my class and I have managed to finish everything with the exception of the Hawaiian sales tax that simply refuses to work properly. I would really be grateful if someone could point out what I did wrong because everybody I ask has no clue what is the problem.

    double IceCreamVanillaPrice = 2.50;
    double IceCreamCCPrice = 4.50;
    double IceCreamOSPrice = 3.25;
    double IceCreamBCPrice = 5.00;


    Scanner getInput = new Scanner(System.in);

    // Setting up the menu
    System.out.println("Hello! Welcome to Neal's Ice Cream Kitchen.");
    System.out.println("What would you like?");
    System.out.println("-----------------------------------------------
    -------");
    System.out.println("(1) Vanilla Ice Cream            $"+ 
    IceCreamVanillaPrice);
    System.out.println("(2) Cookies and Cream Ice Cream  $"+ 
    IceCreamCCPrice);
    System.out.println("(3) Orange Sherbet Ice Cream     $"+ 
    IceCreamOSPrice);
    System.out.println("(4) Berry and Cherry Ice Cream   $"+ 
    IceCreamBCPrice);
    System.out.println("-----------------------------------------------
     -------");
    System.out.println("Enter the number of the Ice Cream you want to 
    order.");



    // Setting up the ordering system and how much they want as well as 
     figuring out the total cost 
    int numIceCream = 0;
    numIceCream = getInput.nextInt();


    // Vanilla Ice Cream

    if (numIceCream == 1) {

       System.out.println("How much Vanilla Ice Cream cones do you 
       want?");
       int numVanilla = getInput.nextInt();
       double SalesTax1 = numVanilla * IceCreamVanillaPrice + 0.04167 ;
       System.out.println("Your total will be $" + SalesTax1); }


      // Cookies and Cream Ice Cream

      else if (numIceCream == 2) {

        System.out.println("How much Cookies and Cream Ice Cream cones 
        do you want?");
        int numCC = getInput.nextInt();
        double SalesTax2 = numCC * IceCreamCCPrice + 0.04167 ;
        System.out.println("Your total will be $" + SalesTax2); }


      // Orange Sherbet Ice Cream

      else if (numIceCream == 3) { 

        System.out.println("How much Orange Sherbert Ice Cream cones do 
         you want?");
        int numOS = getInput.nextInt();
        double SalesTax3 = numOS * IceCreamOSPrice + 0.04167 ;
        System.out.println("Your total will be $" + SalesTax3); }


      // Berry and Cherry Ice Cream

      else if (numIceCream == 4) {

        System.out.println("How much Berry and Cherry Ice Cream cones 
        do you want?");
        int numBC = getInput.nextInt();
        double SalesTax4 = numBC * IceCreamBCPrice + 0.04167 ;
        System.out.println("Your total will be $" + SalesTax4); }

    else {

      System.out.println ("Sorry that is not a Valid Order"); }





   System.out.println("Thank you for shopping at Neal's Ice Cream 
   Kitchen! Have a Nice day!");
    `
Neal. M
  • 5
  • 3
  • 1
    "... refuses to work properly", meaning what, exactly? – Fred Larson Jan 18 '18 at 21:12
  • 3
    Is 0.04167 (which should be a constant, BTW) intended as a tax *rate*, or as a fixed amount? – Fred Larson Jan 18 '18 at 21:16
  • Instead of adding 4.167% of the price to the total, it just adds 0.04167 or something else weird to the end of the total price. So it looks like this... Enter the number of the Ice Cream you want to order. 1 How much Vanilla Ice Cream cones do you want? 1 Your total will be $2.54167 Thank you for shopping at Neal's Ice Cream Kitchen! Have a Nice day! – Neal. M Jan 18 '18 at 21:33
  • You should learn to indent your curly braces properly. This is gonna bite you in the ass at some point. – f1sh Jan 18 '18 at 21:38
  • As @FredLarson noted, a tax rate needs to be *multiplied*, not *added*. `double totalPrice = numberOfCones * pricePerCone * (1 + taxRate);` – Mike Patrick Jan 19 '18 at 00:09

2 Answers2

5

It looks like you're adding 4.167 cents to each order.... You probably want to multiply each order by 1.04167 instead, if you're calculating taxes.

double SalesTax4 = numBC * IceCreamBCPrice * 1.04167;
RAZ_Muh_Taz
  • 4,059
  • 1
  • 13
  • 26
jwismar
  • 12,164
  • 3
  • 32
  • 44
1

I think you need to revisit your tax calculating statement. It should be something like: salestax = numIC * ICPrice * 1.04167; if 4.167% is the fixed ST rate.

AhmadH
  • 76
  • 6