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

Can you help me with this problem? The last person who did this wrote a bad code

ID: 3772985 • Letter: C

Question

Can you help me with this problem? The last person who did this wrote a bad code. And can you use a try-catch in the main method.

Write an inventory manager program in Java. The information about what stock you have on hand is stored in a le. Your program will read the items you have in stock from a le. Each line read from the le 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 le named Item to your project. 1.3 Download the items le

File:

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

1.4 Copy/Move the le to the project folder named InventoryManager. This should be inside your NetBeans Project Folder.

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

3 Implement InventoryManager.java Class, do the following: – Write a class method called printInventory which takes an Array of Items as its parameter. This method will print the entire inventory to the console. – Write a class method called checkLowInventory which takes an Array of Items as its parameter. This method checks for items that have fewer quantity than 5, and prints them in the same format as printInventory does. If there is no such item then print an appropriate message. – Write a class method called totalInventoryValue which takes an Array of Items as its parameter. This method computes the total value of the current inventory using the quantity and price per unit information, and prints that total value to the console. In the main method: 3.1 Use File class and Scanner class to read the items and related information from the le provided with this assignment. It is available on ilearn. 3.2 For every item in this le create a new object of the Item class with appropriate values. 3.3 Let all the objects be a part of an array. There are 10 items in the le. 3.4 Then print the following menu to the console : PrintInventory (p) Check Low inventory (c) Print Total Value of inventory (v) Exit (e) 3.5 Prompt the user to enter an option. Read this option in as a char. You can assume they will enter a lower case character and that the input will be valid. 3.6 Depending on the option entered you will do the following: If the user enters p, call printInventory method If the user enters c, call checkLowInventory method If the user enters v, call totalInventoryValue method If the user enters e, Program Exits 3.7 Loop steps 3.4 to 3.6 until the user enters e as an option.

Explanation / Answer

PROGRAM:

import java.io.*;
import java.util.*;
class Item
{
String name;
int quantity;
double price;
Item()
{}
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;
}
String getName()
{
return name;
}
double getPrice()
{
return price;
}
int getQuantity()
{
return quantity;
}
}

public class InventoryManager {
public static void main(String []args)
{String name;
int quantity;
double price;
char select;
int j=0;
String [][]Inventory=new String[10][3];
Item []InventoryItems=new Item[10];
  
try {
           File file = new File("C:\Users\MDR\Documents\NetBeansProjects\JavaApplication2\src\inventory.txt");
           FileReader fileReader = new FileReader(file);
           BufferedReader bufferedReader = new BufferedReader(fileReader);
           StringBuffer stringBuffer = new StringBuffer();
           String line;
  
while ((line = bufferedReader.readLine()) != null) {
               Inventory[j]=line.split(" ");
System.out.println(line);
name=Inventory[j][0];
quantity=Integer.parseInt(Inventory[j][1]);
price=Double.parseDouble(Inventory[j][2]);
Item it=new Item(name,quantity,price);
InventoryItems[j]=it;
j++;
           }
}
catch (IOException e) {
           e.printStackTrace();
       }
  
while(true)
{
System.out.println("PrintInventory (p) Check Low inventory (c) Print Total Value of inventory (v) Exit (e)");
Scanner scan=new Scanner(System.in);
select=scan.next().charAt(0);
switch(select)
{
case 'p': printInventory(InventoryItems);
break;
case 'c':checkLowInventory(InventoryItems);
break;
case 'v':totalInventoryValue(InventoryItems);
break;
case 'e':System.exit(0);
break;
default:System.out.println("wrong option");
  
}
}
  
}
public static void printInventory(Item items[])
{
System.out.println("stock quantity price");
for(int i=0;i<items.length;i++)
{
System.out.println(items[i].getName()+" "+items[i].getQuantity()+ " "+items[i].getPrice());
  
}
  
}
public static void checkLowInventory(Item items[])
{
System.out.println("stock quantity price");   
for(int i=0;i<items.length;i++)
{
if(items[i].getQuantity()<5)
System.out.println(items[i].getName()+" "+items[i].getQuantity()+ " "+items[i].getPrice());
  
}
}
public static void totalInventoryValue(Item items[])
{double totalInventory=0;
for(int i=0;i<items.length;i++)
{
totalInventory+=items[i].getQuantity()*items[i].getPrice();
  
  
}
System.out.println("TotalInventory="+totalInventory);
}
  
}

OUTPUT:

run:
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
PrintInventory (p) Check Low inventory (c) Print Total Value of inventory (v) Exit (e)
p
stock quantity price
Paper 10 5.99
ColoredPaper 10 6.99
PaperClips 55 0.99
Staples 1000 0.1
Chairs 3 49.99
Pens 500 0.75
Pencils 500 0.1
Highlighters 100 1.0
Toner 2 69.99
Post-its 100 1.99
PrintInventory (p) Check Low inventory (c) Print Total Value of inventory (v) Exit (e)
c
stock quantity price
Chairs 3 49.99
Toner 2 69.99
PrintInventory (p) Check Low inventory (c) Print Total Value of inventory (v) Exit (e)
v
TotalInventory=1298.2
PrintInventory (p) Check Low inventory (c) Print Total Value of inventory (v) Exit (e)
e
BUILD SUCCESSFUL (total time: 48 seconds)

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