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

The BMC Parts Company needs a program that will read the inventory.txt file and

ID: 3817056 • Letter: T

Question

The BMC Parts Company needs a program that will read the inventory.txt file and create an inventory report based on the data in the file. The inventory.txt file contains the part number, opening balance, number of items sold, and the minimum stock required. The output file, inventoryNeeded.txt, will contain the part number, current balance and the amount that is necessary to bring the inventory to the minimum level.
In this assignment, students will design the logic for the program that reads the input file and creates the output file. Files provided include inventory.txt and the partially completed program inventoryNeeded.java. The program file provided includes the necessary variable declarations and input and output file statements. You need to write the part of the program that reads the input file, calculates the current balance and amount required to bring the inventory to the minimum level. Then output the part number, current balance and the amount needed to the output file.

inventory.txt file contains:

QA310
95
47
50
CM145
320
162
200
MS514
34
20
25
EN212
163
150
160

inventory Needed Notepad File Edit Format View Help Part Number: QA310 Current Balance: 48 Amount Needed: 2 Part Number CM145 Current Balance: 158 Amount Needed: 42 Part Number MS514 Current Balance: 14 Amount Needed: 11 Part Number EN212 Current Balance: 13 Amount Needed: 147

Explanation / Answer

inventoryNeeded.java

package com.code.programs.chegg;

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.FileReader;

import java.io.FileWriter;

import java.io.IOException;

public class inventoryNeeded {

  

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

   {

       BufferedReader br = new BufferedReader(new FileReader("inventory.txt")); //Creating reader for reading data from inventory.txt

       BufferedWriter bw = new BufferedWriter(new FileWriter("inventoryNeeded.txt")); //Creating writer for writing data to inventoryNeeded.txt

       String str="";

       int openingBalance,itemSold,mininumRequired,currentBalance;

       while((str=br.readLine())!=null)   //Reading data from file till null is found

       {

           //Writing the part number to file

           bw.write("Part Number: "+str);bw.newLine();

          

          

           //Reading openingBalance,itemSold and mininumRequired and converting them to integer

           openingBalance = Integer.parseInt(br.readLine());

           itemSold = Integer.parseInt(br.readLine());

           mininumRequired = Integer.parseInt(br.readLine());

          

           currentBalance = openingBalance - itemSold;   //Calculating the currentBalance

          

           //Writing the data to file

           bw.write("Current Balance: "+currentBalance);bw.newLine();

           bw.write("Amount Needed: "+(mininumRequired - currentBalance));bw.newLine();

           bw.newLine();

       }

       //Closing the reader and writer

       br.close();

       bw.close();

      

   }

  

}