Question

In: Computer Science

PLEASE DO IN C# Warehouse Inventories Objective: Work with multiple objects and review reading data files....

PLEASE DO IN C#

Warehouse Inventories

Objective:

Work with multiple objects and review reading data files.

Description: A wholesale distributor has six warehouses (Atlanta, Baltimore, Chicago, Denver, Ely and Fargo) and sells five different items (identified by part number: 102, 215, 410, 525 and 711). Each warehouse may stock any or all of the five items. The company buys and sells these items constantly. Company transaction records contain a transaction code (‘P’ for a purchase or ‘S’ for a sale) followed by an item number and the quantity (bought or sold).

The transaction records are contained in a transaction data file named Transactions.txt.

Sample transaction records:    Transactions.txt

P 410 1000

S 215 120

S 711 300

|

A separate data file contains the initial status of the six warehouses at the beginning of the day (i.e., the ending status from the night before). This data file has only six records (lines). Each record (line) contains five numbers that show the quantity on hand for the five items in that warehouse. This file is named Inventory.txt.

Sample status data file: Inventory.txt

500 120 60 0 350

100 230 0 50 0

0 75 0 0 220

600 50 120 300 40

210 160 30 80 50

90 50 90 200 70

|

The status data file is updated by processing the transaction records in the transaction data file according to these rules:

1 –     For a sale (‘S’) – subtract the quantity sold from the warehouse that

            has the largest supply of that item on hand.

2 –     For a purchase (‘P’) – add the quantity purchased to the warehouse

            that has the lowest supply of that item on hand.

Instructions:

Write an object-oriented C# program to do the above inventory warehouse processing. Each of the six warehouses should be treated as an individual object. For example, Atlanta would be an object with each of the five part numbers as instance fields. Each of the other warehouses should also be objects with the five part numbers as instance fields. Of course, there would be one class which would be the main (driver) class from which these 6 objects would be created.

In the beginning of the program, the status data file (Inventory.txt) should be read and an object for each warehouse created. The Inventory.txt data file is in the following order: the first line is the Atlanta warehouse, the second line is the Baltimore warehouse, third Chicago, then Denver, Ely and Fargo. After the objects are created, the transactions data file (Transactions.txt) are read and processed.

The objects should be updated as the transaction records are read and processed.

The program should:

1 –     Display the initial (beginning-of-day) status for all warehouses.

2 –     Process each transaction from the transaction data file and show which

            warehouse’s inventory was updated to reflect that transaction.

3 –     Display the final (end-of-day) status for all warehouses.

Requirements:

The class must be named Inventory.

The main program (driver) must be named Warehouses.

A driver (main class) as well as a programmer-defined class must be used.

Submit program through the assignment tool in Moodle2.

Include a comment stating your name.

Each student must create his/her own independent program.

Warehouse Inventories

Objective:

Work with multiple objects and review reading data files.

Description: A wholesale distributor has six warehouses (Atlanta, Baltimore, Chicago, Denver, Ely and Fargo) and sells five different items (identified by part number: 102, 215, 410, 525 and 711). Each warehouse may stock any or all of the five items. The company buys and sells these items constantly. Company transaction records contain a transaction code (‘P’ for a purchase or ‘S’ for a sale) followed by an item number and the quantity (bought or sold).

The transaction records are contained in a transaction data file named Transactions.txt.

Sample transaction records:    Transactions.txt

P 410 1000

S 215 120

S 711 300

|

A separate data file contains the initial status of the six warehouses at the beginning of the day (i.e., the ending status from the night before). This data file has only six records (lines). Each record (line) contains five numbers that show the quantity on hand for the five items in that warehouse. This file is named Inventory.txt.

Sample status data file: Inventory.txt

500 120 60 0 350

100 230 0 50 0

0 75 0 0 220

600 50 120 300 40

210 160 30 80 50

90 50 90 200 70

|

The status data file is updated by processing the transaction records in the transaction data file according to these rules:

1 –     For a sale (‘S’) – subtract the quantity sold from the warehouse that

            has the largest supply of that item on hand.

2 –     For a purchase (‘P’) – add the quantity purchased to the warehouse

            that has the lowest supply of that item on hand.

Instructions:

Write an object-oriented C# program to do the above inventory warehouse processing. Each of the six warehouses should be treated as an individual object. For example, Atlanta would be an object with each of the five part numbers as instance fields. Each of the other warehouses should also be objects with the five part numbers as instance fields. Of course, there would be one class which would be the main (driver) class from which these 6 objects would be created.

In the beginning of the program, the status data file (Inventory.txt) should be read and an object for each warehouse created. The Inventory.txt data file is in the following order: the first line is the Atlanta warehouse, the second line is the Baltimore warehouse, third Chicago, then Denver, Ely and Fargo. After the objects are created, the transactions data file (Transactions.txt) are read and processed.

The objects should be updated as the transaction records are read and processed.

The program should:

1 –     Display the initial (beginning-of-day) status for all warehouses.

2 –     Process each transaction from the transaction data file and show which

            warehouse’s inventory was updated to reflect that transaction.

3 –     Display the final (end-of-day) status for all warehouses.

Requirements:

The class must be named Inventory.

The main program (driver) must be named Warehouses.

A driver (main class) as well as a programmer-defined class must be used.

Solutions

Expert Solution

Complete code in C#:-

using System;
using System.IO;
using System.Collections.Generic;

// Inventory class.
class Inventory {
  
   // Instance variable, 'Name' stores class name.
   public String Name;
   // 'Items' stores quantity of each one of the 5 items.
   public int[] Items;
  
   // Constructor, creates Inventory object.
   public Inventory(int[] items, String Name) {
       // Sets name of class
       this.Name = Name;
       // Sets quantity of each item.
       this.Items = new int[5];
       for(int i = 0; i < 5; i++) {
           this.Items[i] = items[i];
       }
   }

   // Printing Status of Each Inventory.
   public void Print() {
       Console.WriteLine(this.Name);
       Console.Write(this.Items[0]+" "+this.Items[1]+" "+this.Items[2]+" "+this.Items[3]+" "+this.Items[4]+"\n\n");
   }
}

// Main driver class.
class Warehouses {

   // This converts String array to Integer array.
   private static void ParseStringToInteger(String[] strlist, int[] Items) {
       Items[0] = Int32.Parse(strlist[0]);
       Items[1] = Int32.Parse(strlist[1]);
       Items[2] = Int32.Parse(strlist[2]);
       Items[3] = Int32.Parse(strlist[3]);
       Items[4] = Int32.Parse(strlist[4]);
   }

   // This Function gives the inventory of minimum quantity of a specified item, represented by 'index'.
   private static Inventory minInventory(Inventory one, Inventory two, Inventory three, Inventory fourth, Inventory fifth, Inventory sixth, int index) {
       // Calculate minimum quantity of the item in all classes.
       int min = Math.Min(one.Items[index], Math.Min(two.Items[index], Math.Min(three.Items[index], Math.Min(fourth.Items[index], Math.Min(fifth.Items[index], sixth.Items[index])))));
      
       // If cases, matches the minimum quantity with the present in each inventory.
       // Which ever gets match, return that inventory.
       if(min == one.Items[index]) {
           return one;
       }
       else if(min == two.Items[index]) {
           return two;
       }
       else if(min == three.Items[index]) {
           return three;
       }
       else if(min == fourth.Items[index]) {
           return fourth;
       }
       else if(min == fifth.Items[index]) {
           return fifth;
       }
       return sixth;
   }

   // Same as 'minInventory()' function except the only thing that it will return the inventory with maximum quantity instead of minimum.
   private static Inventory maxInventory(Inventory one, Inventory two, Inventory three, Inventory fourth, Inventory fifth, Inventory sixth, int index) {
       // Finding maximum quantity
       int max = Math.Max(one.Items[index], Math.Max(two.Items[index], Math.Max(three.Items[index], Math.Max(fourth.Items[index], Math.Max(fifth.Items[index], sixth.Items[index])))));
       // Retrun inventory that matches with maximum quantity.
       if(max == one.Items[index]) {
           return one;
       }
       else if(max == two.Items[index]) {
           return two;
       }
       else if(max == three.Items[index]) {
           return three;
       }
       else if(max == fourth.Items[index]) {
           return fourth;
       }
       else if(max == fifth.Items[index]) {
           return fifth;
       }
       return sixth;
   }  

   // Main function.
   public static void Main(String[] args) {

       // Dictionary which defines mapping between item number and its index in "Inventory.Items" array.
       Dictionary<String, int> mapping = new Dictionary<String, int>();
       mapping.Add("102", 0);
       mapping.Add("215", 1);
       mapping.Add("410", 2);
       mapping.Add("525", 3);
       mapping.Add("711", 4);

       // Asking for Inventory file name.
       Console.Write("Enter Invetory File name : ");
       // Reading file name from terminal
       String inventoryFile = Console.ReadLine();
       String line;
       // Creating instances of Inventory.
       Inventory Atlanta, Baltimore, Chicago, Denver, Ely, Fargo, warehouse;
       // This 'Items' array will store the quantity for each item in each inventory.
       int[] Items = new int[5];
       // Trying to open inputs and read them.
       // Is exception gets generate, catch it in 'catch' block.
       try {
           // Creating input stream for 'Inventor.txt' file.
           using (StreamReader sr = new StreamReader(inventoryFile)) {
               // Reading data for 'Atlanta'.
               line = sr.ReadLine();
               String[] strlist = line.Split(" ");
               ParseStringToInteger(strlist, Items);
               // Creating 'Atlanta' object.
               Atlanta = new Inventory(Items, "Atlanta");
              
               // Reading data for 'Baltmiore'
               line = sr.ReadLine();
               strlist = line.Split(" ");
               ParseStringToInteger(strlist, Items);
               // Creating Object for 'Baltimore'.
               Baltimore = new Inventory(Items, "Baltimore");

               // Reading data for 'Chicago'.
               line = sr.ReadLine();
               strlist = line.Split(" ");
               ParseStringToInteger(strlist, Items);
               // Creating 'Chicago' object.
               Chicago = new Inventory(Items, "Chicago");

               // Reading data for 'Denver'.
               line = sr.ReadLine();
               strlist = line.Split(" ");
               ParseStringToInteger(strlist, Items);
               // Creating 'Denver' object.
               Denver = new Inventory(Items, "Denver");

               // Reading data for 'Ely'.
               line = sr.ReadLine();
               strlist = line.Split(" ");
               ParseStringToInteger(strlist, Items);
               // Creating 'Ely' object.
               Ely = new Inventory(Items, "Ely");

               // Reading data for 'Fargo'.
               line = sr.ReadLine();
               strlist = line.Split(" ");
               ParseStringToInteger(strlist, Items);
               // Creating 'Fargo' object.
               Fargo = new Inventory(Items, "Fargo");
           }

           // Priting 'Inventory's' status before processing transactions.
           Console.WriteLine("---------------------------------------------------------------------------------");
           Console.WriteLine("Status of each Inventory before Transactions: ");
           Atlanta.Print();
           Baltimore.Print();
           Chicago.Print();
           Denver.Print();
           Ely.Print();
           Fargo.Print();

           // Processing transactions and printing status of updated inventory.
           Console.WriteLine("\n---------------------------------------------------------------------------------");
   Console.Write("Enter Transaction File name : ");
   // Reading transaction file name from user.
           String transactionFile = Console.ReadLine();
           // Creating stream for transaction
           using (StreamReader sr = new StreamReader(transactionFile)) {
               // Reading transaction file line by line.
               while((line = sr.ReadLine()) != null) {
                   String[] strlist = line.Split(" ");
                   // Using swith-case mechanism for handling different tranactions.
                   // P OR S.
                   switch (strlist[0]) {
                       case "P":
                           // If transaction is of type purchasing
                           warehouse = minInventory(Atlanta, Baltimore, Chicago, Denver, Ely, Fargo, mapping[strlist[1]]);
                           warehouse.Items[mapping[strlist[1]]] += Int32.Parse(strlist[2]);
                           warehouse.Print();
                           break;
                       case "S":
                       // If transaction is of type selling.
                           warehouse = maxInventory(Atlanta, Baltimore, Chicago, Denver, Ely, Fargo, mapping[strlist[1]]);
                           warehouse.Items[mapping[strlist[1]]] -= Int32.Parse(strlist[2]);
                           warehouse.Print();
                           break;
                       default :
                           Console.WriteLine("File contains unwanted data.");
                           break;
                   }
               }
           }

           // Printing Inventory's status after processing transactions.
           Console.WriteLine("\n---------------------------------------------------------------------------------");
           Console.WriteLine("Status of each Inventory after Transactions: ");
           Atlanta.Print();
           Baltimore.Print();
           Chicago.Print();
           Denver.Print();
           Ely.Print();
           Fargo.Print();

       // Catch block for hndling generated exceptions.
       } catch (Exception e) {
   // Let the user know what went wrong.
   Console.WriteLine("The file could not be read:");
   Console.WriteLine(e.Message);
   }
   }
}

Screenshot of output:-


Related Solutions

