package ecommerce;
import java.util.Scanner;
import java.util.ArrayList;
class Product {
String name;
int quantity;
double price;
Product(){
this.name="Pen";
this.quantity=0;
this.price=0.0;
}
Product(String name,double price) {
this.name=name;
this.price=price;
this.quantity=1;
}
Product(String name,double price,int quantity) {
this.name=name;
this.price=price;
this.quantity=quantity;
}
String getName() {
return name;
}
int getQuantity() {
return quantity;
}
double getPrice() {
return price;
}
double getTotalPrice() {
return quantity*price;
}
void displayProduct() {
System.out.printf("%-15s %-10s %-10s %-10s \n", name ,
quantity ,price, getTotalPrice());
}
}
public class EcommerceOrderingProcessing {
public static void main(String[] args) {
int numberOfproducts;
Scanner sc= new Scanner(System.in);
ArrayList<Product>cart=new ArrayList<>();
System.out.println("Welcome to ecommerce ordering
system");
System.out.print("Enter how many products you
want:");
numberOfproducts=sc.nextInt();
sc.nextLine();
for(int i=0;i<numberOfproducts;i++) {
System.out.println("Enter details for products "+
(i+1)+ ": ");
System.out.print("Product name:");
String name=sc.nextLine();
System.out.print("price:");
double price=sc.nextDouble();
System.out.print("Quantity:");
int quantity=sc.nextInt();
sc.nextLine();
System.out.println("\n");
Product p1 = new Product(name, price, quantity);
cart.add(p1);
}
Product p2 = new Product("Mouse",250,2);
Product p3 = new Product("Pen",15.55,1);
System.out.println("************** INVOICE
***************");
System.out.printf("%-15s %-10s %-10s %-10s \
n","Product","Quantity","price","TotalPrice");
double grandTotal=0;
for (Product key : cart) {
key.displayProduct();
grandTotal += key.getTotalPrice();
}
//Discount policy
double discount = 0.0;
if(grandTotal>=1000) {
discount = 0.15;
}else if (grandTotal>500) {
discount = 0.1;
}
double discountAmount = grandTotal*discount;
double finalTotal = grandTotal - discountAmount;
System.out.println("\n");
System.out.println("Sub total : " + grandTotal);
System.out.println("Discount Amount: "
+discountAmount);
System.out.println("Final Amount : " + finalTotal);
System.out.println("--------------------------");
}
}