Answered! need some help with this java Program please. Write a program (ProductsInvoice.java) that…

need some help with this java Program please.

Write a program (ProductsInvoice.java) that will first input (read from the console) the name and address of a store (e.g., BestBuy, Cub Foods, etc). Then it will input the name, quantity, and the price of three products. The name and address of the store and the product’s name may contain spaces.

Don't use plagiarized sources. Get Your Custom Essay on
Answered! need some help with this java Program please. Write a program (ProductsInvoice.java) that…
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS $13/PAGE
Order Essay

Output an invoice with the store’s name and address on the top right corner followed by the three products in three different lines. In each line display the name, the price, the quantity and the total. You need to calculate the total, which is the price multiplied by the quantity. You will also need to output the following:

Subtotal: this is the product’s total before tax.

Sales Tax: use 7.625% for the tax rate.

Total: this is the total after tax.

All prices, totals and subtotal should be displayed in US currency format (e.g., $1,000). The invoice should be formatted in columns with 70 characters for the store’s name, 70 characters for the store’s address, 30 characters for the product’s name, 10 characters for the product’s quantity, 15 characters for product’s price, and 15 characters for the product’s total.

Formatting: For the prices, totals and subtotal use NumberFormat class and to display the invoice using columns use printf.

Input Validation: your program should NOT accept negative values and empty strings. When the user enters an invalid input your program should ask him/her to try again (See the second screed shot below).

here is how the ouput should look like!

Enter Stores name: Apple Store Enter Stores address: 1234 grand ave, St Paul MN 55112 Enter details of product 1 Name: Iphone 6s Price: 699.99 Quantity: Enter details of product 2 Name Apple Watch S2 Price 399.99 Quantity: Enter details of product 3 Name Apple Tv Price: 299.99 Quantity: Iphone 6s Apple Watch S2 Apple TV Subtotal Sales Tax (7.625% Total Apple Store 1234 grand ave, St Paul MN 55112 $699.99 $699.99 $399.99 $799.98 $299.99 $899.97 $2,399.94 $183.00 $2,582.94

Expert Answer

Java Program:

import java.util.*;
import java.text.*;

//Class definition
class ProductInvoice
{
//Main function
public static void main(String args[])
{
//String for storing store name and store address
String storeName, storeAddress;

//Array for Name
String[] name = new String[3];

//Array for Price
double[] price = new double[3];

//Array for Quantity
int[] qty = new int[3];

Scanner sc = new Scanner(System.in);

//Reading store name
System.out.println(“nn Enter Store’s name: “);
storeName = sc.nextLine();

//Reading store address
System.out.println(“nn Enter Store’s address: “);
storeAddress = sc.nextLine();

int i;

//Reading three product details
for(i=0; i<3; i++)
{
System.out.println(“nn Enter details of product ” + (i+1));

//Reading name
System.out.println(“n Name: “);
name[i] = sc.nextLine();

//Reading price
System.out.println(“n Price: “);
price[i] = sc.nextDouble();

//Reading quantity
System.out.println(“n Quantity: “);
qty[i] = sc.nextInt();

sc.nextLine();
}

double subTotal=0, salesTax=0, total;

//Printing store name and address
System.out.printf(“nnn %70s “, storeName);
System.out.printf(“n %70s n”, storeAddress);

//Processing product details
for(i=0; i<3; i++)
{
//Printing product details
System.out.printf(“n %30s %6d %7c %s %7c %s n”, name[i], qty[i], ‘$’, NumberFormat.getNumberInstance(Locale.US).format(price[i]), ‘$’, NumberFormat.getNumberInstance(Locale.US).format((price[i] * qty[i])));
subTotal += price[i] * qty[i];
}

//Calculating sales tax
salesTax = subTotal * (7.625 / 100.0);

//Calculating total
total = subTotal + salesTax;

//Printing tax and total
System.out.printf(“nn %30s %29c %s “, “Subtotal”, ‘$’ , NumberFormat.getNumberInstance(Locale.US).format(subTotal));
System.out.printf(“nn %30s %29c %s “, “Sales Tax (7.625%)”, ‘$’ , NumberFormat.getNumberInstance(Locale.US).format(salesTax));
System.out.printf(“nn %30s %29c %s nn”, “Total”, ‘$’ , NumberFormat.getNumberInstance(Locale.US).format(total));
}
}

___________________________________________________________________________________________

Sample Output:

Answered! need some help with this java Program please. Write a program (ProductsInvoice.java) that... 1

Still stressed from student homework?
Get quality assistance from academic writers!