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...
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...
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...
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...
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
(must be done in JAVA code) A company dedicated to parking management has decided to renew...
(must be done in JAVA code) A company dedicated to parking management has decided to renew itself by automating its control process since this process is done manually. The company has hired its development team to automate the process and gave it an October 19th deadline until 6 pm. An analyst defined the system requirements as follows: 1. The system must allow configuring the number of spaces that a vehicle parking lot will contain. 2. The system must allow the...
write down the java code for garden sprinkler system.
write down the java code for garden sprinkler system.
The inventory data of Bilal Inc. is provided below, The company uses perpetual inventory system. Inventory:...
The inventory data of Bilal Inc. is provided below, The company uses perpetual inventory system. Inventory: 1st March = 200 units @ $4.00 (purchased) Purchases: 12th March = 500 units @ $4.50 (purchased) 15th March = 400 units @ $4.75 (purchased) 17th March = 828 units @ $5.00 (purchased) Sales: 20th March = 1928 units sold Instructions Under a perpetual inventory system, determine the cost of goods sold and ending inventory for the month of March under FIFO method
A company is considering the purchase of a $200,000 computer-based inventory management system. It will be...
A company is considering the purchase of a $200,000 computer-based inventory management system. It will be depreciated straight-line to zero over its four-year life. It will be worth $30,000 at the end of that time. The system will save $60,000 before taxes in inventory-related costs. The relevant tax rate is 39%. Because the new setup is more efficient than the existing one, the company will be able to carry fewer inventories and thus free up $45,000 in net working capital....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT