Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You will be writing a small inventory manager program. The information about wha

ID: 3772601 • Letter: Y

Question

You will be writing a small inventory manager program. The information about what stock you have on hand is stored in a file. Your program will read the items you have in stock from a file. Each line read from the file will be an Item object. There will be 10 in total. The Item objects created MUST be stored in an Array of Item objects. The array size will be 10.

Once your inventory is loaded your program will do the four following operations:
1 Print Inventory
2 Check for low Inventory
3 Print Current Value of Inventory
4 Exit Program.

Assignment Steps:
1 Setting up Project:
1.1 Create a Project named InventoryManager
1.2 Add a file named Item to your project.
1.3 Download the items file from ilearn under the assignment PDF.
1.4 Copy/Move the file to the project folder named InventoryManager. This should be inside your NetBeans Project Folder.

2 Implement Item.java Class:
2.1 Create three data fields : name , quantity, and price per unit. Make sure all data fields are private and have the appropriate type.
2.2 Create a no-arg constructor that initializes NO data fields and a constructor that initializes ALL data fields.
2.3 Create all getters and setters for each data field.
2.4 Implement a toString method that builds a nicely formatted string representing an Item object.
REMEMBER YOU ARE NOT ALLOWED to print from this method. IT MUST return a String.

The items file from iLearn is a simple .txt file with the following information:
Paper 10 5.99
ColoredPaper 10 6.99
PaperClips 55 0.99
Staples 1000 0.10
Chairs 3 49.99
Pens 500 0.75
Pencils 500 .10
Highlighters 100 1.00
Toner 2 69.99
Post-its 100 1.99

Explanation / Answer

Program:

Inventory.java:

import java.io.*;

import java.util.*;

public class Inventory

{

     public static void main(String[] args) throws Exception

     {

          final int MAX = 10;

          Item[] items = new Item[MAX];

          int count = 0;

         

          try

          {

              Scanner infile = new Scanner(new File("simple.txt"));

                            

              while(infile.hasNextLine() && count < MAX)

              {

                   String line = infile.nextLine();

                   String[] tokens = line.split(" ");

                  

                   items[count] = new Item(tokens[0], Integer.parseInt(tokens[1]), Double.parseDouble(tokens[2]));

                   count++;

              }            

          }

          catch(Exception e)

          {

              System.out.println("Input file is not found");

          }   

         

          for(int i = 0; i < count; i++)

              System.out.println(items[i]);

          int min=items[0].getQuantity();

          System.out.println();

          System.out.println("Minimum Inventories are: ");

          for(int i = 0; i < count; i++)

          {

              if(items[i].getQuantity()< min)

              {

                   min=items[i].getQuantity();

                   System.out.println(items[i].getName()+" " + min +" "+items[i].getPrice());

              }

          }

          double totalVal=0;

          for(int i=0;i<count;i++)

          {

               totalVal=totalVal+(items[i].getPrice()*items[i].getQuantity());

          }

          System.out.println();

          System.out.println("Current value of Inventory is: "+totalVal);

     }

}

Item.java:

import java.io.Serializable;

import java.util.*;

public class Item implements Serializable

{

     private String name;

     private int quantity;

     private double price;

    

     public Item()

     {

         

     }

     public Item(String name, int quantity, double price)

     {

          this.name = name;

          this.quantity = quantity;

          this.price = price;

     }

     public void setName(String name)

     {

          this.name = name;

     }

     public void setQuantity(int quantity)

     {

          this.quantity = quantity;

     }

     public void setPrice(double price)

     {

          this.price = price;

     }

    

     public String getName()

     {

          return name;

     }

     public int getQuantity()

     {

          return quantity;

     }

     public double getPrice()

     {

          return price;

     }

   

     public String toString()

     {

          return (name+"    "+ quantity +"    "+ price);

     }

}

simple.txt:

Paper 10 5.99

ColoredPaper 10 6.99

PaperClips 55 0.99

Staples 1000 0.10

Chairs 3 49.99

Pens 500 0.75

Pencils 500 0.10

Highlighters 100 1.00

Toner 2 69.99

Post-its 100 1.99

Sample Output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote