JAVA Write a program in Java using eclipse that will first i

JAVA:

Write a program in Java using eclipse that will first input (read from the console) the name and address of a store. 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. 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. Here is how you program should work (Simple input and output are shown in the following screen shot):

Console X sterminated> Invoice Dava Application] 1Librarylava/JavavirtualMachines/idk1.8.0 31.jdk/Contents/Home/bin/java Jan Input store\'s name: My Electronics Input Store\'s address: mpls, MN 55116 Enter details of product 1 Name Iphone 6s Plus Price 699.99 Quantity: Enter details of product 2 Name: Smart TV 55 Price 1299.89 Quantity: Enter details of product 3 Name: Raspberry P Price: 35.99 Quantity: My Electronics mpls, MN 55116 Iphone 6s Plus $1,399.98 $699.99 Smart TV 55 $1,299.89 $1,299.89 $35.99 $143.96 Raspberry PI Subtotal $2,843.83 Sales Tax C7.625%D $216.84 Total $3,060.67

Solution

import java.io.*;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.*;

public class Solution {

  
   public static void main(String arg[])
   {
      
       NumberFormat formatter = NumberFormat.getCurrencyInstance();
      
      
      
      
   Scanner sc=new Scanner(System.in);
      
   System.out.println(\"Input store\'s name:\");
   String name=sc.nextLine();
   System.out.println(\"Input store\'s address\");
   String address=sc.nextLine();
  
   String productName[]=new String[3];
   double productPrice[]=new double[3];
   double productQuantity[]=new double[3];
   double total[]=new double[3];
  
   for(int i=0;i<3;i++)
   {
   System.out.println(\"\\tEnter details of Product \"+(1+i));
   System.out.println(\"name:\");
   productName[i] =sc.next();
   System.out.println(\"Price:\");
   productPrice[i]=sc.nextDouble();
   System.out.println(\"Quanty:\");
   productQuantity[i]=sc.nextDouble();
   total[i]=productPrice[i]*productQuantity[i];
  
   }

   System.out.printf(\" %70.70s%n\", name);
   System.out.printf(\" %70.70s%n\", address);
  
  
  
   for(int i=0;i<3;i++){
      
       System.out.printf(\" %30.30s\", productName[i]);
       System.out.printf(\" %10.10s\", productQuantity[i]);
       System.out.printf(\" %15.15s\", formatter.format(productPrice[i]));
       System.out.printf(\" %15.15s%n\", formatter.format(total[i]));
      
  
   }
  
   double subTotal=total[0]+total[1]+total[2];
  
   System.out.printf(\" %60.50s\", \"Subtotal\");
   System.out.printf(\" %12.12s%n\", formatter.format(subTotal));
   System.out.printf(\" %73.73s%n\", formatter.format(subTotal*7.625/100));
   System.out.printf(\" %73.73s%n\", formatter.format(subTotal*7.625/100+subTotal));
  
  
  
  
          
  
   }
  
   }

JAVA: Write a program in Java using eclipse that will first input (read from the console) the name and address of a store. Then it will input the name, quantity
JAVA: Write a program in Java using eclipse that will first input (read from the console) the name and address of a store. Then it will input the name, quantity

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site