Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I made it this far but I'm not sure what else this is asking for...Include a method called productsBuilder that takes no parameters and returns

I made it this far but I'm not sure what else this is asking for...Include a method called productsBuilder that takes no parameters and returns a String. In the method body construct a String (name it productsCatalog) and populate it with items, each of which must be 10 characters long. For any product less than 10 characters, pad the remainder with spaces. You don't need to get the values from the user, just populate the String with 3 product names. For example, product 1 might be "Desk ", product 2 might be "Table ", and product 3 might be "Pen ". All 3 of these products are within the productsCatalog String.

package ecommerceapp; import java.util.Scanner; import java.util.Random;

public class ECommerceApp {

public static String productsBuilder() { return "Table, Desk, Chair"; } public static boolean getOrder(String name) //Getting product name from the user { return productsBuilder().contains(name); //If found returns true, if not returns false } public static double getPrice() { Random rand = new Random(); //Getting a random price between 1 and 100 return rand.nextInt((100 - 1 + 1)) +1; } public static double getTax(double price) { return (price * 10.0 / 100.0); //10% tax of the price } public static double getTotal(double price, double tax) { return price + tax; //Returns the sum of price and the tax } public static void printTotal(double total) { System.out.println(String.format("Your sale total is $%.2f",total)); //Prints out the total of the item in the catalog } public static void main(String[] args) { //Printing the banner String productsCatalog = productsBuilder(); System.out.print("Enter the product name for order: "); //Getting input from the user String orderName = new Scanner(System.in).next(); System.out.println("****************************************** " + "====== Welcome to my eCommerce app! ====== " + "******************************************"); System.out.println(); if(getOrder(orderName)) { double price = getPrice(); double tax = getTax(price); double total_sale = getTotal(price, tax); printTotal(total_sale); } else { System.out.println("The product was not found."); } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administration The Complete Guide To Dba Practices And Procedures

Authors: Craig S. Mullins

2nd Edition

0321822943, 978-0321822949

More Books

Students also viewed these Databases questions