0% found this document useful (0 votes)
8 views

demo2

The document outlines a C# program for a grocery management system, featuring classes for managing grocery items, sales, and user interactions. It includes functionalities for adding, removing, displaying items, checking availability, and processing sales. The program uses a dictionary to store product names and quantities, and employs a console-based menu for user navigation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

demo2

The document outlines a C# program for a grocery management system, featuring classes for managing grocery items, sales, and user interactions. It includes functionalities for adding, removing, displaying items, checking availability, and processing sales. The program uses a dictionary to store product names and quantities, and employs a console-based menu for user navigation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 22

using System;

using System.Collections.Generic;

using System.Linq;

using System.Numerics;

using System.Text;

using System.Threading.Tasks;

namespace DAX_GroceryArray

class DAX_GroceryArray

public static void Main(string[] args)

//GetDetails g = new DAX_GroceryArray1();

//g.greeting();

DAX_GroceryArray1 arrayIn = new DAX_GroceryArray1();

Remove_Menu rm = new Remove_Menu();

while (true)

Console.WriteLine("GROCERY MANAGEMENT SYSTEM\


n**************************\n\t1.ADD MENU \n\t2.REMOVE MENU \n\
t3.DISPLAY\n\t4.AVAILABLE PRODUCT QUANTITY \n\t5.ADD USER\n\
t6.DISPLAY\n\t7.SALES \n\t8.USER ENTER ADMIN CHOICE");

int choice = Convert.ToInt32(Console.ReadLine());

switch (choice)

case 1:

rm.menu();

break;
case 2:

Remove_Menu.remove();

break;

case 3:

rm.display();

break;

case 4:

rm.availability();

break;

case 5:

arrayIn.getname();

break;

case 6:

arrayIn.display();

break;

case 7:

rm.listmenu();

break;

case 8:

rm.displaylist();

break;

public class Remove_Menu : Add_Menu

public List<int> saleproduct = new List<int>();


//string product_name;

string element,product_name;

int sales;

public static void remove()

if (items_menu.Count!=0)

Console.WriteLine("THE ELEEMT SHOULD REMOVE FROM A


LIST");

string element = Console.ReadLine();

if (items_menu.ContainsKey(element))

items_menu.Remove(element);

else

Console.WriteLine("THE ELEMENT NOT FOUND !!!");

else

Console.WriteLine("THERE IS NO ELEMENT !!!");

public void display()

foreach (var s in items_menu)

Console.WriteLine(s);

public void availability()

{
if (items_menu.Count!=0)

int value1;

Console.WriteLine("CHECK THE AVAILIABITY OF PRODUCT");

string valuename = Console.ReadLine();

if (items_menu.ContainsKey(valuename))

value1 = items_menu[valuename];

Console.WriteLine("THE QUANTITY OF PRODUCT IS : "+


value1);

else

Console.WriteLine("THE ELEMENT NOT FOUND !!!");

public void listmenu()

int product_quantity;

int productvalue;

if (items_menu.Count!=0)

Console.WriteLine("ENTER THE PRODUCT NAME");

product_name = Console.ReadLine();

if (items_menu.ContainsKey(product_name))

{
productvalue=items_menu[product_name];

Console.WriteLine("ENTER THE PRODUCT QUANTITY YOU


WISH TO BUY");

product_quantity=Convert.ToInt32(Console.ReadLine());

if (productvalue>=product_quantity)

sales=productvalue-product_quantity;

saleproduct.Add(sales);

Console.WriteLine("THE PRODUCT BUYED


SUCCESSFULLY"+sales);

else

Console.WriteLine("THE PRODUCT QUANTITY IS OUT OF


STOCK!!!!");

else

Console.WriteLine("Invalid");

public int displaylist(List<int> saleproduct)

int a1;
foreach (int s in saleproduct)

//Console.WriteLine("PRODUCT NAME "+product_name+"


REMAINING QUANTITY "+s);

//Console.WriteLine(s);

a1=s;

return s;

//return a1;

public class Add_Menu

public static Dictionary<string, int> items_menu = new


Dictionary<string, int>();

public void menu()

Console.WriteLine("ENTER THE TOTAL NUMBER OF ITEMS


PRESENT IN THE VEGETABLE SHOP");

int total = Convert.ToInt32(Console.ReadLine());

System.Console.WriteLine(total);

int q;

for (int i = 0; i<total; i++)

Console.WriteLine("Enter the"+(i+1)+" product name


Element in the Dictionary");

string product_name = Console.ReadLine();


Console.WriteLine("Enter the"+(i+1)+" product Quantity
Element in the Dictionary");

int product_quantity = Convert.ToInt32(Console.ReadLine());

if (product_quantity>0)

items_menu.Add(product_name, product_quantity);

else

Console.WriteLine("Pls enter valid quantity");

product_quantity = Convert.ToInt32(Console.ReadLine());

items_menu.Add(product_name, product_quantity);

foreach (var s in items_menu)

Console.WriteLine($"PRODUCT NAME:{s.Key}, QUANTITY:


{s.Value} ");

public class Sales : Remove_Menu

//Remove_Menu remove1 = new Remove_Menu();

public void displaylist1()

Console.WriteLine("hello");

int a= displaylist(saleproduct);

Console.WriteLine(a);
}

}
DEMO 2 PREPARATION

1) USED TO ACCESS KEY IN DIC

foreach (string s in items_menu.Keys) or Values

Console.WriteLine($"PRODUCT NAME:{s.Key}, QUANTITY:{s.Value} ");

DEMO 3
using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace DAX_GroceryShopManagement

public abstract class DAX_Abstract

protected Dictionary<string, int> items_menu = new


Dictionary<string, int>();

public List<int> saleproduct = new List<int>();

protected string product_name, pname;

int pquantity;

public void add_menu()

Console.WriteLine("ENTER THE NUMBER OF ITEMS TO ADD");

int numbercount = Convert.ToInt32(Console.ReadLine());

for (int i = 0; i<numbercount; i++)

Console.WriteLine("ENTER PRODUCT NAME");

pname=Console.ReadLine();

Console.WriteLine("ENTER PRODUCT QUANTITY");

pquantity=Convert.ToInt32(Console.ReadLine());
items_menu.Add(pname, pquantity);

public void display()

foreach (var item in items_menu)

Console.WriteLine(item);

abstract public void sale(string product_name);

public abstract class DAX_Abstract1 : DAX_Abstract

int productvalue;

int product_quantity;

int sales;

override public void sale(string product_name)

if (items_menu.Count!=0)

if (items_menu.ContainsKey(product_name))

productvalue=items_menu[product_name];
Console.WriteLine("ENTER THE PRODUCT QUANTITY YOU
WISH TO BUY");

product_quantity=Convert.ToInt32(Console.ReadLine());

if (productvalue>=product_quantity)

sales=productvalue-product_quantity;

saleproduct.Add(sales);

Console.WriteLine("THE PRODUCT BUYED


SUCCESSFULLY"+sales);

else

Console.WriteLine("THE PRODUCT QUANTITY IS OUT OF


STOCK!!!!");

else Console.WriteLine("Invalid");

public void pop(string element)

if (items_menu.Count!=0)

if (items_menu.ContainsKey(element))

items_menu.Remove(element);
}

else

Console.WriteLine("THE ELEMENT NOT FOUND !!!");

else

Console.WriteLine("THERE IS NO ELEMENT !!!");

public void display(string e)

Console.WriteLine("THE AVAILIABLITY OF PRODUCT\t" +e +"\tIS");

Console.WriteLine(items_menu[e]);

//foreach (int s in saleproduct)

//{

// Console.WriteLine(s);

//}

}
using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace DAX_GroceryShopManagement

class Dax_main : DAX_Abstract1

public static void Main(string[] args)

DAX_Abstract1 daxabstract = new Dax_main();

int choice;

while (true)

Console.WriteLine("ENTER USER CHOICE\n 1.ADD \n2.SALE\


n3.AVAILIABILITY\n4.REMOVE\n5.DISPLAY");

choice=Convert.ToInt32(Console.ReadLine());

switch (choice)

case 1:

daxabstract.add_menu();

break;

case 2:

Console.WriteLine("ENTER THE PRODUCT NAME");


string product_name = Console.ReadLine();

daxabstract.sale(product_name);

break;

case 3:

Console.WriteLine("ENTER PRODUCT NAME TO CHECK


AVAILIABILITY");

string product_name1 = Console.ReadLine();

daxabstract.display(product_name1);

break;

case 4:

Console.WriteLine("THE ELEEMT SHOULD REMOVE FROM A


LIST");

string element = Console.ReadLine();

daxabstract.pop(element);

break;

case 5:

daxabstract.display();

break;

// abstract public class DAX_Abstract

// {

// protected const int num = 10;

// protected virtual void display()

// {
// Console.WriteLine("hello display on parent class"+num);

// }

// abstract protected void a();

// }

// //interface Ia

// //{

// // public void ia();

// //}

// abstract public class A : DAX_Abstract

// {

// protected const int num = 11;

// public void display()

// {

// Console.WriteLine("hello"+num);

// }

// public void ia()

// {

// Console.Write("hi");

// }

// abstract public void b();

// //override public void a()

// //{

// // Console.WriteLine("This is abstract class call");

// //}

// //override protected void a11()

// //{

// // Console.WriteLine("hello world");

// //}
// //abstract protected void a11();

// }

// //public class B

// //{

// // public void display()

// // {

// // Console.WriteLine("hello"+num);

// // }

// // override public void b()

// // {

// // Console.WriteLine("hello world");

// // }

// // override protected void a11()

// // {

// // Console.WriteLine("hello world");

// // }

// // //abstract protected void cal1();

// //}

// public class c:A

// {

// override protected void a()

// {

// Console.WriteLine("THIS IS DAXA IN PROTECTED METHOD


CALLING A");

// }

// override public void b()

// {
// Console.WriteLine("THIS IS DAXA IN PROTECTED METHOD
CALLING B");

// }

// public static void Main()

// {

// c c1 = new c();

// c1.a();

// c1.b();

// }

// }

***************************************************************************
*******

public class Class2

{
public static void dictionary()

Dictionary<string, int> dict = new Dictionary<string, int>();

List<int> a = new List<int>();

dict.Add("1", 1);

dict.Add("22", 2);

dict.Add("three", 3);

int c = dict.Count-1;

//to print the keys based on index

Console.WriteLine(dict.Keys.ElementAt(c));

Console.WriteLine(dict.Values.ElementAt(c));

//string findmethod = dict.Find(c => c.StartsWith(1));

//int findindex = dict.IndexOf("three");

if (dict.ContainsKey("1"))

Console.WriteLine("key found and value is "+dict["1"]);

// to get value and print keys

int ele = Convert.ToInt32(Console.ReadLine());

foreach (var item in dict)

if (item.Value==ele)

Console.WriteLine(item.Key);

//from key to print value


string key = Console.ReadLine();

foreach (var item in dict)

if (item.Key==key)

Console.WriteLine(item.Value);

// for print all keys in dict

foreach (var item in dict.Keys)

Console.WriteLine(item);

// **************************** USED TO CLEAR ALL ELEMENT IN


DICT*******************************

//dict.Clear();

Console.WriteLine(dict.Count);

foreach (var item in dict)

Console.WriteLine(dict.Count);

Console.WriteLine(item);

public class List: Class2

public List<int> l1 = new List<int>();

public void list()

l1.Add(1);
l1.Add(2);

l1.Add(3);

l1.Add(4);

l1.AddRange(new int[]{5,6});

l1.Insert(0, 001);

l1.InsertRange(1, new int[] {7,8,93});

foreach (var item in l1)

Console.WriteLine(item);

l1.Remove(111111);

Console.WriteLine("after remove");

foreach (var item in l1)

Console.WriteLine(item);

int findindex = l1.IndexOf(1);

Console.WriteLine("find index="+findindex);

class Class3 : Class2

public static void Main(String[] args)

List lis = new List();

lis.list();

Class2.dictionary();

}
}

***************************************************************************
******

You might also like