Warehouse Inventories Objective: Work with multiple objects and review reading data files. Description: A wholesale distributor...
Warehouse Inventories Objective: Work with multiple objects and review reading data files. Description: A wholesale distributor has six warehouses (Atlanta, Baltimore, Chicago, Denver, Ely and Fargo) and sells five different items (identified by part number: 102, 215, 410, 525 and 711). Each warehouse may stock any or all of the five items. The company buys and sells these items constantly. Company transaction records contain a transaction code (‘P’ for a purchase or ‘S’ for a sale) followed by an item...
Basic Unix Commands Objective: The objective of this lab is to work with files of UNIX...
Basic Unix Commands Objective: The objective of this lab is to work with files of UNIX file system. Procedure: 1. OpenyourUnixshellandtrythesecommands: Ø Create a new file and add some text in it vcat > filename Ø View a file vcat /etc/passwd vmore /etc/passwd vmore filename Ø Copy file, making file2 vcp file1 file2 Ø Move/rename file1 as file2 vmv file1 file2 Ø Delete file1 as file2 vrm file //Deletefile //Double-checkfirst vrm -i file Ø Counts the lines, words, characters in...
The objective of this homework assignment is to demonstrate proficiency with reading files, and using string...
The objective of this homework assignment is to demonstrate proficiency with reading files, and using string methods to slice strings, working with dictionaries and using-step wise development to complete your program. Python is an excellent tool for reading text files and parsing (i.e. filtering) the data. Your assignment is to write a Python program in four steps that reads a Linux authentication log file, identifies the user names used in failed password attempts and counts the times each user name...
Objective Work with strings Work with files Work with formatted output This program will display a...
Objective Work with strings Work with files Work with formatted output This program will display a very basic handling of transactions for a checking account. The program will read in a data file with all the past transactions. Use FileUtil.selectOpenFile or input() to get a file name from the user. The format of the file will be very basic, just a date (as a string in the format of MM/DD), a single letter which indicates the type of transaction (‘B’...
PYTHON...... Working with lists, functions, and files Objective: Work with lists Work with lists in functions...
PYTHON...... Working with lists, functions, and files Objective: Work with lists Work with lists in functions Work with files Assignment: Part 1: Write a program to create a text file which contains a sequence of test scores. Ask for scores until the user enters an empty value. This will require you to have the scores until the user enters -1. After the scores have been entered, ask the user to enter a file name. If the user doesn’t not enter...
A. What are Objects? B. How do Objects differ from Classes? C. Where are Objects stored...
A. What are Objects? B. How do Objects differ from Classes? C. Where are Objects stored in Memory? D. Why do you not need to declare when you are finished using an Object in Java? E. Can you edits the contents of a String? View keyboard shortcuts EditViewInsertFormatToolsTable 12pt Paragraph
C++ 19.Which of the following headers is required for reading from and writing to disk files?...
C++ 19.Which of the following headers is required for reading from and writing to disk files? #include <ifstream> #include <fstream> #include <iostream> #include <ofstream> 20.Which of the following options is the correct way to call the open function on an ifstream object named ifstr? ifstr.open("data.txt") ifstr.open("data", ".txt") ifstr.open("data.txt", "read") ifstr.open() 24. What is wrong with the following function definition? void erase_file(ifstream infile, ofstream outfile) { char ch; while (infile.get(ch)) { outfile << ch; } } The ifstream and ofstream parameters...
PLEASE MAKE THIS TWO DIFFERENT FILES. ONE FOR CLASS (temperature.h) AND ONE FOR temperature.cpp Objective: This...
PLEASE MAKE THIS TWO DIFFERENT FILES. ONE FOR CLASS (temperature.h) AND ONE FOR temperature.cpp Objective: This assignment will provide further practice with implementing classes. Task:  For this homework, you will write a class called Temperature, in the files temperature.h and temperature.cpp, for creating and using objects that will store temperatures (like for weather forecasting programs). This class should be portable, so it should work with any up-to-date C++ compiler. Program Details and Requirements: 1) An object of type Temperature should represent...
how do i run 3 files on c++?
how do i run 3 files on c++?
Please do this in C++ Objective: Create an Inheritance Hierarchy to Demonstrate Polymorphic Behavior 1. Create...
Please do this in C++ Objective: Create an Inheritance Hierarchy to Demonstrate Polymorphic Behavior 1. Create a Rectangle 2. Class Derive a Square Class from the Rectangle Class 3. Derive a Right Triangle Class from the Rectangle Class 4. Create a Circle Class 5. Create a Sphere Class 6. Create a Prism Class 7. Define any other classes necessary to implement a solution 8. Define a Program Driver Class for Demonstration (Create a Container to hold objects of the types...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT