Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.Scanner;// import the Scanner public class BestPurchaseOnline { //class method public static void main(String[] args) { /*this program computes the online order from customer

import java.util.Scanner;// import the Scanner

public class BestPurchaseOnline { //class method public static void main(String[] args) { /*this program computes the online order from customer selections, which inlcude total items ordered, total price of order with and without sales tax */ Scanner input = new Scanner(System.in);// create the Scanner //Declare the variables String sName = "";//variable for customer name int nItem = 0; // variabel for item selected int nCount = 0; // variable for number of items ordered. double dTotalAmountDue = 0.0; // variable for total amount due + sales tax double dAmountBeforeSalesTax = 0.0; // variable for amount due before sales tax double dAmountAfterSalesTax = 0.0; //Declare Constant final int SENTINEL = 10; // value to end number of item final int SMARTPHONE_PRICE = 249; final int SMARTPHONE_CASE_PRICE = 39; final int PC_LAPTOP_PRICE = 1149; final int TABLET_PRICE = 349; final int TABLET_CASE_PRICE = 49; final int eREADER_PRICE = 119; final int PC_DESKTOP_PRICE = 899; final int LED_MONITOR_PRICE = 299; final int LASER_PRINTER_PRICE = 399; final double dSalesTax = 0.065; // variable for tax of sale System.out.print("Please enter your name: "+sName);// prompt the user to enter name sName = input.nextLine(); System.out.println(" BEST PURCHASE PRODUCTS"); //Menu selection for item to purchase System.out.println("1. Smartphone $249"); System.out.println("2. Smartphone case $39"); System.out.println("3. PC Laptop $1149"); System.out.println("4. Tablet $349"); System.out.println("5. Tablet case $49"); System.out.println("6. eReader $119"); System.out.println("7. PC Desktop $899"); System.out.println("8. LED Monitor $299"); System.out.println("9. Laser Printer $399"); System.out.println("10.Complete my order"); System.out.println("Please select an item from the menu above: ");//prompt user to select an item nItem = input.nextInt(); // start of loop while(nItem!=SENTINEL){ // Start of Loop aslong as user does not enter SENTINEL value nCount++; // nCount = nCount + 1, keeping track of number of items being odered. if(nItem==SMARTPHONE_PRICE) // if user enters 1 it assigns the value of 249 dAmountBeforeSalesTax = dAmountBeforeSalesTax + SMARTPHONE_PRICE; else if(nItem==SMARTPHONE_CASE_PRICE) dAmountBeforeSalesTax = dAmountBeforeSalesTax + SMARTPHONE_CASE_PRICE; else if (nItem==PC_LAPTOP_PRICE) dAmountBeforeSalesTax = dAmountBeforeSalesTax + PC_LAPTOP_PRICE; else if (nItem==TABLET_PRICE) dAmountBeforeSalesTax = dAmountBeforeSalesTax + TABLET_PRICE; else if (nItem==TABLET_CASE_PRICE) dAmountBeforeSalesTax = dAmountBeforeSalesTax + TABLET_CASE_PRICE; else if (nItem==eREADER_PRICE) dAmountBeforeSalesTax = dAmountBeforeSalesTax + eREADER_PRICE; else if (nItem==PC_DESKTOP_PRICE) dAmountBeforeSalesTax = dAmountBeforeSalesTax + PC_DESKTOP_PRICE; else if (nItem==LED_MONITOR_PRICE) dAmountBeforeSalesTax = dAmountBeforeSalesTax + LED_MONITOR_PRICE; else if(nItem==LASER_PRINTER_PRICE) dAmountBeforeSalesTax = dAmountBeforeSalesTax + LASER_PRINTER_PRICE; System.out.println("Please select another item from the menu above: ");// prompt user to enter another item. nItem = input.nextInt(); }// comment System.out.println("Thank you for ordering with Best Purchase, "+sName);// thanks the customer for ordering System.out.println("Total items ordered: "+nCount);// displays the number of items being ordered. System.out.println("Price of items ordered:$ "+ dAmountBeforeSalesTax);// displays the total of items ordered before tax dAmountAfterSalesTax = (dSalesTax * dAmountBeforeSalesTax);// Displays the total amount with tax. System.out.println("Sales Tax:$ "+dAmountAfterSalesTax); dTotalAmountDue = (dSalesTax + dAmountBeforeSalesTax);// displays the total amount due with tax. System.out.println("Total amount due:$ "+dTotalAmountDue); }// end main method }// end class BestPurchaseOnline

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

Essential Data Protection For Estate Agencies In Singapore 2024

Authors: Yang Yen Thaw Yt

1st Edition

B0CQK79WD3, 979-8872095392

More Books

Students also viewed these Databases questions

Question

2. What would you do first if you were Jennifer?

Answered: 1 week ago

Question

Make efficient use of your practice time?

Answered: 1 week ago