Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 36

St.

Xavier’s School, Burdwan


ICSE Project for 2022

Computer Applications
Programming in Java with BlueJ

Class – 10
Section – C
Roll No. – 44
UID – 7724045
Name – Diganta Pal

Topic – Grocery Bill Generation

Date of Submission 10/07/2021

Signature of Examiner with Date


Preface
This project has been prepared keeping in view the
requirements of the Indian Certificate of Secondary
Education (ICSE), New Delhi.
This project deals with the use of the concept of Grocery Bill
Generation by using a Java program. The features of OOP are
also used for the better understanding of the program. User
defined functions, comments, variable description, algorithm
and input/output screenshots are provided for the easy and
clear understanding of the program. The logic is coded as
simple as possible for the easier and faster understanding of
the program and it is also ensured that one can develop
his/her own program using this concept by understanding
this project.
All suggestions for the improvement of this project will be
gratefully acknowledged.
Acknowledgement
I would like to express my special thanks of gratitude to my
Computer teacher, Mr. Bhattacharya as well as our principal,
Rev. Fr. Dr. Maria Joseph S, S.J. who gave me the golden
opportunity to do this wonderful project on the concept of
Grocery Bill Generation which also helped me in doing a lot
of research and I came to know about so many things, so I
am really thankful to them. Secondly, I would like to thank
my parents, friends and other classmates who helped me a
lot in finalising this project within the limited time frame. But,
above all I would like to express my special thanks of
gratitude to the Almighty God, without Him, this project
would not be successful.

DATE: 01/07/2020 Diganta Pal


X-C, 44
Contents

Sl. No. Topic Page No.

1. Algorithm 1
2. Source Code 6

3. Variable Description 19
4. Input and Output Screenshots 21

5. Conclusion 32
Question: Develop a Java program using BlueJ on the
concept of “Grocery Bill Generation”.

Algorithm
1. All classes from I/O Java package are imported.
2. A public class named “Test_Grocery_Store” is declared.
3. A method named “test_Method ()” is declared within that
class.
4. An object named “obj” is created.
5. The first method “allMethods ()” of “Grocery_Store” class
is called and is linked with the just created object using dot
operator.
6. The method and class is ended.
7. All classes from I/O Java package are again imported.
8. A class named “Grocery_Store” is declared.
9. An object named “r” is created using BufferedReader.
10. An array “item[]” is created of String datatype and
initialized with the names of the items available.
11. An array “price[]” is created of int datatype and
initialized with the costs of the items.
12. A variable “customer_name” of String datatype is
declared and initialized as null.
13. A variable “customer_phno” of long datatype is declared
and initialized with 0L.
14. Variables “choice_item”, “ch”, “choice”,
“items_ordered” of String datatype are declared and all
are initialized as null.
15. Variables “qty”, “srch_index”, “bill_no” of int datatype
are declared and variables “qty” and “srch_index” are
initialized with 0 while variable “bill_no” is initialized with
5301 (for example; user can take any value as bill number
of their choice).
16. Variables “totamt”, “gst”, “grand_total” of double
datatype are declared and all are initialized with 0.0.
17. A variable “flag” of boolean datatype is declared and
initialized with ‘true’.
18. A method “allMethods()” is declared where all the other
methods of the class are encapsulated.
19. The method is ended.
20. A method “stcal()” is declared.
21. A for loop is started from i=0 up to i<60 where i is a
variable of int datatype and i increases one by one.
22. A variable “l” of int datatype is declared and initialized
with the value of the length of the name of the item
coming at index i in the “item[]” array.
23. A for loop is started from j=l up to j<=30 where j is a
variable of int datatype and j increases one by one.
24. A number of blank spaces are added beside the name of
the item coming at index i in the “item[]” array, which
depends on how many times the j loop is executed.
25. The j loop is ended.
26. The i loop is ended.
27. The “stcal()” method is ended.
28. A method “calculate()” is declared.
29. A do-while loop is started. The true part will be executed
once before coming to the condition. Then, again the true
part will be executed if there is another customer
otherwise the control will proceed to the next line.
30. In the true part, the necessary things to be displayed are
printed.
31. A for loop is started from i=0 up to i<60 where i is a
variable of int datatype and i increases one by one.
32. If i is exactly divisible by 2 then the control is directed to
come to the next line using “System.out.println();”
statement.
33. The item name and the item price at the index i in the
“item[]” and “price[]” arrays are printed in proper way.
34. The i loop is ended.
35. The “customer_name” variable is initialized with the
name of customer given by the user.
36. The “customer_phno” variable is initialized with the
phone number of customer given by the user.
37. Other necessary adjustments are made.
38. A do-while loop is started. The true part will be executed
once before coming to the condition. Again, the true part
will be executed if there is another item to be purchased
otherwise, the control will proceed to the next line.
39. In the true part of the second do-while-loop, the
“choice_item” variable is initialized with the name of the
item to be purchased given by the user.
40. A for loop is started from i=0 up to i<60 where i is a
variable of int datatype and i increases one by one.
41. If the item to be purchased is available at the store, then
the ‘srch_index” variable is initialized with i, the “flag”
variable is initialized with false and the “break” statement
is written.
42. The i loop is ended.
43. If the value of “flag” variable remains true i.e. the item is
not found, then the necessary message is printed.
44. If the value of “flag” variable is false i.e. the item is
available, then the “qty” variable is initialized with the
number of that item to be purchased given by the user.
The “totamt” variable is initialized with the total cost of all
the items bought by the customer without GST. The
“items_ordered” variable is initialized with the necessary
things to be printed in the bill in a particular order.
45. The message “Is there any more item to be purchased ?
Type ‘yes’ to confirm.” is printed.
46. The “ch” variable is initialized with either ‘yes’ or ‘no’ as
given by user.
47. The “flag” variable is initialized with “true”.
48. The second do-while loop is ended.
49. The condition to check that the “ch” variable contains
‘yes’ or not is given here.
50. The “gst” and “grand_total” variables are initialized with
the necessary values. The GST is calculated by multiplying
0.18 with the total price of all the items to be purchased.
The grand total is calculated by adding the total price of
the items and the GST.
51. The bill is printed with all the necessary details.
52. After all, the statement “Is there any more customer ?
Type ‘yes’ to confirm.” is printed.
53. The “choice” variable is initialized with either ‘yes’ or
‘no’ as given by the user.
54. The “bill_no” variable is increased by one.
55. The “totamt”, “gst” and “grand_total” variables are
initialized with 0.0.
56. The “items_ordered” variable is initialized as null.
57. The first do-while loop is ended.
58. The condition to check that the “choice” variable
contains ‘yes’ or not is given here.
59. The “calculate()” method is ended.
60. The class is ended.
Source Code
/* Java program to generate grocery store bill */
import java.io.*; /* importing all classes from Input-Output
Java package to perform input/output tasks */
public class test_Grocery_Store /* declaring a class */
{ /* start of class */
public void test_Method () throws IOException /* declaring
a method */
{ /* start of method */
Grocery_Store obj=new Grocery_Store (); /* creating an
object */
obj.allMethods(); /* calling the 'allMethods' method of
the 'Grocery_Store' class to initiate the running of the
program */
} /* end of method */
} /* end of class */
import java.io.*; /* importing all classes from Input-Output
Java Package to perform input/output tasks */
public class Grocery_Store /* declaring another class */
{ /* start of class */
BufferedReader r=new BufferedReader(new
InputStreamReader(System.in)); /* creating another object to
retrieve data from keyboard and

storing it in a variable */
String item[]={"Eggs","Complan","Jelly","Glucon D","Marie
Biscuit","Sugar","Mustard Oil","Coconut
Oil","Detergent","Potato",
"Tomato ketchup","Onion","Dehradun Rice","Ashirwad
Atta","Flour","Corn Flakes","Mango
Pickle","Jam","Maggi","Chowmin",
"Amul Butter","Poppy Seeds","Cumin Powder","Black
Pepper","Elaichi","Masoor Dal","Moong
Dal","Chickpea","Soyabean Chunks","Turmeric Powder",
"Chilli Powder","Hair Oil","Floor
Cleaner","Semolina","Soap","Sunflower
Oil","Powder","Toothpaste","Toothbrush","Odonil",
"Squash","Oats","Papad","Cadbury Dairy Milk","Body
Lotion","Shampoo","Deodrant","Jaggery","Incense
Sticks","Sunrise Sahi Garam Masala",
"Corn Flour","Amul Milk","All
Out","Salt","Pasta","Cashew
Nuts","Horlicks","Boost","Sunlight Bar","Vim Dish Wash"};
int
price[]={200,160,110,120,40,50,190,60,80,30,120,100,100,80
,90,115,110,130,140,50,130,1800,400,1000,3000,100,250,20
0,120,200,200,95,140,50,30,190,

100,50,80,130,60,200,80,200,370,150,230,60,120,250,60,370
,75,20,80,1000,220,135,20,40};
String customer_name="";
long customer_phno=0L;
String choice_item="", ch="", choice="", items_ordered="";
int qty=0,srch_index=0, bill_no=5301;
double totamt=0.0, gst=0.0, grand_total=0.0;
boolean flag=true;
public void allMethods() throws IOException /* declaring
this method to encapsulate all the other methods of the class
*/
{ /* start of method */
stcal();
calculate();
} /* end of method */
public void stcal() /* declaring this method to perform the
initial steps of the bill generation */
{ /* start of method */
for(int i=0;i<60;i++) /* for loop to find the length of each
item and making their lengths uniform */
{ /* start of for loop */
int l=item[i].length();
for(int j=l;j<=30;j++) /* for loop to make the lengths of
the items constant */
{ /* start of for loop */
item[i]+=" "; /* adding a certain number of blank
spaces beside the item at index i to make the length of each
item same and
replacing the previous
elements with the new formed ones in the array */
} /* end of for loop */
} /* end of for loop */
} /* end of method */
public void calculate () throws IOException /* declaring this
method to print and calculate the necessary things */
{ /* start of method */
do
{ /* start of do while loop */
System.out.println("\n\n\n\t\t\t\t\t :: You are
welcome to this Grocery Store ::");
System.out.println("\t\t\t\t\t
--------------------------------------\n");
System.out.println("\
t=================================================
==================================================
=======================\n");
System.out.println("\t\t\t\t\t\t\t H A R I B A N S H A\
n"); /* the name of the store is displayed */
System.out.println("\
t=================================================
==================================================
=======================\n\n");
System.out.println("\t\t\t\t\t\t\t Available Items");
System.out.println("\t\t\t\t\t\t\t ---------------\n");
System.out.println("\n\t\tItem Names\t\t\tPrice Per
Unit\t\t\tItem Names\t\t\tPrice Per Unit\n");
System.out.println("\n\t\t----------\t\t\t--------------\t\t\
t----------\t\t\t--------------\n");
for(int i=0;i<60;i++) /* for loop to display the names of
the items and their prices */
{ /* start of for loop */
if(i%2==0) /* to divide the list of items into two
equal columns */
System.out.println();
System.out.print("\t\t"+(i+1)+") "+item[i]+"\t = Rs.
"+price[i]+"/-"+"\t"); /* displaying each item name and their
price along

with the serial number */


} /* end of for loop */
System.out.println("\n\n\
t=================================================
==================================================
=======================\n");
System.out.println("\n\tEnter the customer's name :
");
System.out.print("\t");
customer_name=r.readLine();
System.out.println("\n\tEnter the customer's phone
number : ");
System.out.print("\t");
customer_phno=Long.parseLong(r.readLine());
do
{ /* start of do while loop */
System.out.println("\n\tEnter the name of the item
to be purchased : ");
System.out.print("\t");
choice_item=r.readLine();
for(int i=0;i<60;i++) /* for loop to search for the item
asked by the customer */
{ /* start of for loop */
if(choice_item.equalsIgnoreCase(item[i].trim())) /*
checking whether the item asked by the customer is avaiable
at the store or not by
comparing the strin given by the user with the
string at index i of the array after removing all the blank
spaces beside it */
{
srch_index=i;
flag=false;
break; /* immediately the control will come out
from this loop after the required item is found */
}
} /* end of for loop */
if(flag) /* if the value of flag remains true i.e. if the
item is not found, then this block will be executed */
{
System.out.println("\n\tSorry, the item is not
available.");
}
else /* if the value of flag is false i.e. if the item is
found, then this block will be executed */
{
System.out.println("\n\tEnter the number of
items to be purchased.");
System.out.print("\t");
qty=Integer.parseInt(r.readLine());
totamt+=price[srch_index]*qty;
items_ordered+=item[srch_index]+"Rs.
"+price[srch_index]+"/-"+" \t X\t "+qty+"\t = Rs. "+
(price[srch_index]*qty)+"/-"+"\n\t\t\t\t";
}
System.out.println("\n\tIs there any more item to
be purchased ? Type 'yes' to confirm.");
System.out.print("\t");
ch=r.readLine();
flag=true;
} /* end of do while loop */
while(ch.equalsIgnoreCase("yes")); /* checking
whether there are any more items to be purchased */
gst=totamt*0.18;
grand_total=totamt+gst;
System.out.println("\n\n\
t=================================================
==================================================
========================");
System.out.println("\n\t\t\t\t\t\t\t H A R I B A N S H
A"); /* the name of the store is displayed */
System.out.println("\n\
t=================================================
==================================================
========================");
System.out.println("\n\t\t\t\t\t\t\t\t\t\t Bill No. :
"+bill_no); /* bill number is displayed */
System.out.println("\n\n\t\t\t\t\t\t\t BILL");
System.out.println("\t\t\t\t\t\t\t ====");
System.out.println("\n\t\t\t\tName of the Customer
: "+customer_name); /* customer's name is displayed */
System.out.println("\t\t\t\tPhone Number of the
Customer : "+customer_phno); /* customer's phone number
is displayed */
System.out.println("\n\t\t\t\tItem\t\t\t Price\t\
tQuantity\t Amount");
System.out.println("\t\t\t\t----\t\t\t -----\t\t--------\t
------");
System.out.println("\n\t\t\t\t"+items_ordered);
System.out.println("\t\t\t\
t-------------------------------------------------------------------------");
System.out.println("\n\t\t\t\t\t\t\t Total amount =
Rs. "+totamt+"/-"); /* total cost of all the items purchased
without GST is displayed */
System.out.println("\t\t\t\t\t\t\t G.S.T. @ 18 % = Rs.
"+gst+"/-"); /* GST on total cost is displayed */
System.out.println("\t\t\t\t\t\t\t Grand Total = Rs.
"+grand_total+"/-"); /* the sum of GST and total cost of the
items purchased is displayed */
System.out.println("\t\t\t\
t-------------------------------------------------------------------------");
System.out.println("\n\n\t\t\t\t\t\t "+"Thank you for
visiting H A R I B A N S A");
System.out.println("\n\t\t\t\t\t\t\t Visit Again !");
System.out.println("\n\n\
t=================================================
==================================================
========================");
System.out.println("\n\n\tIs there any customer ?
Type 'yes' to confirm.");
System.out.print("\t");
choice=r.readLine();
bill_no++;
totamt=gst=grand_total=0.0;
items_ordered="";
} /* end of do while loop */
while(choice.equalsIgnoreCase("yes")); /* checking
whether there are any more customers */
} /* end of method */
} /* end of class */
Main window screen

Showing that test_Grocery_Store class is compiled


Showing that Grocery_Store class is compiled
Variable Description
Datatype Variable/Array Purpose
Name
Grocery_Store obj To create an object to call the starting
method of “Grocery_Store” class and
store it.
BufferedReader r To create an object to retrieve data
from keyboard and store it.
String item[] To store the name of each item
available at the store.
int price[] To store the cost of each item available
at the store accordingly.
String customer_name To store the name of the customer as
given by the user.
long customer_phno To store the phone number of the
customer as given by the user.
String choice_item To store the name of the item to be
purchased as given by the user.
String ch To store the user’s response in buying
any more item as either ‘yes’ or ‘no’
String choice To store the user’s response as either
‘yes’ or ‘no’ if there is another
customer.
String items_ordered To store the name of an item, quantity
of that item and the total cost of the
total number of that item purchased.
int qty To store the total number of a
particular item purchased.
int srch_index To store the index of a particular item
and its corresponding price occurring in
the “item[]” and “price[]” arrays
respectively.
int bill_no To store the serial number of a
particular bill and increase one by one.
double totamt To store the total price of all the items
bought by the customer excluding GST.
double gst To store the GST calculated on the total
price.
double grand_total To store the total price of all the items
bought by the customer including GST.
boolean flag To store either ‘true’ or ‘false’
accordingly.
int i To act as a loop variable storing
numbers 0 to 59 and increasing one by
one.
int l To store the length of each item
occurring at index i in the “item[]”
array.
int j To act as a loop variable storing
numbers from the value of l to 30 and
increasing one by one for a particular
item.
Input and Output Screenshots
Input 1
Output 1

Input 2
Output 2

Input 3
Output 3
Input 4
Output 4
Input 5
Output 5
Conclusion
To conclude, how one can use the concept of Grocery Bill
Generation in Java program is clearly depicted in this project.
The features of OOP are used to build the program. Along
with this, algorithm, variable description, comments and
input/output screenshots of the program are also used for
the better understanding of the program and the use of the
concept of Objects and Classes. The logic of the program is
kept as simple as possible so it can be understood easily.
Though the class design, variable description, coding and
execution of the program may be improved by making it
more user-friendly and making the interface more simple.
The project has helped me to increase my logical thinking
and I learnt a lot of things at every single step in doing this
project. It will be really beneficial for us if we will be again
assigned with the task of doing such a project to maintain our
ballistic performance in future.

You might also like