Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication1
- {
- public class Admin : ClientHandler
- {
- private string name;
- private int password ;
- public Admin(string name,int password)
- {
- this.name = name;
- this.password = password;
- }
- private bool SecCHeck(string name, int password)
- {
- if (String.Equals(this.name,name) && (this.password == password))
- return true;
- return false;
- }
- public override void ClientUi(string name,int password)
- {
- if (!SecCHeck(name, password))
- {
- Console.WriteLine(" Wrong Password");
- return;
- }
- Console.WriteLine("Admin login succsful Please choose the option you want");
- while (true)
- {
- Console.WriteLine("Please choose the option you want");
- Console.WriteLine(" 1-Stock List, 2-Add Item, 3- Remove Item, 4 Change Item, 5-Return To main Menue");
- int choice = int.Parse(Console.ReadLine());
- switch (choice)
- {
- case 1:
- PrintStock();
- break;
- case 2:
- AddItem();
- break;
- case 3:
- RemoveItem();
- break;
- case 4:
- ChangeItem();
- break;
- case 5:
- return;
- default:
- Console.WriteLine("We have encoutred a problame in your selction");
- break;
- }
- }
- }
- private void ChangeItem()
- {
- Console.WriteLine("Pls enetr the name of the item you want to change his propties");
- string name = Console.ReadLine(),Nname;
- int Id = base.Search(name),choice,price,age;
- if (items[Id].GetType() == typeof(Animal))
- {
- Console.WriteLine("1-to change price, 2-to change name,3-to change age");
- choice = int.Parse(Console.ReadLine());
- switch (choice)
- {
- case 1:
- Console.WriteLine("Pls write the new price you want to set for {0}", name);
- price = int.Parse(Console.ReadLine());
- items[Id].SetPrice(price);
- break;
- case 2:
- Console.WriteLine("Pls write the new name you want to set for {0}", name);
- Nname = Console.ReadLine();
- items[Id].SetName(Nname);
- break;
- case 3:
- Console.WriteLine("Pls write the new age you want to set for {0}", name);
- Animal animal = (Animal)items[Id];
- age = int.Parse(Console.ReadLine());
- animal.SetAge(age);
- break;
- default:
- Console.WriteLine("Eror you didnt give valid choice");
- break;
- }
- }
- else
- {
- Console.WriteLine("1-to change price, 2-to change name");
- choice = int.Parse(Console.ReadLine());
- switch (choice)
- {
- case 1:
- Console.WriteLine("Pls write the new price you want to set for {0}", name);
- price = int.Parse(Console.ReadLine());
- items[Id].SetPrice(price);
- break;
- case 2:
- Console.WriteLine("Pls write the new name you want to set for {0}", name);
- Nname = Console.ReadLine();
- items[Id].SetName(Nname);
- break;
- default:
- Console.WriteLine("Eror you didnt give valid choice");
- break;
- }
- }
- }
- private void RemoveItem()
- {
- Console.WriteLine("Pls enter the name of the item you wish to delete");
- string name = Console.ReadLine();
- base.DeleteItem(base.Search(name));
- }
- private void AddItem()
- {
- Console.WriteLine("If you want to add an animal press 1 else if you want to add genrel item press 2");
- int choice = int.Parse(Console.ReadLine());
- if (choice == 1)
- {
- if (items[0] == null)
- {
- Console.WriteLine("Pls enter data(price,name,age)");
- int price = int.Parse(Console.ReadLine());
- string name = (Console.ReadLine());
- int age = int.Parse(Console.ReadLine());
- items[0] = new Animal(price, name, age);
- }
- else
- {
- Console.WriteLine("Pls enter data(price,name,age)");
- int price = int.Parse(Console.ReadLine());
- string name = (Console.ReadLine());
- int age = int.Parse(Console.ReadLine());
- items[items[0].GetAmm()] = new Animal(price, name, age);
- }
- }
- if(choice==2)
- {
- if (items[0] != null)
- {
- Console.WriteLine("Pls enter data(price,name)");
- int price = int.Parse(Console.ReadLine());
- string name = (Console.ReadLine());
- items[items[0].GetAmm()] = new Item(price, name);
- }
- else
- {
- Console.WriteLine("Pls enter data(price,name)");
- int price = int.Parse(Console.ReadLine());
- string name =Console.ReadLine();
- items[0] = new Item (price, name);
- }
- }
- else
- {
- Console.WriteLine("Eror ! argument isnt valid");
- }
- }
- protected override void PrintStock()
- {
- int i = 0;
- Console.WriteLine("name price age");//need to fix formating
- while (i < items.Length)
- {
- if (items[i] != null)
- if (items[i].GetType() == typeof(Animal))
- {
- Animal animal = (Animal)items[i];
- Console.WriteLine(items[i].GetName() + " " + items[i].GetPrice() + " " + animal.GetAge());
- }
- else
- Console.WriteLine(items[i].GetName() + " " + items[i].GetPrice());
- i++;
- }
- Console.WriteLine();
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication1
- {
- public class Animal : Item
- {
- private int age;
- public Animal(int price, string name, int age) : base(price, name)
- {
- SetAge(age);
- }
- public void SetAge(int age) { this.age = age; }
- public int GetAge() { return age; }
- public override int Buy()
- {
- Console.WriteLine("Are you sure you want to buy {0} the price is {1} and the age is {2}", GetName(), GetPrice(), age);
- char answer = char.Parse(Console.ReadLine());
- if (answer == 'N')
- return 0;
- else
- return GetPrice();
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication1
- {
- public abstract class ClientHandler : Object
- {
- private static int MaxItems = 99;
- protected static Item[] items = new Item[MaxItems];
- protected abstract void PrintStock();
- public abstract void ClientUi(string name, int password);
- protected void DeleteItem(int itemID)
- {
- for (int i = items[0].GetAmm(); i > itemID; itemID++)
- {
- items[itemID] = items[itemID + 1];
- }
- }
- protected int Search(string name)
- {
- int i = 0;
- while (i < MaxItems)
- {
- if (items[i] != null)
- if (name.Equals(items[i].GetName(), StringComparison.Ordinal))
- return i;
- i++;
- }
- return -1;
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication1
- {
- public class Item : Object
- {
- private static int items_amm = 0;
- private int price;
- private string name;
- public Item(int price, string name)
- {
- items_amm++;
- this.price = price;
- this.name = name;
- }
- public virtual int Buy()
- {
- Console.WriteLine("Are you sure you want to buy {0} the price is {1} press 'N' to cancel transction", name, price);
- char answer = char.Parse(Console.ReadLine());
- if (answer == 'N')
- return 0;
- else
- return price;
- }
- public int GetAmm() { return items_amm; }
- public string GetName() { return name; }
- public void SetName(string name) { this.name = name; }
- public void SetPrice(int price) { this.price = price; }
- public int GetPrice() { return price; }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication1
- {
- class Class : Object
- {
- static private Admin admin = new Admin("A",1);// intalizte admin password;
- public static void Main(string[] args)
- {
- Ui();
- }
- public static void Ui()
- {
- Console.WriteLine("Welcome to the pet shop");
- while (true)
- {
- Console.WriteLine("If you are coustomr press 1, if you are an opretor press 2");
- int chocie = int.Parse(Console.ReadLine());
- if (chocie == 1)
- Console.WriteLine("Pls enter your name ");
- string name = Console.ReadLine();
- Customer client = new Customer(name);
- }
- if (chocie == 2)
- {
- Console.WriteLine("Pls enter the username ");
- string username = Console.ReadLine();
- Console.WriteLine("and password");
- int password = int.Parse(Console.ReadLine());
- admin.ClientUi(username, password);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement