Question

In: Computer Science

$$$$$$$$$$$$$$ please write in C# $$$$$$$$$$$$$$$ Write a program to keep track of a hardware store’s...

$$$$$$$$$$$$$$ please write in C# $$$$$$$$$$$$$$$

Write a program to keep track of a hardware store’s inventory. You will need to create necessary classes for handling the data and a separate client class with the main method.

The store sells various items. For each item in the store, the following information is maintained: item ID, item name, number of pieces currently in the store, manufacturer’s price of the item and the store’s selling price. Create a class Item to store the information about the items. Provide appropriate setters and getters. Override the toString() method.

Create a class Inventory that contains a vector of items. This class will contain a bunch of methods to help build the application. Create a static variable to keep track of the total different items in inventory. Every time a new item is added to the inventory this variable has to be updated.

  1. A method to create 5 Item objects by initializing the following properties of Item and returning a vector of Item.

ItemID,itemName,pInstore,manufPrice,sellingPrice

  1. A method to check whether an item is in the store by doing a lookup in the vector.
  2. A method to update the quantity on hand for the item being sold
  3. A method to report the quantity on hand for any item requested during purchase
  4. A method to print the report for the manager in the following format

ItemID     itemName               pInstore        manufPrice     sellingPrice

12            Circular saw            150               45.00      125.00

235        Cooking Range          50                450.0             850.00

.

Total Inventory: $####.##

Total number of items in the store:

The total inventory is the total selling value of all the items currently in the store. The total number of items is the sum of the number of pieces of all items in the store.

Create a separate client class with the main method, display the menu and use switch case statement to execute appropriate method. The main method should display a menu with the following choices such as:

  1. Check whether an item is in the store
  2. Sell an item
  3. Print the report

For option 1, the user must also be prompted for the itemID. You will then call the method created in the Inventory class.

For option 2, verify if pInstore > qtyOrdered. You will invoke the method created in Inventory class.

For option 3, display the report. Again, this is nothing but executing method from Inventory class.

Also after an item is sold update the appropriate counts. Initially, the number of pieces in the store is the same as the number of pieces ordered and the number of pieces of an item sold is zero. You will use the utility method created as part of Inventory class.

Solutions

Expert Solution

Screenshot

Program

using System;
using System.Collections.Generic;
namespace InventoryInCSharp
{
    //Create a class Item{
    class Item
    {
        //Attributes
        private int itemID;
        private string itemName;
        private int plnStore;
        private float manuPrice;
        private float sellingPrice;
        //constructor
        public Item(int id,string name,int cnt,float mPr,float sPr)
        {
            itemID = id;
            itemName = name;
            plnStore = cnt;
            manuPrice = mPr;
            sellingPrice = sPr;
        }
        //Getters and setters
        public int ItemId
        {
            set
            {
                itemID = value;
            }
            get
            {
                return itemID;
            }
        }
        public string ItemName
        {
            set
            {
               ItemName = value;
            }
            get
            {
                return itemName;
            }
        }
        public int ItemCnt
        {
            set
            {
                this.plnStore = value;
            }
            get
            {
                return this.plnStore;
            }
        }
        public float ItemMPrice
        {
            set
            {
                this.manuPrice = value;
            }
            get
            {
                return this.manuPrice;
            }
        }
        public float ItemSPrice
        {
            set
            {
                this.sellingPrice = value;
            }
            get
            {
                return this.sellingPrice;
            }
        }
        //To string implementation
        public override string ToString()
        {
            string str = String.Format("{0,5} {1,20} {2,10} {3,15} {4,15}", itemID, itemName, plnStore, manuPrice.ToString("#.00"), sellingPrice.ToString("#.00"));
            return str;
        }
    }

    //Create class Inventory
   class Inventory
    {
        //Attributes
       private List<Item> items = new List<Item>();
       static int totalItems=0;
       static float totalPrice = 0;
        //Create an inventory of 5 items
        public void createInventory()
        {
            items.Add(new Item(12, "Circular saw", 150, 45, 125));
            items.Add(new Item(235,"Cooking Range",50,450,850));
            items.Add(new Item(15, "Screw Driver", 75,10,15));
            items.Add(new Item(25, "Cooking Gadget", 100, 25, 35));
            items.Add(new Item(235, "Tilter", 60,30,35));
            for (int i = 0; i < items.Count; i++)
            {
                Inventory.totalItems += items[i].ItemCnt;
                Inventory.totalPrice += items[i].ItemSPrice* items[i].ItemCnt;
            }
        }
        //Search an item
        public void searchItem(int id)
        {
            int cnt = items.Count;
            for (int i = 0; i <cnt; i++)
            {
                 if (items[i].ItemId == id)
                {
                    Console.WriteLine("Item details are: "+items[i]);
                    return;
                }
            }
            Console.WriteLine("Not found in inventory!!!");
        }
        //Update inventory data
        public void updateInventory(int id,int quantityOrdered)
        {
            for (int i = 0; i < items.Count; i++)
            {
                if (items[i].ItemId == id)
                {
                    if (items[i].ItemCnt >= quantityOrdered)
                    {
                        items[i].ItemCnt -= quantityOrdered;
                        Inventory.totalPrice -= (quantityOrdered* items[i].ItemCnt);
                        Inventory.totalItems -= quantityOrdered;
                        Console.WriteLine(quantityOrdered + " " + items[i].ItemName + " sold ");
                        return;
                    }
                }
            }
            Console.WriteLine("Item not found in the list!!");
        }
        //Print report
        public void printReport()
        {
            Console.WriteLine("\nItemID         itemName        pInstore      manufPrice   sellingPrice");
            for (int i = 0; i < items.Count; i++)
            {
                Console.WriteLine(items[i]);
            }
            Console.WriteLine("Total Inventory: $"+Inventory.totalPrice);
            Console.WriteLine("Total number of items in the store: "+Inventory.totalItems);
        }
    }

    //Test class
    class Program
    {
        static void Main(string[] args)
        {
            //Inventory object
            Inventory inventory = new Inventory();
            //Fill inventory
            inventory.createInventory();
            //User choice
            int opt = userMenu();
            //loop until exit
            while (opt != 4)
            {
                //Each options
                switch (opt)
                {
                    case 1:
                        Console.Write("\nEnter item id to search: ");
                        int id = Convert.ToInt32(Console.ReadLine());
                        inventory.searchItem(id);
                        break;
                    case 2:
                        Console.Write("\nEnter item id to sell: ");
                        id = Convert.ToInt32(Console.ReadLine());
                        Console.Write("Enter quantity to sell: ");
                        int quant = Convert.ToInt32(Console.ReadLine());
                        inventory.updateInventory(id, quant);
                        break;
                    case 3:
                        inventory.printReport();
                        break;
                    default:
                        break;
                }
                Console.WriteLine();
                //Repetition
                opt = userMenu();
            }
        }
        //Method to get user choice without error
        static int userMenu()
        {
            Console.WriteLine("USER OPTIONS: ");
            Console.WriteLine("1. Check whether an item is in the store\n2. Sell an item\n3. Print the report\n4. Exit");
            Console.Write("Enter your choice: ");
            int opt = Convert.ToInt32(Console.ReadLine());
            while(opt<1 || opt > 4)
            {
                Console.WriteLine("Error!!!Choice must be 1-4");
                Console.Write("Enter your choice: ");
                opt = Convert.ToInt32(Console.ReadLine());
            }
            return opt;
        }
    }
}

------------------------------------------------------------

Output

USER OPTIONS:
1. Check whether an item is in the store
2. Sell an item
3. Print the report
4. Exit
Enter your choice: 1

Enter item id to search: 12
Item details are:    12         Circular saw        150           45.00          125.00

USER OPTIONS:
1. Check whether an item is in the store
2. Sell an item
3. Print the report
4. Exit
Enter your choice: 2

Enter item id to sell: 12
Enter quantity to sell: 10
10 Circular saw sold

USER OPTIONS:
1. Check whether an item is in the store
2. Sell an item
3. Print the report
4. Exit
Enter your choice: 3

ItemID         itemName        pInstore      manufPrice   sellingPrice
   12         Circular saw        140           45.00          125.00
235        Cooking Range         50          450.00          850.00
   15         Screw Driver         75           10.00           15.00
   25       Cooking Gadget        100           25.00           35.00
235               Tilter         60           30.00           35.00
Total Inventory: $66575
Total number of items in the store: 425

USER OPTIONS:
1. Check whether an item is in the store
2. Sell an item
3. Print the report
4. Exit
Enter your choice: 4

---------------------------------------------

Note:-

I assume you are expecting program this way.


Related Solutions

Write a c++ program for the Sales Department to keep track of the monthly sales of...
Write a c++ program for the Sales Department to keep track of the monthly sales of its salespersons. The program shall perform the following tasks: Create a base class “Employees” with a protected variable “phone_no” Create a derived class “Sales” from the base class “Employees” with two public variables “emp_no” and “emp_name” Create a second level of derived class “Salesperson” from the derived class “Sales” with two public variables “location” and “monthly_sales” Create a function “employee_details” under the class “Salesperson”...
Accounting Program in c++ Write a class to keep track of a balance in a bank...
Accounting Program in c++ Write a class to keep track of a balance in a bank account with a varying annual interest rate. The constructor will set both the balance and the interest rate to some initial values (with defaults of zero). The class should have member functions to change or retrieve the current balance or interest rate. There should also be functions to make a deposit (add to the balance) or withdrawal (subtract from the balance). You should not...
C++ Please. Break it down barney style if possible. Instructions Create a program to keep track...
C++ Please. Break it down barney style if possible. Instructions Create a program to keep track of the statistics for a kid’s soccer team. The program will have a structure that defines what data the program will collect for each of the players. The structure will keep the following data: Players Name (string) Players Jersey Number (integer) Points scored by Player (integer) The program will have an array of 12 players (use less for testing and development, use a constant...
ASSIGNMENT: Write a program to keep track of the total number of bugs collected in a...
ASSIGNMENT: Write a program to keep track of the total number of bugs collected in a 7 day period. Ask the user for the number of bugs collected on each day, and using an accumulator, keep a running total of the number of bugs collected. Display the total number of bugs collected, the count of the number of days, and the average number of bugs collected every day. Create a constant for the number of days the bugs are being...
C++ program, I'm a beginner so please make sure keep it simple Write a program to...
C++ program, I'm a beginner so please make sure keep it simple Write a program to read the input file, shown below and write out the output file shown below. Use only string objects and string functions to process the data. Do not use c-string functions or stringstream (or istringstream or ostringstream) class objects for your solution. Input File.txt: Cincinnati 27, Buffalo 24 Detroit 31, Cleveland 17 Kansas City 24, Oakland 7 Carolina 35, Minnesota 10 Pittsburgh 19, NY Jets...
Using c++ Design a system to keep track of employee data. The system should keep track...
Using c++ Design a system to keep track of employee data. The system should keep track of an employee’s name, ID number and hourly pay rate in a class called Employee. You may also store any additional data you may need, (hint: you need something extra). This data is stored in a file (user selectable) with the id number, hourly pay rate, and the employee’s full name (example): 17 5.25 Daniel Katz 18 6.75 John F. Jones Start your main...
Write a program using c++. Write a program that uses a loop to keep asking the...
Write a program using c++. Write a program that uses a loop to keep asking the user for a sentence, and for each sentence tells the user if it is a palindrome or not. The program should keep looping until the user types in END. After that, the program should display a count of how many sentences were typed in and how many palindromes were found. It should then quit. Your program must have (and use) at least four VALUE...
Write a Java program that lets the user keep track of their homemade salsa sales. Use...
Write a Java program that lets the user keep track of their homemade salsa sales. Use 5-element arrays to track the following. The salsa names mild, medium, sweet, hot, and zesty. The number of each type sold. The price of each type of salsa. Show gross amount of money made (before tax). Calculate how much the user owes in sales tax (6% of the amount made). Then display the net profit (after subtracting the tax).
Use C++ please You will be building a linked list. Make sure to keep track of...
Use C++ please You will be building a linked list. Make sure to keep track of both the head and tail nodes. (1) Create three files to submit. PlaylistNode.h - Class declaration PlaylistNode.cpp - Class definition main.cpp - main() function Build the PlaylistNode class per the following specifications. Note: Some functions can initially be function stubs (empty functions), to be completed in later steps. Default constructor (1 pt) Parameterized constructor (1 pt) Public member functions InsertAfter() - Mutator (1 pt)...
USING PYTHON ONLY Write a gradebook program that lets a teacher keep track of test averages...
USING PYTHON ONLY Write a gradebook program that lets a teacher keep track of test averages for his or her students. Your program should begin by asking the teacher for a number of students in their class as well as the total # of tests that will be given to the class. Validate this information to ensure that the numbers entered are positive. Next, prompt the teacher to enter in scores for each student. Ensure that the values entered are...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT