Computer Science, asked by beastgamerz59, 1 month ago

Develop a JAVA program for a shopkeeper which helps him to

generate the bill for the customer by accepting the customer

name,his address, his tel. No., the items purchased, their unit price

and the quantity of each item and compute the bill amount assuming

the customer has bought three item. Display the bill with all the

information like shop name, tel no. Of shop, customer name, his

address, his tel no. , the items purchased, unit price of each item and

quantity and the total for each item as well as the total bill amount in

proper foramt like a bill you see when you buy something from shop. The description of variables should be written ​

Answers

Answered by GlimmeryEyes
2

Answer:

package com.know.shop;

import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;

class Product {

// properties

private String pname;

private int qty;

private double price;

private double totalPrice;

// constructor

Product(String pname, int qty,

double price, double totalPrice) {

this.pname = pname;

this.qty = qty;

this.price = price;

this.totalPrice = totalPrice;

}

// getter methods

public String getPname() {

return pname;

}

public int getQty() {

return qty;

}

public double getPrice() {

return price;

}

public double getTotalPrice() {

return totalPrice;

}

// displayFormat

public static void displayFormat() {

System.out.print(

"\nName Quantity Price Total Price\n");

}

// display

public void display() {

System.out.format("%-9s %8d %10.2f %10.2f\n",

pname, qty, price, totalPrice);

}

}

public class ShoppingBill {

public static void main(String[] args) {

// variables

String productName = null;

int quantity = 0;

double price = 0.0;

double totalPrice = 0.0;

double overAllPrice = 0.0;

char choice = '\0';

// create Scanner class object

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("Name: ");

productName = 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;

// create Product class object and add it to the list

product.add( new Product(

productName, quantity, price, totalPrice) );

// 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

Product.displayFormat();

for (Product p : product) {

p.display();

}

// overall price

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

// close Scanner

scan.close();

}

}

Answered by seenmp1975
0

Answer:

Develop a JAVA program for a shopkeeper which helps him to generate the bill for the customer by accepting the customer name,his address, his tel. No., the items purchased, their unit price and the quantity of each item and compute the bill amount assuming the customer has bought three item. Display the bill with all the information like shop name, tel no. Of shop, customer name, his address, his tel no. , the items purchased, unit price of each item and quantity and the total for each item as well as the total bill amount in proper foramt like a bill you see when you buy something from shop. The description of variables should also be wwritt

{ How to Write an Invoice

Create a Professional Layout.

Include Company and Client Information.

Add an Invoice Number, Invoice Date, and Due Date.

Write Each Line Item with a Description of Services.

Add-up Line Items for Total Money Owed.

Include Simple Payment Terms and Payment Options.

Add a Personal Note.}

( hope it's correct)

hope it's helpful...

Similar questions