Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write each of these methods in the Unit6ProblemSet.java class. When you are fini

ID: 3689341 • Letter: W

Question

Write each of these methods in the Unit6ProblemSet.java class.
When you are finished, compress the Unit6ProblemSet NetBeans folder and submit to the dropbox.
Follow the steps provided in the instructions file of the dropbox.

Exercises to be completed:

1. Write a method called bannerPrinter that takes no parameter and has no return value.
bannerPrinter outputs a greeting to the command line as shown below. (.5 point)

******************************************
****** Welcome to my eCommerce app! ******
******************************************
(print a blank line after the banner)

2. Write a method called productBuilder that takes no parameters and returns an array of Strings.
In the method body construct and return an array of 5 Strings (call the array products) and
populate the array with 5 product names. You don't need to get the values from the user, just
populate with 5 product names. (2 points)

3. Write a method called getOrder that takes an array of Strings as a parameter (the products
array) and returns a boolean. In the method body, prompt the user to enter a product name
(a String), then check whether the product name exists in the array of strings. If it exists,
return true, otherwise return false. (2 points)

4. Write a method called getPrice that returns a double. In the method body generate a random
number between 1 and 100. Use Math.random() multiplied by a scaling factor and return this
value as the price. (1 point)

5. Write a method called getTax that takes a double as a parameter (the price) and returns a
double. Compute the return value as 10% of the parameter value (i.e. 10% of the price).
This is the tax. (1 point)

6. Write a method called getTotal that takes two doubles as parameters (the price and the tax)
and returns a double. The return value is computed as the sum of the two parameters. The
return value is the sale total. (1 point)

7. Write a method called printTotal that takes a double as a parameter (the sale total) and
has no return value. This method outputs the following to the command line:
"Your sale total is: $X" where X is the sale total parameter value. (.5 point)

8. Call each of the methods above from the main method. The pseudocode for the main method
will be as given below. (2 points)

Print the banner message
Get the product array
Get the product order from the user and check it exists in the product array
If the product exists
Get the product price
Compute the product tax
Compute the total sale
Output the total sale
Else
Output "Product not found."

Explanation / Answer

Ans

import java.util.Scanner;

public class Unit6ProblemSet {
   public static void main(String args[]) {
       bannerPrinter();
       String[] productName = productBuilder();
       boolean productExist = getOrder(productName);
       if (productExist) {
           double price = getPrice();
           double tax = getTax(price);
           double total = getTotal(price, tax);
           System.out.println("Total Sale price: "
                   + String.format("%.2f", total));
       } else {
           System.out.println("Product not found.");
       }

   }

   public static void bannerPrinter() {
       System.out.println("******************************************"
               + "****** Welcome to my eCommerce app! ******"
               + "******************************************");
       System.out.println();

   }

   /*****************************************************************************
   * Product Builder Name
   *
   * @return pName: Product name
   *****************************************************************************/
   public static String[] productBuilder() {
       String[] pName = new String[5];
       Scanner scanner = new Scanner(System.in);
       for (int index = 0; index < 5; index++) {
           System.out.print("Enter the product name " + (index + 1) + " : ");
           pName[index] = scanner.nextLine();
       }
       // scanner.close();
       return pName;
   }

   /***
   *
   * @param pName
   * @return
   */
   public static boolean getOrder(String[] pName) {
       String productName = "";
       Scanner scan = new Scanner(System.in);
       System.out.println("Enter the product name : ");
       productName = scan.nextLine();
       for (int index = 0; index < pName.length; index++) {
           if (productName.equals(pName[index])) {
               scan.close();
               return true;
           }
       }
       scan.close();
       return false;
   }

   /***
   *
   * @return
   */
   public static double getPrice() {
       double price = Math.random() * 100.0 + 1.0;
       return price;
   }

   /***
   *
   * @param price
   * @return
   */
   public static double getTax(double price) {
       return (price * 0.10);
   }

   /***
   *
   * @param price
   * @param tax
   * @return
   */
   public static double getTotal(double price, double tax) {
       double total = price + tax;
       return total;
   }

   /***
   *
   * @param total
   */
   public static void printTotal(double total) {
       System.out.println("Your sale total is: $" + total);
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote