Question: Modify your widget order from Week3. Create a method that accepts the number of widgets purchased. Have the method do your math and return a

Modify your widget order from Week3. Create a method that accepts the number of widgets purchased. Have the method do your math and return a double as the order total, using the rules for shipping & tax.

You may name your user created price-determining method whatever you want. Use good naming conventions and a logical name to indicates what the method does.

In your Java class, you'll be working with two methods. In your main method, the following should occur:

  • prompt the user for the number of widgets
  • pass that number as parameters to your method
  • receive a double back from your method and print it out to the console for the user with the DecimalFormat class or printf( )

In your method:

  • do the math to figure out the tax & shipping costs.
  • add everything up
  • return a double that represents the final order total.

Save this file and test with the following test data to verify it is correct. We will add testing to this project after Topic 5.

Test Data #1 Test Data #2

Enter the number of widgets purchased: 5

------------------------

Order Total: $54.70

Enter the number of widgets purchased: 8

------------------------

Order Total: $87.52

Here is my code from Week 3: I need to get this code modified for the requirements above.

import java.util.Scanner;

public class WidgetOrderSivakumar { public WidgetOrderSivakumar(int i, double d) { }

public static void main(String[] args) { final double TAX_RATE = 0.055; final double SHIPPING = 0.1094; int numberofwidgets; double subtotal=0.0; double tax = 0.0; double shipping = 0.0; double total = 0.0; @SuppressWarnings("resource") Scanner sc = new Scanner(System.in); System.out.print("Enter the number of widgets purchased: "); numberofwidgets=sc.nextInt(); System.out.print("Enter the widget order subtotal: "); subtotal=sc.nextDouble(); System.out.printf("Number of widgets purchased: %d ", numberofwidgets); System.out.printf("widget Subtotal:$%.2f ", subtotal); tax = subtotal*TAX_RATE; shipping = subtotal * SHIPPING; total = subtotal + tax + shipping; System.out.printf("Tax: $%.2f ", tax); System.out.printf("Shipping: $%.2f ", shipping); System.out.println("----------------------"); System.out.printf("Order Total :$%.2f ", total); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!