Question

In: Computer Science

Java code for creating an Inventory Management System of any company - designing the data structure(stack,...

Java code for creating an Inventory Management System of any company

- designing the data structure(stack, queue, list, sort list, array, array list or linked list) (be flexible for future company growth

Java code for creating an initial list in a structure. Use Array (or ArrayList) or Linkedlist structure whichever you are confident to use. - Implement Stack, Queue, List type structure and proper operation for your application. Do not use any database. All data must use your data structures.

Minimum requirements of the system but not limited to only these:

Menu

1. Search Product

2. Search Product by other attribute

Menu

1. Show entire inventory

2. Show inventory by Manufacturer/Supplier

3. Show inventory by Type

4. Show inventory by Location

5. List products by price

6. List products by supplier

7. List products by availability

8. Show current discount items

Menu

1. Add record/product/part

2. Remove record

3. Change record

Menu for report

1. {make report - e.g. quantity report}

2. {make report - e.g. statistic report}

3. {Alert - Full or low quantity alerting}

Solutions

Expert Solution

store.java

import java.io.*;
import java.lang.*;

class store
{
        private InputStreamReader ir=new InputStreamReader(System.in);
        private BufferedReader br;
        private FileOutputStream fos;
        private PrintStream ps; 
        private FileReader frs;

        //function to check the existence for a file
        private boolean checkFile(String filename)
        {
                File myFile=new File(filename);
                boolean b=myFile.exists();      

                return b;
        }

        //function for auto-generating the product id
        private String generate_id()
        {
                String id=" ";
                String thisLine;
                String[] fullText = new String[200];
                String[] lastLine=new String[5];
                int counter=0,nid=0,l=0,z=0;

                boolean b=checkFile("Item.txt");

                if(b==false)
                {
                        id="00001";
                }
                else
                {
                        try
                        {
                                frs=new FileReader("Item.txt");
                                br=new BufferedReader(frs);
                                while((thisLine=br.readLine()) != null)
                                {
                                        counter=counter+1;
                                        fullText[counter] = thisLine;
                                }
                                frs.close();
                                lastLine=fullText[counter].split(",");
                                nid=Integer.parseInt(lastLine[0]);
                                nid=nid+1;
                                l=(String.valueOf(nid)).length();
                                z=5-l;
                                for(int i=1;i<=z;i++)
                                {
                                        id=id+"0";      
                                }
                                id=id+String.valueOf(nid);
                                id=id.substring(1);
                        }
                        catch(Exception ex)
                        {
                                System.out.println("Could not generate the Item ID...!");
                        }
                }
                return id;
        }

        //function to add new product
        private void addItem()
        {
                String desc;
                String id;
                double price=0;
                int stock=0,rol=0;

                try
                {
                        id=generate_id();
                        System.out.print("\n Product ID :"+id+"\n");
                        br=new BufferedReader(ir);

                        System.out.print("\n Product Description :");
                        desc=br.readLine();

                        System.out.print("\n Unit Price : Rs.");
                        price=Double.parseDouble(br.readLine());

                        System.out.print("\n Starting stock value :");
                        stock=Integer.parseInt(br.readLine());          

                        System.out.print("\n Re-order Level :");
                        rol=Integer.parseInt(br.readLine());

                        fos=new FileOutputStream("Item.txt",true);
                        ps=new PrintStream(fos);

                        ps.println(id+","+desc+","+price+","+stock+","+rol);
                        fos.close();
                        System.out.println("Successfully added one product...");
                }
                catch(Exception ex)
                {
                        System.out.println("Error in accepting item specifications...");
                }       
        }

        //function to make selling transaction for a specific product
        private void makeTransaction()
        {
                String id,desc,s="y";
                String msg,stock;
                String value[]=new String[5];
                double price=0,amount=0;
                int qty=0;

                try
                {
                        while(s.equals("y"))
                        {
                                br=new BufferedReader(ir);

                                System.out.print("\n Enter Product ID :");
                                id=br.readLine();
                                msg=findProduct(id);
                                if(msg.equals("Product not found..."))
                                {
                                        System.out.print("\n"+msg);
                                        continue;
                                }
                                br=new BufferedReader(ir);
                                value=msg.split(",");
                                if(Integer.parseInt(value[3])==Integer.parseInt(value[4]))
                                {
                                        System.out.println("Product in Re-Order Level.");
                                        System.out.println("Need to generate a purchase order...");
                                        continue;       
                                }
                                desc=value[1];
                                price=Double.parseDouble(value[2]);
                                stock=value[3];

                                if(Integer.parseInt(stock)==0)
                                {
                                        System.out.println("Current stock is NIL...");
                                        System.out.println("Could not process any transaction on this product...");
                                        continue;
                                }

                                System.out.print("\n Qty to sold :");
                                qty=Integer.parseInt(br.readLine());

                                if(qty>Integer.parseInt(stock))
                                {
                                        System.out.println("Out of stock...!");
                                        System.out.println("Could not sell out this product...");
                                        continue;
                                }
                                amount=qty*price;

                                int d=updateStock(id,qty);
                                if(d==1)
                                {
                                        System.out.println("Failed to update the stock...!");   
                                }

                                frs=new FileReader("Item.txt");
                                br=new BufferedReader(frs);

                                while((msg=br.readLine()) != null)
                                {
                                        value=msg.split(",");
                                        if(value[0].equals(id))
                                        {
                                                stock=value[3];
                                                break;
                                        }
                                }

                                fos=new FileOutputStream("Transaction.txt",true);
                                ps=new PrintStream(fos);
                                ps.println(id+","+desc+","+qty+","+amount+","+stock);
                                fos.close();

                                s="n";
                        }
                        System.out.println("Transaction processed successfully...");    
                }
                catch(Exception ex)
                {
                        System.out.println("Could not process the transaction...!");    
                }       
        }

        //function for searching a product in the master file
        private String findProduct(String pID) throws IOException
        {
                int counter=0,i=0,flag=0;
                String s;
                String cline[]=new String[255];
                String cID[]=new String[5];
                String value=" ";

                frs=new FileReader("Item.txt");
                br=new BufferedReader(frs);

                try
                {
                        while((s=br.readLine()) != null)
                        {
                                counter=counter+1;
                                cline[counter]=s;
                                cID=cline[counter].split(",");
                                if(cID[0].equals(pID))
                                {
                                        for(;i<cID.length;i++)
                                        {
                                                value=value+","+cID[i]; 
                                        }
                                        flag=1;
                                        break;
                                }
                        }
                        switch(flag)
                        {
                                case 0:
                                        value="Product not found...";
                                        break;
                                case 1:
                                        value=value.substring(2);
                                        break;                                          
                        }
                }
                catch(Exception ex)
                {
                        System.out.println("Could continue operation on searching the product...!");
                }

                return value;
        }

        //function for updating the value of current stock whenever a specific item is sold out
        private int updateStock(String pID,int qty) throws IOException
        {
                int counter=0,i=0,pos=0;
                String s;
                String cline[]=new String[255];
                String cID[]=new String[5];
                String row[]=new String[5];
                String desc,price,rol;
                int stock=0,status=0;

                try
                {
                        frs=new FileReader("Item.txt");
                        br=new BufferedReader(frs);             

                        while((s=br.readLine()) != null)
                        {
                                counter=counter+1;
                                cline[counter]=s;                       
                                cID=s.split(",");
                                if(cID[0].equals(pID))
                                {
                                        pos=counter;
                                        row=s.split(",");
                                }       
                        }

                        fos=new FileOutputStream("Item.txt",false);
                        ps=new PrintStream(fos);

                        for(i=0;i<cline.length;i++)
                        {                       
                                if(i==pos)
                                {
                                        desc=row[1];
                                        price=row[2];
                                        stock=Integer.parseInt(row[3])-qty;
                                        rol=row[4];
                                        ps.println(pID+","+desc+","+price+","+stock+","+rol);
                                }
                                else
                                {
                                        if(cline[i]!=null)
                                        {
                                                ps.println(cline[i]);
                                        }
                                }
                        }
                        fos.close();    
                        status=0;
                }
                catch(Exception ex)
                {
                        status=1;       
                }
                return status;  
        }

        //function to generate and print the daily transaction report
        private void displayReport()
        {
                String id,desc,qty,value,stock,s;
                String cline[]=new String[5];

                try
                {
                        frs=new FileReader("Transaction.txt");
                        br=new BufferedReader(frs);             

                        System.out.println("\nID   Description   Qty Sold   Amount   C.Stock");
                        System.out.println("----------------------------------------------");

                        while((s=br.readLine()) != null)
                        {
                                cline=s.split(",");
                                id=cline[0];
                                desc=cline[1];
                                qty=cline[2];
                                value=cline[3];
                                stock=cline[4];

                                System.out.println(id+"   "+desc+"              "+qty+"   "+"Rs."+value+"   "+stock);
                        }       
                }
                catch(Exception ex)
                {
                        System.out.println("Some exceptions occured...");
                        System.out.println("Could not generate the daily transaction report...!");      
                }
        }

        public static void main(String args[]) throws IOException
        {
                store inv=new store();
                int ch=0;
                String s;
                InputStreamReader ir=new InputStreamReader(System.in);
                BufferedReader br=new BufferedReader(ir);

                System.out.println("S T O C K    M A N A G E M E N T    S Y S T E M");
                System.out.println("-----------------------------------------------");
                System.out.println("1. ADD NEW PRODUCT");
                System.out.println("2. SELL PRODUCT");
                System.out.println("3. VIEW DAILY TRANSACTION REPORT");
                System.out.println("---------------------------------");
                System.out.println("4. Exit");
                begin:
                while(ch!=4)
                {
                        System.out.print("\n");
                        System.out.print("\n Enter a choice and Press ENTER to continue[1-4]:");
                        ch=Integer.parseInt(br.readLine());

                        if(ch>4||ch<1)
                        {
                                System.out.println("This doesn't appear to be a valid option...!");
                                continue begin; 
                        }

                        if(ch==1)
                        {
                                s="y";
                                while(s.equals("y")||s.equals("Y"))
                                {
                                        inv.addItem();
                                        System.out.print("\n Add another[y/n]:");
                                        s=br.readLine();                                                
                                }
                                continue begin;
                        }
                        else
                        if(ch==2)
                        {
                                s="y";
                                while(s.equals("y")||s.equals("Y"))
                                {
                                        inv.makeTransaction();                  
                                        System.out.print("\n Sell another[y/n]:");
                                        s=br.readLine();                                                
                                }
                        }
                        else
                        if(ch==3)
                        {
                                inv.displayReport();            
                        }       
                }
                System.out.println("Thanks for using this program...!");
        }
} 

Item.txt

00001,aa,12000.0,1,1
00002,bb,23000.0,33,7
00003,cc,12000.0,345,23
00004,dd,10000.0,40,12
00005,ee,5000.0,12,1
00006,ff,4500.0,20,5
00007,gg,3000.0,15,3
00008,hh,2500.0,100,20

Transaction.txt

00002,bb,12,276000.0,33

Related Solutions

Introduced to data structure using java 2)One of the applications of stack is to convert infix...
Introduced to data structure using java 2)One of the applications of stack is to convert infix expressions to postfix. Given the following infix expression, use the stack method to convert it to postfix. Show your work. x - y / (a + b) + z 3)write a generic method to find the maximum of three variables of generic type (i.e. type T). Note that you must use the compareTo method to compare the values. Also, the code must return one...
Designing and implementing a C++ structure data type - Monthly Budget Remember to use correct code...
Designing and implementing a C++ structure data type - Monthly Budget Remember to use correct code formatting and documentation. A student has established the following monthly budget: Budget Categories       Budgeted amount ----------------------------------------------------- Housing                  $ 580.00 Utilities                   $ 150.00 Household Expenses    $ 65.00 Transportation           $ 50.00 Food                      $ 250.00 Medical                  $ 30.00 Insurance                $ 100.00 Entertainment           $ 150.00 Clothing                  $ 75.00 Miscellaneous           $ 50.00 ---------------------------------------------------- Write a program that declares a MonthlyBudget structure designed with member variables to hold each of these expense categories. The program should define two MonthlyBudget structure variables...
Assignment #2 (JAVA) In assignment 1 you had used the data structure called Stack to evaluate...
Assignment #2 (JAVA) In assignment 1 you had used the data structure called Stack to evaluate arithmetic expressions by first converting the given infixed expressions to postfixed expressions, and then evaluated the post fixed expression. Repeat the exercise for this assignment (assignment 2) by using the data structure called Binary Trees. Your output must display the original expression, the postfixed expression representing the Binary tree, and the evaluated result. Please bear in mind that a given expression could result in...
Requirements Both the stack and queue were implemented correctly according data structure and java standard practices....
Requirements Both the stack and queue were implemented correctly according data structure and java standard practices. The stack was used to implement a post-fix calculator using push, pop, peek and other stack concepts. The queue was used to implement the palindrome using add, remove, insert and other queue concepts. Both implementations produced the expected output. All submission requirements were followed. Test Harness for the first part: public class StackCalcTest { public static void main(String[] args) { StackCalc stackCalc = new...
C++ code Inventory Item Stack You are writing an Inventory program that will allow the user...
C++ code Inventory Item Stack You are writing an Inventory program that will allow the user to enter a part into the inventory, take a part from the inventory, or quit. You are provided with the InvItem class (InvItem.h) and a partial Driver.cpp. You will be creating a DynamicStack class that should implement a Stack data structure. The DynamicClass should be implemented as a template class to allow any data type be added/removed from the stack. You will submit three...
Using existing Stack Java Collection Framework, write Java Code segment to do the following.   You may...
Using existing Stack Java Collection Framework, write Java Code segment to do the following.   You may write this in jGrasp Create a Stack of String called, myStacks Read input from keyboard, 10 names and then add to myStacks As you remove each name out, you will print the name in uppercase along with a number of characters the name has in parenthesis. (one name per line).   e.g.     Kennedy (7) Using existing Stack Java Collection Framework, write Java Code segment to...
Inventory Turnover and Days’ Sales in Inventory The Southern Company installed a new inventory management system...
Inventory Turnover and Days’ Sales in Inventory The Southern Company installed a new inventory management system at the beginning of 2015. Shown below are data from the company’s accounting records as reported out by the new system: 2015 2016 Sales Revenue $8,000,000 $11,000,000 Cost of Goods Sold 4,000,000 4,800,000 Beginning Inventory 510,000 530,000 Ending Inventory 530,000 600,000
Write a java program to reverse element of a stack. For any given word (from input),...
Write a java program to reverse element of a stack. For any given word (from input), insert every character (from the word) into a stack. The output from the stack should be the same as the input. Your program should be using a stack and a queue to complete this process. 1. Push into stack 2. Pop from stack 3. Enqueue into queue 4. Dequeue from queue 5. Push into stack 6. Pop from stack and display java
Java Code using Stack Write a program that opens a text file and reads its contents...
Java Code using Stack Write a program that opens a text file and reads its contents into a stack of characters, it should read character by character (including space/line change) and push into stack one by one. The program should then pop the characters from the stack and save them in a second text file. The order of the characters saved in the second file should be the reverse of their order in the first file. Ex input file: Good...
Code in Java Create a stack class to store integers and implement following methods: 1) void...
Code in Java Create a stack class to store integers and implement following methods: 1) void push(int num): This method will push an integer to the top of the stack. 2) int pop(): This method will return the value stored in the top of the stack. If the stack is empty this method will return -1. 3) void display(): This method will display all numbers in the stack from top to bottom (First item displayed will be the top value)....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT