Sie sind auf Seite 1von 59

COMPUTER PROJECT

GROCERY SHOP
1

INDEX

Sr.no Topics Page


no.

1 Introduction 2

2 Documentation
3

3 Source Code 6

4 Output Screenshots 35

5 Acknowledgement 40
2

INTRODUCTION

This is my computer project which is comprised of various


methods and ways.

It is about a grocery shop in which you can make


purchases and a bill with total amount appears on the
output screen.

In this project the below mentioned is used:

 If else

 While loop

 Do while loop

 For loop

 Arrays

 Parameterized constructor
3

DOCUMENTATION

Class ComputerProject

 java.lang.Object

 ComputerProject

public class ComputerProject


extends java.lang.Object

 Field Summary

Fields
Modifier and Type Field and Description
(package private) static costprice
double[]
(package private) static count
int
(package private) static i
int
(package private) static name
java.lang.String[]
(package private) static quantity
int[]
(package private) static subname
java.lang.String[]
(package private) static sum
double
4

(package private) static totalprice


double[]

 Constructor Summary

Constructors
Constructor and Description
ComputerProject()

 Method Summary

All MethodsStatic MethodsInstance MethodsConcrete Methods


Modifier and Type Method and Description
Void bill()
Void chocolates()
Void dairyproducts()
(package private) void delay()
Void fruits()
static void main()
Void menu()
Void order(java.lang.String name1, j
double cost, double total1)
Void vegetables()
 Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode,


notify, notifyAll, toString, wait, wait, wait

 Field Detail
5

 costprice[Show source in BlueJ]


static double[] costprice
 count[Show source in BlueJ]
static int count
 i[Show source in BlueJ]
static int i
 name[Show source in BlueJ]
static java.lang.String[] name
 quantity[Show source in BlueJ]
static int[] quantity
 subname[Show source in BlueJ]
static java.lang.String[] subname
 sum[Show source in BlueJ]
static double sum
 totalprice[Show source in BlueJ]
static double[] totalprice
 Constructor Detail

 ComputerProject[Show source in BlueJ]


public ComputerProject()
 Method Detail

 bill[Show source in BlueJ]


public void bill()
 chocolates[Show source in BlueJ]
public void chocolates()
6

 dairyproducts[Show source in BlueJ]


public void dairyproducts()
 delay[Show source in BlueJ]
void delay()
 fruits[Show source in BlueJ]
public void fruits()
 main[Show source in BlueJ]
public static void main()
 menu[Show source in BlueJ]
public void menu()
 order
 public void order(java.lang.String name1,
 java.lang.String subname1,
 int quantity1,
 double cost,
double total1)
 vegetables[Show source in BlueJ]
public void vegetables()
7

//COMPUTER PROJECT 2018-2019


import java.util.*;
import java.text.SimpleDateFormat;
import java.util.Date;
public class ComputerProject
{//classbegins
static String name[] = new String[100];
static String subname[]= new String[100];
static int quantity[]=new int[100];
static double costprice[] = new double[100];
static double totalprice[] = new double[100];
static int count=-1,i=0;
static double sum = 0.0;

public static void main()


{
Scanner sc = new Scanner(System.in);
String login [] = {"adi"};
String password [] = {"123"};
ComputerProject obj = new ComputerProject();
8

String login1, password1;

boolean success =false;


do
{

System.out.println("Enter the login ID");


login1 = sc.nextLine();
System.out.println("Enter the password");
password1 = sc.nextLine();

if(((login[0].compareTo(login1)==0)||(login[1].compareTo(log
in1)==0)||(login[2].compareTo(login1)==0))&&((password[0]
.compareTo(password1)==0))||((password[1].compareTo(pas
sword1)==0))||((password[2].compareTo(password1)==0)))

{
success=true;
System.out.println(" WELCOME TO
ALL IN ONE GROCERY STORE");
9

System.out.println("");
System.out.println("**********************************
***************************************************
***************************************************
************************");
obj.menu();
}
else
{
System.out.println("YOU HAVE ENTERED THE WRONG
ID AND/OR THE WRONG PASSWORD. PLEASE TRY
AGAIN");
}
}while (success==false);
}

public void menu()


{
int n;
Scanner sc = new Scanner(System.in);
ComputerProject obj = new ComputerProject();
System.out.println();
10

System.out.println("-------------------------------------------------
-------------------------------------------------------------------------
-----------------------------------------------------------------");
System.out.println();
System.out.println(" MAIN
MENU");
System.out.println();
System.out.println("-------------------------------------------------
-------------------------------------------------------------------------
----------------------------------------------------");
System.out.println();
System.out.println();
System.out.println("1.CHOCOLATES");
System.out.println("2.FRUITS");
System.out.println("3.VEGETABLES");
System.out.println("4.DAIRY PRODUCTS");
System.out.println("5.BILL");
System.out.println("6.EXIT");

System.out.println();
System.out.println();
System.out.println("Enter your choice");
11

n=sc.nextInt();
if(n==1)

obj.chocolates();
if(n==2)

obj.fruits();
if(n==3)

obj.vegetables();
if(n==4)

obj.dairyproducts();
if(n==5)

obj.bill();
if(n==6)
{
System.out.println();
System.out.println("GOODBYE.");
System.out.println("VISIT US SOON.");
12

}
if((n==0)||(n>6))
{
System.out.println();
System.out.println(" YOU HAVE MADE THE WRONG
CHOICE. PLEASE TRY AGAIN");
obj.menu();
}
}

public void chocolates()


{
Scanner sc = new Scanner(System.in);
ComputerProject obj = new ComputerProject();
int chocolate,chocolateno,costtprice;
String chocolatename, k;
System.out.println();
System.out.println("-------------------------------------------------
-------------------------------------------------------------------------
--------------------------------");
System.out.println();
13

System.out.println("
CHOCOLATES");
System.out.println();
System.out.println();
System.out.println(" ___ ___
___ ___ ");
System.out.println("
.'\\__\\'\\__\\'\\__\\'\\ ");
System.out.println(" \\/ __\\/
__\\/ __\\/ __\\ ");
System.out.println("
\\'\\__\\'\\__\\'\\__\\'\\ ");
System.out.println(" \\/ __\\/
__\\/ __\\ /__\\ ");
System.out.println("
\\\\__\\'\\__\\'\\__\\__\\ ");
System.out.println();
System.out.println();
System.out.println("-------------------------------------------------
-------------------------------------------------------------------------
--------------------------------");
System.out.println();
System.out.println();
14

System.out.println("01. Dark Chocolate Rs. 35");

System.out.println("02. Dairy Milk Silk Rs. 75");

System.out.println("03. Flake Rs. 100");

System.out.println("04. Nestle KitKat Rs. 20");

System.out.println("05. Back");

System.out.println();

System.out.println();

System.out.println("Enter the serial number - ");

chocolate = sc.nextInt();

System.out.println();
15

switch(chocolate)
{
case 1:

System.out.println("How many Dark Chocolates do you


want?");
chocolateno = sc.nextInt();
System.out.println();
chocolatename = "Dark Chocolate";
costtprice = chocolateno*35;
System.out.println("Are you sure you want to buy?(Y/N)");
char ch = sc.next().charAt(0);
if((ch == 'y')||(ch == 'Y'))
{
obj.order("CHOCOLATES",chocolatename,chocolateno,35.0,c
osttprice);
obj.menu();
}
else if ((ch == 'n')||(ch == 'N'))
{
obj.menu();
16

}
break;

case 2:

System.out.println("How many Dairy Milk Silk do you


want?");
chocolateno = sc.nextInt();
System.out.println();
chocolatename = "Dairy Milk Silk";
costtprice = chocolateno*75;
System.out.println("Are you sure you want to buy?(Y/N)");
ch = sc.next().charAt(0);
if((ch == 'y')||(ch == 'Y'))
{
obj.order("CHOCOLATES",chocolatename,chocolateno,75.0,c
osttprice);
obj.menu();
}
else if ((ch == 'n')||(ch == 'N'))
{
17

obj.menu();
}
break;

case 3:

System.out.println("How many Flakes do you want?");


chocolateno = sc.nextInt();
System.out.println();
chocolatename = "Flake";
costtprice = chocolateno*100;
System.out.println("Are you sure you want to buy?(Y/N)");
ch = sc.next().charAt(0);
if((ch == 'y')||(ch == 'Y'))
{
obj.order("CHOCOLATES",chocolatename,chocolateno,100.0,
costtprice);
obj.menu();
}
else if ((ch == 'n')||(ch == 'N'))
{
18

obj.menu();
}
break;

case 4:

System.out.println("How many Nestle Kit Kat do you


want?");
chocolateno = sc.nextInt();
System.out.println();
chocolatename = "Nestle Kit Kat";
costtprice = chocolateno*20;
System.out.println("Are you sure you want to buy?(Y/N)");
ch = sc.next().charAt(0);
if((ch == 'y')||(ch == 'Y'))
{
obj.order("CHOCOLATES",chocolatename,chocolateno,20.0,
costtprice);
obj.menu();
}
else if ((ch == 'n')||(ch == 'N'))
19

{
obj.menu();
}
break;

case 6:

obj.main();
break;

default:

System.out.println();
System.out.println("You have made the wrong choice");
System.out.println("Please make a correct choice");
obj.chocolates();

}
}

void delay()
20

{
int i;
for(i=0;i<=10000;i++)
{}
}

public void fruits()


{
Scanner sc = new Scanner(System.in);
ComputerProject obj = new ComputerProject();
int fruit ,fruitno,fruitprice;
String fruitname, f;
System.out.println();
System.out.println("-------------------------------------------------
-------------------------------------------------------------------------
--------------------------------");
System.out.println();
System.out.println("
FRUITS");
System.out.println();
System.out.println();
System.out.println();
21

System.out.println();
System.out.println(" /> //
__");
System.out.println(" ___/ \\//
_/ /");
System.out.println(" ,' , \\_/ \\/
_/__");
System.out.println(" / _/ |--\\
` `~,");
System.out.println(" ' , ,/ /`\\ / `
` `,");
System.out.println(" | | | \\> `
` ` |");
System.out.println(" | , \\/ ' '
` ` /");
System.out.println(" `, ' ' ' `
' /");
System.out.println(" \\ ` ' '
, ,'");
System.out.println(" \\ ` ` ' ,
,/");
System.out.println(" `, ` ' ,
,'");
22

System.out.println(" \\ ` ,
/");
System.out.println(" `~---
-~'");
System.out.println();
System.out.println();
System.out.println("-------------------------------------------------
-------------------------------------------------------------------------
--------------------------------");
System.out.println();
System.out.println();
System.out.println("01. Apples (1kg) Rs. 50 ");
System.out.println("02. Kiwi (1kg) Rs. 40");
System.out.println("03. Custard Apple (1kg) Rs.
45");
System.out.println("04. Bananas (1 dozen) Rs.
30");
System.out.println("05. Oranges (1kg) Rs. 60 ");
System.out.println("06. Back");
System.out.println();
System.out.println();
System.out.println("Enter the serial number - ");
fruit = sc.nextInt();
23

switch (fruit)
{

case 1:

System.out.println("How many Apples do you want?");


fruitno = sc.nextInt();
System.out.println();
fruitname = "Apples";
fruitprice = fruitno*50;
System.out.println("Are you sure you want to buy?(Y/N)");
char ch = sc.next().charAt(0);
if((ch == 'y')||(ch == 'Y'))
{
obj.order("FRUITS",fruitname,fruitno,50.0,fruitprice);
obj.menu();
}
else if ((ch == 'n')||(ch == 'N'))
{
obj.menu();
}
24

break;

case 2:

System.out.println("How many Kiwis do you want?");


fruitno = sc.nextInt();
System.out.println();
fruitname = "Kiwi";
fruitprice = fruitno*40;
System.out.println("Are you sure you want to buy?(Y/N)");
ch = sc.next().charAt(0);
if((ch == 'y')||(ch == 'Y'))
{
obj.order("FRUITS",fruitname,fruitno,40.0,fruitprice);
obj.menu();
}
else if ((ch == 'n')||(ch == 'N'))
{
obj.menu();
}
break;
25

case 3:

System.out.println("How many Custard Apples do you


want?");
fruitno = sc.nextInt();
System.out.println();
fruitname = "Custard Apple";
fruitprice = fruitno*45;
System.out.println("Are you sure you want to buy?(Y/N)");
ch = sc.next().charAt(0);
if((ch == 'y')||(ch == 'Y'))
{
obj.order("FRUITS",fruitname,fruitno,45.0,fruitprice);
obj.menu();
}
else if ((ch == 'n')||(ch == 'N'))
{
obj.menu();
}
break;
26

case 4:

System.out.println("How many Bananas do you want?");


fruitno = sc.nextInt();
System.out.println();
fruitname = "Bananas";
fruitprice = fruitno*30;
System.out.println("Are you sure you want to buy?(Y/N)");
ch = sc.next().charAt(0);
if((ch == 'y')||(ch == 'Y'))
{
obj.order("FRUITS",fruitname,fruitno,30.0,fruitprice);
obj.menu();
}
else if ((ch == 'n')||(ch == 'N'))
{
obj.menu();
}
break;
27

case 5:

System.out.println("How many Oranges do you want?");


fruitno = sc.nextInt();
System.out.println();
fruitname = "Oranges";
fruitprice = fruitno*60;
System.out.println("Are you sure you want to buy?(Y/N)");
ch = sc.next().charAt(0);
if((ch == 'y')||(ch == 'Y'))
{
obj.order("FRUITS",fruitname,fruitno,60.0,fruitprice);
obj.menu();
}
else if ((ch == 'n')||(ch == 'N'))
{
obj.menu();
}
break;

case 6:
28

obj.main();
break;

default:

System.out.println();
System.out.println("You have made the wrong choice");
System.out.println("Please make the correct choice");
obj.fruits();

}
}

public void vegetables()


{
Scanner sc = new Scanner(System.in);
ComputerProject obj = new ComputerProject();
int veggieno,vegetableprice;
String veggiename, v;
System.out.println();
29

System.out.println("-------------------------------------------------
-------------------------------------------------------------------------
--------------------------------");
System.out.println();
System.out.println("
VEGETABLES");
System.out.println(" \\.-'");
System.out.println(" '.; ;..'.-
'_'");
System.out.println(" '-
.\\.;//.'_.");
System.out.println(" '- '.;;.//
.-.");
System.out.println(" .-'-\\;,-
'-.");
System.out.println("
_\\_");
System.out.println(" //'\\");
System.out.println(" |`--
`|");
System.out.println("
|'__.|");
System.out.println(" |
|");
30

System.out.println(" |-..-
|");
System.out.println(" | ;");
System.out.println(" ;'--
//");
System.out.println(" \\//");
System.out.println("
\\(");
System.out.println("
\\.");
System.out.println("-------------------------------------------------
-------------------------------------------------------------------------
--------------------------------");
System.out.println();
System.out.println();
System.out.println("01. Potatoes (1kg) Rs. 20");
System.out.println("02. Lady Finger (1kg) Rs. 25");
System.out.println("03. Lettuce (1kg) Rs. 30 ");
System.out.println("04. Cabbage (1kg) Rs. 40");
System.out.println("05. Carrots (1kg) Rs. 35");
System.out.println("06. Back ");
System.out.println();
System.out.println();
31

System.out.println("Enter the serial number - ");


veggieno = sc.nextInt();
System.out.println();
switch(veggieno)
{
case 1:

System.out.println("How many Potatoes do you want?");


veggieno = sc.nextInt();
System.out.println();
veggiename = "Potatoes ";
vegetableprice = veggieno*20;
System.out.println("Are you sure you want to buy?(Y/N)");
char ch = sc.next().charAt(0);
if((ch == 'y')||(ch == 'Y'))
{
obj.order("VEGETABLES","Potatoes (1kg)
",veggieno,20.0,vegetableprice);
obj.menu();
}
else if ((ch == 'n')||(ch == 'N'))
32

{
obj.menu();
}
break;

case 2:

System.out.println("How many Lady Fingers do you want?");


veggieno = sc.nextInt();
System.out.println();
veggiename = "Lady Finger ";
vegetableprice = veggieno*25;
System.out.println("Are you sure you want to buy?(Y/N)");
ch = sc.next().charAt(0);
if((ch == 'y')||(ch == 'Y'))
{
obj.order("VEGETABLES","Lady Finger (1kg)
",veggieno,25.0,vegetableprice);
obj.menu();
}
else if ((ch == 'n')||(ch == 'N'))
33

{
obj.menu();
}
break;

case 3:

System.out.println("How many Lettuce do you want?");


veggieno = sc.nextInt();
System.out.println();
veggiename = "Lettuce ";
vegetableprice = veggieno*30;
System.out.println("Are you sure you want to buy?(Y/N)");
ch = sc.next().charAt(0);
if((ch == 'y')||(ch == 'Y'))
{
obj.order("VEGETABLES","Lettuce (1kg)
",veggieno,30.0,vegetableprice);
obj.menu();
}
else if ((ch == 'n')||(ch == 'N'))
34

{
obj.menu();
}
break;

case 4:

System.out.println("How many Cabbage do you want?");


veggieno = sc.nextInt();
System.out.println();
veggiename = "Cabbage";
vegetableprice = veggieno*40;
System.out.println("Are you sure you want to buy?(Y/N)");
ch = sc.next().charAt(0);
if((ch == 'y')||(ch == 'Y'))
{
obj.order("VEGETABLES","Cabbage (1kg)
",veggieno,40.0,vegetableprice);
obj.menu();
}
else if ((ch == 'n')||(ch == 'N'))
35

{
obj.menu();
}
break;

case 5:

System.out.println("How many Carrots do you want?");


veggieno = sc.nextInt();
System.out.println();
veggiename = "Carrots ";
vegetableprice = veggieno*35;
System.out.println("Are you sure you want to buy?(Y/N)");
ch = sc.next().charAt(0);
if((ch == 'y')||(ch == 'Y'))
{
obj.order("VEGETABLES","Carrots(1kg)
",veggieno,35.0,vegetableprice);
obj.menu();
}
else if ((ch == 'n')||(ch == 'N'))
36

{
obj.menu();
}
break;

case 6:

obj.main();
break;

default :

System.out.println();
System.out.println("You have made the wrong choice");
System.out.println("Please make the correct choice");
obj.vegetables();

}
}

public void dairyproducts()


37

{
Scanner sc = new Scanner(System.in);
ComputerProject obj = new ComputerProject();
int dairyproduct,dairyno,costtprice;
String dairyname;
System.out.println();
System.out.println("-------------------------------------------------
-------------------------------------------------------------------------
--------------------------------");
System.out.println();
System.out.println(" DAIRY
PRODUCTS");
System.out.println();
System.out.println();
System.out.println("
_________");
System.out.println(" |
_______ |");
System.out.println(" //\\
\\");
System.out.println("
//__\\_________\\");
38

System.out.println(" | | \\
|");
System.out.println(" | | \\
|");
System.out.println(" | | \\
|");
System.out.println(" | | M \\
|");
System.out.println(" | | \\
|");
System.out.println(" | |\\ I \\
|");
System.out.println(" | | \\ \\
|");
System.out.println(" | | \\ L
\\ |");
System.out.println(" | | \\
\\|");
System.out.println(" | | \\
K |");
System.out.println(" | | \\
|");
System.out.println(" | | \\
|");
39

System.out.println("
|___|_______\\__|");
System.out.println();
System.out.println();
System.out.println("-------------------------------------------------
-------------------------------------------------------------------------
--------------------------------");
System.out.println();
System.out.println();
System.out.println("01. Milk (1 litre) Rs. 40");
System.out.println("02. Yoghurt (500gm) Rs. 50");
System.out.println("03. Cheese (500 gm.) Rs. 45");
System.out.println("04. Ice Cream (1 litre) Rs. 80");
System.out.println("05. Back");
System.out.println();
System.out.println();
System.out.println("Enter the serial number - ");
dairyproduct = sc.nextInt();
System.out.println();
switch(dairyproduct)
{
40

case 1:

System.out.println("How much Milk do you want?");


dairyno = sc.nextInt();
System.out.println();
dairyname = "Milk";
costtprice = dairyno*40;
System.out.println("Are you sure you want to buy?(Y/N)");
char ch = sc.next().charAt(0);
if((ch == 'y')||(ch == 'Y'))
{
obj.order("DAIRY
PRODUCTS",dairyname,dairyno,40.0,costtprice);
obj.menu();
}
else if ((ch == 'n')||(ch == 'N'))
{
obj.menu();
}
break;
41

case 2:

System.out.println("How much Yoghurt do you want?");


dairyno = sc.nextInt();
System.out.println();
dairyname = "Yoghurt";
costtprice = dairyno*50;
System.out.println("Are you sure you want to buy?(Y/N)");
ch = sc.next().charAt(0);
if((ch == 'y')||(ch == 'Y'))
{
obj.order("DAIRY
PRODUCTS",dairyname,dairyno,50.0,costtprice);
obj.menu();
}
else if ((ch == 'n')||(ch == 'N'))
{
obj.menu();
}
break;
42

case 3:

System.out.println("How much Cheese do you want?");


dairyno = sc.nextInt();
System.out.println();
dairyname = "Cheese";
costtprice = dairyno*45;
System.out.println("Are you sure you want to buy?(Y/N)");
ch = sc.next().charAt(0);
if((ch == 'y')||(ch == 'Y'))
{
obj.order("DAIRY",dairyname,dairyno,45.0,costtprice);
obj.menu();
}
else if ((ch == 'n')||(ch == 'N'))
{
obj.menu();
}
break;

case 4:
43

System.out.println("How much Ice Cream do you want?");


dairyno = sc.nextInt();
System.out.println();
dairyname = "Ice Cream";
costtprice = dairyno*80;
System.out.println("Are you sure you want to buy?(Y/N)");
ch = sc.next().charAt(0);
if((ch == 'y')||(ch == 'Y'))
{
obj.order("DAIRY",dairyname,dairyno,80.0,costtprice);
obj.menu();
}
else if ((ch == 'n')||(ch == 'N'))
{
obj.menu();
}
break;

case 5:
44

obj.main();
break;

default:

System.out.println();
System.out.println("You have made the wrong choice");
System.out.println("Please make the correct choice");
obj.dairyproducts();

}
}

public void order(String name1, String subname1, int


quantity1,double cost, double total1)
{
count++;
name[count]=name1;
subname[count]=subname1;
quantity[count]=quantity1;
costprice[count]=cost;
45

totalprice[count]=total1;
System.out.println("-------------------------------------------------
-------------------------------------------------------------------------
--------------------------------");
System.out.println();
System.out.println(" Your order has
been added to cart");
System.out.println();
System.out.println(name[count]+" \t"+subname[count]+"
\t"+quantity[count]+" \t" +costprice[count]+"
\t"+totalprice[count]);
System.out.println();
System.out.println("-------------------------------------------------
-------------------------------------------------------------------------
--------------------------------");
}

public void bill()


{
int i=0;
double sum=0.0;
46

System.out.println("-------------------------------------------------
-------------------------------------------------------------------------
--------------------------------");
System.out.println(" ALL IN
ONE GENERAL STORE" );
System.out.println("-------------------------------------------------
-------------------------------------------------------------------------
--------------------------------");
System.out.println();
System.out.println(" BILL
");
System.out.println();
Date now = new Date();
System.out.println("\t \t \t \t \t \t " + now);
System.out.println();
System.out.println("-------------------------------------------------
-------------------------------------------------------------------------
--------------------------------");
System.out.println("MAIN MENU SUB-MENU
QUANTITY COST PRICE TOTAL PRICE");
System.out.println("-------------------------------------------------
-------------------------------------------------------------------------
--------------------------------");
System.out.println();
47

System.out.println();
for(i=0;i<=count;i++)
{
System.out.println();
System.out.println(name[i]+" "+subname[i]+"
"+quantity[i]+" "+costprice[i]+" \t"+totalprice[i]);
sum=sum+totalprice[i];
}
System.out.println();
System.out.println();
System.out.println("-------------------------------------------------
-------------------------------------------------------------------------
--------------------------------");
System.out.println("YOUR GRAND TOTAL IS
Rs."+sum);
System.out.println("-------------------------------------------------
-------------------------------------------------------------------------
--------------------------------");
System.out.println();
System.out.println(" THANK
YOU FOR VISITING US");

System.out.println();
48

System.out.println(" WE HOPE YOU


ENJOYED SHOPPING AT ALL IN ONE GENERAL
STORE");
System.out.println(" HAVE A
GREAT DAY!");
System.out.println(" VISIT
SOON.");

}//class ends
49

OUTPUT
50
51
52
53
54
55
56
57
58

Das könnte Ihnen auch gefallen