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

You will write a program to keep up with product vendors inventories. There is n

ID: 3811526 • Letter: Y

Question

You will write a program to keep up with product vendors inventories. There is no Inheritance in this project, the relationship between the classes are "has a aggregations. Vendor has a name and vendor number. Product has a product name, a product description, and an amount. Inventory has a date the last update of vendor's products, a Vendor, a list of Products (The type of list -array or arraylist-- is up to you), and a total cost of all of a vendor's products. P4Driver. The driver should not have any methods other than the main. Your driver should have a list of the Inventory (again the type of list -array or array List- is up to you). You will need to read through the provided text file and add the info to your list for the Inventory Your program will need to: be capable of reading from the provided file and pass the data to the appropriate class. create Inventory for Vendors and add Products to their Inventory modify (change) an Inventory (i.e., a vendor's name, product descriptions, product amounts). You must have the ability to change a value for every class attribute (there are 6 ofthese and this will require methods) display all the info about the Inventory including the Inventory total cost of the vendor's products. Then after modifications are made to the Inventory Display the data again. (You should probably have something that say's "after the data was changed" or something to that effect. To ensure your program works properly, you will need to change 1 thing about each Inventory, but make sure you can change any of the 6 things about an Inventory (l.E. the date, vendor's name, vendor number, product name, description, or cost). You can hard code the data for these changes.

Explanation / Answer

PROGRAM CODE:

package inventory;

public class Vendor {

  

   private String name;

   private int vendorNumber;

   public Vendor(String name, int number) {

       this.name = name;

       this.vendorNumber = number;

   }

   public String getName() {

       return name;

   }

   public void setName(String name) {

       this.name = name;

   }

   public int getVendorNumber() {

       return vendorNumber;

   }

   public void setVendorNumber(int vendorNumber) {

       this.vendorNumber = vendorNumber;

   }

  

   @Override

   public String toString() {

       return " Vendor Name: " + name + " Vendor Number: " + vendorNumber;

   }

}

package inventory;

public class Product {

   private String name;

   private String description;

   private double amount;

  

   public Product(String name, String desc, double amount) {

       this.name = name;

       this.description = desc;

       this.amount = amount;

   }

  

  

   public String getName() {

       return name;

   }

   public void setName(String name) {

       this.name = name;

   }

   public String getDescription() {

       return description;

   }

   public void setDescription(String description) {

       this.description = description;

   }

   public double getAmount() {

       return amount;

   }

   public void setAmount(double amount) {

       this.amount = amount;

   }

   @Override

   public String toString() {

       // TODO Auto-generated method stub

       return " Product Name: " + name + " Product Description: " + description + " Amount: " + amount;

   }

}

package inventory;

import java.util.ArrayList;

import java.util.Date;

public class Inventory {

  

   private Date date;

   private Vendor vendor;

   ArrayList<Product> productList;

   private double totalCost;

  

   public Inventory()

   {

       date = null;

       vendor = null;

       productList = new ArrayList<>();

       totalCost = 0;

   }

   public Inventory(Date date, Vendor vendor) {

       this.date = date;

       this.vendor = vendor;

       productList = new ArrayList<>();

       totalCost = 0.00;

   }

   public Date getDate() {

       return date;

   }

   public void setDate(Date date) {

       this.date = date;

   }

   public Vendor getVendor() {

       return vendor;

   }

   public void setVendor(Vendor vendor) {

       this.vendor = vendor;

   }

   public ArrayList<Product> getProductList() {

       return productList;

   }

   public void setProductList(ArrayList<Product> productList) {

       this.productList = productList;

   }

   public double getTotalCost() {

       return totalCost;

   }

   public void setTotalCost(double totalCost) {

       this.totalCost = totalCost;

   }

  

   public void addProduct(Product prod)

   {

       productList.add(prod);

       totalCost += prod.getAmount();

   }

  

   public void updateProduct(Product prod, int index)

   {

       totalCost -= productList.get(index).getAmount();

       productList.set(index, prod);

       totalCost += productList.get(index).getAmount();

   }

  

   public void deleteProduct(int index)

   {

       totalCost -= productList.get(index).getAmount();

       productList.remove(index);

   }

  

  

   @Override

   public String toString() {

       return " Date: " + date + vendor + productList + " Total Cost: " + totalCost;

   }

}

package inventory;

import java.util.ArrayList;

import java.util.Date;

import java.util.Scanner;

public class P4Driver {

