You are on page 1of 2

import java.util.

ArrayList;
import java.util.List;
import java.util.Scanner;

class read_shoping {
private int itemno;
private int qty;
private double price;
private double totalPrice;

// constructor
read_shoping(int itemno, int qty,
double price) {
this.itemno = itemno;
this.qty = qty;
this.price = price;
}

// getter methods
public String getitemno() {
return itemno;
}
public int getQty() {
return qty;
}
public double getPrice() {
return price;
}

public void calculate_bill()


{
private double totalPrice;

calculate_bill(double totalPrice)
{
this.totalPrice = totalPrice;
}
public double getTotalPrice()
{
return totalPrice;
}
}

public static void displayFormat() {


System.out.print(
"\nName Quantity Price Total Price\n");
}

// display
public void show_bill() {
System.out.format("%-9s %8d %10.2f %10.2f\n",
pname, qty, price, totalPrice);
}
}
public class Main
{
public static void main(String[] args) {
System.out.println("Welcome to Online Shopping)");
int ItemNo = null;
int quantity = 0;
double price = 0.0;
double totalPrice = 0.0;
double overAllPrice = 0.0;
char choice = '\0';

Scanner scan = new Scanner(System.in);

List<Product> product = new ArrayList<Product>();

do {
// read input values
System.out.println("Enter product details,");
System.out.print("No: ");
ItemNo = scan.nextLine();
System.out.print("Quantity: ");
quantity = scan.nextInt();
System.out.print("Price (per item): ");
price = scan.nextDouble();

// calculate total price for that product


totalPrice = price * quantity;

// calculate overall price


overAllPrice += totalPrice;

read_shoping.add( new read_shoping(


productName, quantity, price) );

// ask for continue?


System.out.print("Want to add more item? (y or n): ");
choice = scan.next().charAt(0);

// read remaining characters, don't store (no use)


scan.nextLine();
} while (choice == 'y' || choice == 'Y');

// display all product with its properties


read_shoping.displayFormat();
for (read_shoping p : read_shoping) {
p.display();
}

// overall price
System.out.println("\nTotal Price = " + overAllPrice);

// close Scanner
scan.close();

}
}

You might also like