   public static void main(String[] args) {

       int choice, option;

       ArrayList<Inventory> inventoryList = new ArrayList<>();

       Inventory inventory = null;

       String prodname = null, proddesc, vendorname, description = "";

       int vendornumber, index = 0, inventoryIndex = 0;

       double amount;

       Product product;

       Scanner kbd = new Scanner(System.in);

       System.out.println("MENU 1. Add Inventory 2. Update Inventory 3. Remove Inventory 4. Add Product 5. Remove Product 6. Exit");

       System.out.println("Enter your choice: ");

       choice = Integer.valueOf(kbd.nextLine());

      

       if(choice>=2 && choice<=5)

       {

          

       }

       switch(choice)

       {

       case 1: System.out.print("Enter the vendor name: ");

               vendorname = kbd.nextLine();

               System.out.print("Enter the vendor number: ");

               vendornumber = Integer.valueOf(kbd.nextLine());

               inventory = new Inventory(new Date(), new Vendor(vendorname, vendornumber));

               inventoryList.add(inventory);

               break;

       case 2: {

               System.out.println("Enter the vendor name to edit: ");

               vendorname = kbd.nextLine();

               for(int j=0; j<inventoryList.size(); j++)

               {

                   if(inventoryList.get(j).getVendor().getName().equals(vendorname))

                   {

                       inventory = inventoryList.get(j);

                       inventoryIndex = j;

                       break;

                   }

               }

               System.out.println("MENU 1. Product Name 2. Product Amount");

               System.out.println(" 3. Product Description 4. Vendor Name 5. Vendor Number");

               option = Integer.valueOf(kbd.nextLine());

               if(option >=1 && option<=3)

               {

                   System.out.println("Enter the product name that you want to modify: ");

                   prodname = kbd.nextLine();

                   index = inventory.getProductIndex(prodname);

                   if(index == -1)

                   {

                       System.out.println(prodname + " does not exist");

                       break;

                   }

                      

               }

               if(option == 1)

               {

                       System.out.println("Enter the new Product name: ");

                       prodname = kbd.nextLine();

                       inventory.getProductList().get(index).setName(prodname);

                  

               }

               else if(option == 2)

               {

                   System.out.println("Enter the new amount: ");

                   amount = Double.valueOf(kbd.nextLine());

                   inventory.getProductList().get(index).setAmount(amount);

               }

               else if(option == 3)

               {

                   System.out.println("Enter the new description: ");

                   description = kbd.nextLine();

                   inventory.getProductList().get(index).setDescription(description);

               }

               else if(option == 4)

               {

                   System.out.println("Enter the new vendor name: ");

                   vendorname = kbd.nextLine();

                   inventory.getVendor().setName(vendorname);

               }

               else if(option == 5)

               {

                   System.out.println("Enter the new vendor number: ");

                   vendornumber = Integer.valueOf(kbd.nextLine());

                   inventory.getVendor().setVendorNumber(vendornumber);

               }

               break;

               }

       case 3: System.out.println("Enter the vendor name to remove: ");

               vendorname = kbd.nextLine();

               for(Inventory in: inventoryList)

               {

                   if(in.getVendor().getName().equals(vendorname))

                   {

                       inventoryList.remove(in);

                       break;

                   }

               }

               break;

       case 4: System.out.println("Enter the vendor name to add a product: ");

               vendorname = kbd.nextLine();

               for(int j=0; j<inventoryList.size(); j++)

               {

                   if(inventoryList.get(j).getVendor().getName().equals(vendorname))

                   {

                       inventory = inventoryList.get(j);

                       inventoryIndex = j;

                       break;

                   }

               }

               System.out.println("Enter the product name: ");

               prodname = kbd.nextLine();

               System.out.println("Enter the product descripton: ");

               description = kbd.nextLine();

               System.out.println("Enter the amount: ");

               amount = Double.valueOf(kbd.nextLine());

               inventory.addProduct(new Product(prodname, description, amount));

               break;

       case 5: System.out.println("Enter the vendor name to remove a product: ");

               vendorname = kbd.nextLine();

               for(int j=0; j<inventoryList.size(); j++)

               {

                   if(inventoryList.get(j).getVendor().getName().equals(vendorname))

                   {

                       inventory = inventoryList.get(j);

                       inventoryIndex = j;

                       break;

                   }

               }

               System.out.println("Enter the product name to remove: ");

               prodname = kbd.nextLine();

               inventory.getProductList().remove(inventory.getProductIndex(prodname));

       }

       inventory.setDate(new Date());

       inventoryList.set(inventoryIndex, inventory);

   }

}

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