3 Replies - 252 Views - Last Post: 07 June 2014 - 01:37 PM Rate Topic: -----

#1 animae_damnatae  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 07-June 14

Java Inventory Program Assignment

Posted 07 June 2014 - 09:28 AM

I am having trouble with an assignment. I feel as if I do not understand what is happening. I do not get any errors. Instead, I don't get the results that I am looking for. I will post the assignment below. Out of what is required, I have gotten the add feature to work. The delete feature works but it delete's the record before the record that is currently displayed in the GUI. The save feature creates the text file but nothing is written to it. I cannot figure out where to begin with modify. The search feature doesn't pull up the record that I search for.

Here is the assignment:

The application includes an add button, a delete button, and a modify button on the GUI that allow the user to perform these actions on the item name, the number of units in stock and the price of each unit.
The application includes a save button on the GUI that allows the user to save the inventory to a C:\data\inventory.dat file.
The application uses exception handling to create a directory and file if necessary when the inventory is saved.
The application includes a search button on the GUI that allows the user to search for an item in the inventory by the name of the product.
Once the search button is activated, the application displays the product’s information in the GUI if the product being searched for is found, or displays an appropriate message to the user if the product being searched for is not found.

I am not asking for you to do my homework. I just don't understand why this is not working and any useful tips would be appreciated as this assignment is due tomorrow. I am a novice so please excuse my poor coding techniques.

Thanks!

package it215week9;

import java.io.Serializable;

/**
 * A class that implements the product class for the CD product.
 *
 * 
 */
public class CDProduct implements Serializable {

    private String name;
    private int itemNum;
    private int items;
    private double price;

    public int getItemNum() {
        return itemNum;
    }

    public void setItemNum(int itemNum) {
        this.itemNum = itemNum;
    }

    public int getItems() {
        return items;
    }

    public void setItems(int items) {
        this.items = items;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    /**
     * Default constructor
     */
    public CDProduct() {

    }//end default constructor


    /**
     * Constructor with parameters
     *
     * @param name
     * @param itemNum
     * @param items
     * @param price
     */
    public CDProduct(String name, int itemNum, int items, double price) {
        this.name = name;
        this.itemNum = itemNum;
        this.items = items;
        this.price = price;
    }//end constructor

    public double getInventoryValue() {
        return (items * price);
    }

    public String toString() {
        return "Name:" + name + " Item:" + itemNum + " Items:" + items + " Price:" + price + " Value:" + getInventoryValue();
    }
}



package it215week9;

/**
 * Extends the CDProduct class and adds the genre attribute
 */
public class ExtendedCDProduct extends CDProduct {

    String genre;
    double restockingFee=0.05;

    public ExtendedCDProduct(String name, int itemNum, int items, double price, String genre) {
        super(name,itemNum,items,price);
        this.genre = genre;
    }//end constructor

    public String getGenre() {
        return genre;
    }

    public void setGenre(String genre) {
        this.genre = genre;
    }

    @Override
    public String toString() {
        return super.toString()+" Genre:"+getGenre();
    }

    @Override
    public double getInventoryValue() {
        double inventoryValue = super.getInventoryValue();
        //add the restocking fee
        inventoryValue = (1+restockingFee)*inventoryValue;
        return inventoryValue;
    }

}



package it215week9;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import java.io.Serializable;
import java.lang.SecurityException;
import java.util.Formatter;
import java.util.FormatterClosedException;
import java.util.NoSuchElementException;
import java.util.Scanner;
import javax.swing.JOptionPane;

/**
 * This class uses an array to manage the Inventory of CDs.
 */
public class Inventory implements Serializable {

    private Formatter output;
    CDProduct[] inventory = new CDProduct[10];
    int current = 0;
    //Location where the inventory will be saved.
    String path;
    public static final String FILE_NAME = "inventory.dat";

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public Inventory(int len) {
        inventory = new CDProduct[len];
    }

    /**
     * Add a CD to the inventory.
     * @param cd
     * @throws Exception
     */
    public void addCDProduct(CDProduct cd) throws Exception {
        if (current < inventory.length) {
            inventory[current++] = cd;
        } else {
            throw new Exception("Inventory is full. No items can be added.");
        }
    }

    public void deleteCDProduct(int index){
        //implement this method
        
        if (index < current){
            for (int i = index; i < (current-1); i++){
            //inventory = inventory;
        }
            current = current-1;
        }

    /**
     * sorts the array by cd name.
     */
    public void sort() {
        int len = current; //current length of the array
        for (int i = 0; i < len; i++) {
            for (int j = i; j < len; j++) {
                if (inventory[i].getName().compareToIgnoreCase(inventory[j].getName()) > 0) {
                    CDProduct temp = inventory[j];
                    inventory[j] = inventory[i];
                    inventory[i] = temp;
                }
            }
        }
    }
    /**
     * Returns the index of the CD if found for the given name. If the CD is not found returns -1
     * @param name
     * @return
     */
    public int search(String name) {
        //*******  implement the search method here. This method would search the array of inventory items to find the index of the
        //the matching item and return it. If no match is found then it would return -1.
        
        CDProduct item = inventory[0];
        
        int foundIndex = -1;
        
        for (int i = 0; inventory.length >= i; i++)
        {
            if(item.getName().equalsIgnoreCase(name))
               i = foundIndex;
                return i;
        }
        return -1;
    }
    

    /**
     * Get the total inventory
     * @return
     */
    public double calculateTotalInventory() {
        double totalValue = 0;
        for (int i = 0; i < current; i++) {
            CDProduct cd = inventory[i];
            totalValue += cd.getInventoryValue();
        }
        return totalValue;
    }

    /**
     * Gets the number of items in the inventory
     * @return
     */
    public int getNumberOfItems() {
        return current;
    }

    public CDProduct getItem(int index) {
        return inventory[index];
    }

    public void printInventory() {
        System.out.println("Current Inventory:");
        for (int i = 0; i < current; i++) {
            System.out.println(inventory[i]);
        }
        System.out.println("The total value of the inventory is:" + calculateTotalInventory());
    }
    
    

    public void saveInventory() {
        //********* Implement the  method to save the inventory to  a file.
        
        CDProduct record = new CDProduct();
        
        //File dir = new File("C:\\inventory.txt");
        //boolean fileCreated = false;
        //try{
        //    fileCreated = dir.createNewFile();
       // }
        //catch(IOException e){
        //    System.err.println(e);
        
        //if (fileCreated){
        //    System.out.println("Created file: " + dir.getPath());
        //}
        
        //if (dir.exists()){
        
            for (int i = 0; i < current; i++)
                try{
                
                    output = new Formatter("C:\\inventory.txt");
                    
                    record.setName(record.getName());
                    record.setItemNum(record.getItemNum());
                    record.setItems(record.getItems());
                    record.setPrice(record.getPrice());
                    
                    //if (record.getItems()>0){
                        output.format("%d %s %s %2f\n", record.getName(), record.getItemNum(), record.getItems(), record.getPrice());
                    }
            catch(FileNotFoundException fileNotFoundException){
                    System.err.println("Error: " + fileNotFoundException);
                    System.exit(1);
            }
    } 
}



package it215week9;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.net.URL;
import javax.swing.ImageIcon;
import java.awt.Image;
import java.awt.event.ActionListener;
import java.io.File;
import java.text.NumberFormat;
import java.text.ParseException;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 * Main class for Week 8 inventory.
 */
public class InventoryProgramPart6 extends JFrame implements ActionListener {

    //Labels for different buttons
    public static final String NEXT = "Next";
    public static final String PREVIOUS = "Previous";
    public static final String LAST = "Last";
    public static final String FIRST = "First";
    public static final String SEARCH = "Search";
    public static final String SEARCH_GUI = "SearchGUI";
    public static final String SAVE = "Save";
    public static final String LOAD = "Load";
    public static final String ADD = "Add";
    public static final String ADD_GUI = "AddGUI";
    public static final String MODIFY = "Modify";
    public static final String MODIFY_GUI = "ModifyGUI";
    public static final String DELETE = "Delete";
    public static final String PATH = "c:\\data";
    Inventory cdInventory; //Creates the CD inventory
    // GUI elements for displaying information on the currently-selected items
    private final JLabel nameLabel = new JLabel(" CD Name: ");
    private JTextField nameText;
    private final JLabel numberLabel = new JLabel(" Item Number: ");
    private JTextField numberText;
    private final JLabel genreLabel = new JLabel(" Genre: ");
    private JTextField genreText;
    private final JLabel priceLabel = new JLabel(" Price: ");
    private JTextField priceText;
    private final JLabel quantityLabel = new JLabel(" Quantity: ");
    private JTextField quantityText;
    private final JLabel valueLabel = new JLabel(" Value: ");
    private JTextField valueText;
    private final JLabel totalValueLabel = new JLabel(" Inventory Total: ");
    private JLabel totalValueText;
    //The index of the item being displayed
    private int index = 0;
    private JButton nextButton = new JButton();
    private JButton previousButton = new JButton();
    private JButton firstButton = new JButton();
    private JButton lastButton = new JButton();
    private JButton searchButton = new JButton();
    //declare the new buttons
    private JButton saveButton = new JButton();
    private JButton addButton = new JButton();
    private JButton modifyButton = new JButton();
    private JButton deleteButton = new JButton();

    public InventoryProgramPart6() {
    }

    public void initialize() {

        JPanel centerPanel = new JPanel(new GridLayout(8, 2, 0, 4)); //Panel for collecting all the components.

        centerPanel.add(nameLabel);
        nameText = new JTextField("");
        nameText.setEditable(false);
        centerPanel.add(nameText);

        centerPanel.add(numberLabel);
        numberText = new JTextField("");
        numberText.setEditable(false);
        centerPanel.add(numberText);

        centerPanel.add(genreLabel);
        genreText = new JTextField("");
        genreText.setEditable(false);
        centerPanel.add(genreText);

        centerPanel.add(priceLabel);
        priceText = new JTextField("");
        priceText.setEditable(false);
        centerPanel.add(priceText);

        centerPanel.add(quantityLabel);
        quantityText = new JTextField("");
        quantityText.setEditable(false);
        centerPanel.add(quantityText);

        centerPanel.add(valueLabel);
        valueText = new JTextField("");
        valueText.setEditable(false);
        centerPanel.add(valueText);

        //The following adds information on the whole inventory to the panel
        centerPanel.add(totalValueLabel);
        totalValueText = new JLabel("");
        centerPanel.add(totalValueText);

        getContentPane().add(centerPanel, BorderLayout.CENTER); //Panel is added to the center of the GUI

        //Add the buttons to the content pane

        JPanel buttonPanel = new JPanel(); //GUI set-up
        //Add the buttons to the GUI
        nextButton.setText(NEXT);
        nextButton.setActionCommand(NEXT);
        nextButton.addActionListener(this);
        previousButton.setText(PREVIOUS);
        previousButton.setActionCommand(PREVIOUS);
        previousButton.addActionListener(this);
        firstButton.setText(FIRST);
        firstButton.setActionCommand(FIRST);
        firstButton.addActionListener(this);
        lastButton.setText(LAST);
        lastButton.setActionCommand(LAST);
        lastButton.addActionListener(this);
        searchButton.setText(SEARCH);
        searchButton.setActionCommand(SEARCH_GUI);
        searchButton.addActionListener(this);

        buttonPanel.add(firstButton);
        buttonPanel.add(previousButton);
        buttonPanel.add(nextButton);
        buttonPanel.add(lastButton);
        buttonPanel.add(searchButton);


        JPanel bottomButtonPanel = new JPanel(); //GUI set-up
        saveButton.setText(SAVE);
        saveButton.setActionCommand(SAVE);
        saveButton.addActionListener(this);

        addButton.setText(ADD);
        addButton.setActionCommand(ADD_GUI);
        addButton.addActionListener(this);
        modifyButton.setText(MODIFY);
        modifyButton.setActionCommand(MODIFY_GUI);
        modifyButton.addActionListener(this);
        deleteButton.setText(DELETE);
        deleteButton.setActionCommand(DELETE);
        deleteButton.addActionListener(this);
        bottomButtonPanel.add(saveButton);
        bottomButtonPanel.add(addButton);
        bottomButtonPanel.add(modifyButton);
        bottomButtonPanel.add(deleteButton);


        getContentPane().add(buttonPanel, BorderLayout.NORTH); //FlowLayout panel for collecing all buttons
        getContentPane().add(bottomButtonPanel, BorderLayout.SOUTH);
        //Add the logo to the GUI
        URL url = this.getClass().getResource("logo.jpg");
        Image img = Toolkit.getDefaultToolkit().getImage(url);
        Image scaledImage = img.getScaledInstance(100, 50, Image.SCALE_AREA_AVERAGING); // scale logo to fit GUI

        // create JLabel with logo as label's icon
        Icon logoIcon = new ImageIcon(scaledImage);
        JLabel companyLogoLabel = new JLabel(logoIcon);
        getContentPane().add(companyLogoLabel, BorderLayout.WEST); // add logo to GUI

        paint(0);
    }

    /**
     * Displays the next item
     */
    public void displayNextItem() {
        index++; //Moves the program forward by one item


        if (index == cdInventory.getNumberOfItems()) //Checks if there is a next item to move on to
        {
            //If the program reaches the last item in the list, it cannot move forward so it must go to first item
            index = 0;
        }

        paint(index);

    }

    /**
     * Displays the previous item
     */
    public void displayPreviousItem() {
        index--; //Moves the program back by one item


        if (index < 0) //Checks if there is a next item to move on to
        {
            //If the program reaches the first item in the list, it cannot move back so it must become last item
            index = cdInventory.getNumberOfItems() - 1;
        }

        paint(index);
    }

    /**
     * Displays the first item
     */
    public void displayFirstItem() {

        index = 0;

        paint(index);

    }

    /**
     * Displays the last item
     */
    public void displayLastItem() {


        index = cdInventory.getNumberOfItems() - 1;

        paint(index);

    }

    /**
     * Saves the inventory to the PATH location
     */
    public void saveInventory() {
        //This method uses the save functionality implemented in the Inventory class to save the inventory.
        cdInventory.setPath(PATH);
        cdInventory.saveInventory();
    }
    
    /**
     * Display the GUI for user to enter the CD name for searching
     */
    public void displayGUIForSearch() {
        //*************
        //Dispaly a dialog to get the name from the user to search
        //Use the value returned to invoke the search method below
        String s = (String)JOptionPane.showInputDialog(
                    this,
                    "Enter the name of the product to search",
                    "Customized Dialog",
                    JOptionPane.PLAIN_MESSAGE,
                    null,
                    null,
                    null);
        search(s);
    }

    /**
     * Searches the inventory for the name entered on the GUI. If found displays the item
     * @param searchText
     */
    public void search(String searchText) {
        //************
        //Use this method to get the value in the nameText field and then use the inventory to search the array, set the index to the matched value and display it. enable the buttons
        //If no match is found then display a dialog to show that no match is found. and display the previously displayed item.
        
        {
            index = cdInventory.search(searchText);
            if (index < 0){
           JOptionPane.showMessageDialog(null,"CD not found! Try again...");
            }
        paint(index);    
        }
    }

    /**
     * Disable all buttons on the GUI
     */
    public void disableButtons() {
        nextButton.setEnabled(false);
        previousButton.setEnabled(false);
        firstButton.setEnabled(false);
        lastButton.setEnabled(false);
        searchButton.setEnabled(false);
        addButton.setEnabled(false);
        modifyButton.setEnabled(false);
        deleteButton.setEnabled(false);
        saveButton.setEnabled(false);
    }

    /**
     * Enables all buttons on the GUI
     */
    public void enableButtons() {
        nextButton.setEnabled(true);
        previousButton.setEnabled(true);
        firstButton.setEnabled(true);
        lastButton.setEnabled(true);
        searchButton.setEnabled(true);
        addButton.setEnabled(true);
        modifyButton.setEnabled(true);
        deleteButton.setEnabled(true);
        saveButton.setEnabled(true);
    }

    /**
     * Displays the GUI to Add an item
     */
    public void displayGUIForAdd() {

        disableButtons();
        addButton.setEnabled(true);
        addButton.setActionCommand(ADD);
        //************
        //Implement this method to make the text fields editable and set them to empty.
        nameText.setText("");
        nameText.setEditable(true);
        numberText.setText("");
        numberText.setEditable(true);
        genreText.setText("");
        genreText.setEditable(true);
        priceText.setText("");
        priceText.setEditable(true);
        quantityText.setText("");
        quantityText.setEditable(true);
        valueText.setText("");

    }

    /**
     * Displays the GUI for editing an item;
     */
    public void displayGUIForModify() {
        disableButtons();
        modifyButton.setEnabled(true);
        modifyButton.setActionCommand(MODIFY);
        //******** Implement this to make the text fields editable
        nameText.setEditable(true);
        numberText.setEditable(true);
        genreText.setEditable(true);
        priceText.setEditable(true);
        quantityText.setEditable(true);
    }

    /**
     * Extracts the information from the GUI to create a CDProduct
     * @return the CDProduct from the GUI
     */
    public CDProduct getCDFromGUI() {
        String name = nameText.getText();
        String numberString = numberText.getText();
        String quantityString = quantityText.getText();
        String genre = genreText.getText();
        String priceString = priceText.getText();
        int number = 0;
        try {
            number = Integer.parseInt(numberString);
        } catch (NumberFormatException nfe) {
            JOptionPane.showMessageDialog(this, "Please enter a valid item number. " + numberString + " is not valid.");
            numberText.setText("");
            return null;
        }
        int quantity = 0;
        try {
            quantity = Integer.parseInt(quantityString);
        } catch (NumberFormatException nfe) {
            JOptionPane.showMessageDialog(this, "Please enter a valid quantity " + quantityString + " is not valid.");
            quantityText.setText("");
            return null;
        }
        double price = 0;
        try {
            NumberFormat currencyFormat = NumberFormat.getCurrencyInstance();
            price = currencyFormat.parse(priceString).doubleValue();
        } catch (ParseException nfe) {
            JOptionPane.showMessageDialog(this, "Please enter a valid price " + priceString + " is not valid.");
            priceText.setText("");
            return null;
        }
        CDProduct cd = new ExtendedCDProduct(name, number, quantity, price, genre);
        return cd;
    }

    /**
     * Adds an item from the GUI to the inventory
     */
    public void add() {

        //************
        //Implement this method to use the method getCDFromGUI to create a CDProduct object from the GUI
        //text fields and then use the cdInventory to add it to the inventory.get the index of the newly added item

            //The following code shows the newly added item and enable all the buttons and sets the add button to show the add GUI
            
        CDProduct cd = getCDFromGUI();
        if (cd != null){
            try{
                cdInventory.addCDProduct(cd);
            }catch (Exception e){
                JOptionPane.showMessageDialog(this, "Inventory is fulle. No more products can be added.");
            }
            index = cdInventory.current - 1;
        }
            paint(index);
            enableButtons();
            addButton.setActionCommand(ADD_GUI);
    }

    /**
     * Deletes the current item displayed on the GUI.
     */
    public void delete() {
        //*************
        //Implement this method to confirm from the user with a dialog to delete the item display.
        //If the user select "Yes" then delete the item from the inventory using the cdInventory
        
        //if(index != 0){
        //        JOptionPane.showMessageDialog(null, "RECORD DELETED", "RECORD DELETED", JOptionPane.PLAIN_MESSAGE);
        //        cdInventory.deleteCDProduct(index);
        //}
        
        CDProduct cd = getCDFromGUI();
        if (cd != null){
            try{
                cdInventory.deleteCDProduct(index);
            }catch (Exception e){
                JOptionPane.showMessageDialog(this, e);
            }
            index = 1;
        }
    }
    
    /**
     * Saves the updates from the GUI to the inventory
     */
    public void modify() {

        //*********
        //Implement this method to use the getCDFromGUI method to create a CDProduct object from the
        //displayed text fields once you have the CD then update the cd in the inventory to reflect the
        //update values. You will have set individual fields of the CD in the inventory.

           //The following code shows the updated item, enables buttons and resets the modify button to show modify GUI.
        
        //String name;
        //int number;
        //String genre;
        //int price;
        //int quantity;
        
        //name = nameText.getText();
        //number = Integer.parseInt(numberText.getText());
        //genre = genreText.getText();
        //price = Integer.parseInt(priceText.getText());
        //quantity = Integer.parseInt(quantityText.getText());
                
            paint(index);
            enableButtons();
            modifyButton.setActionCommand(MODIFY_GUI);
    }

    /**
     * Paints the item at the index location in the inventory
     * @param index
     */
    public void paint(int index) //This repaints the GUI with new information about the product
    {
        ExtendedCDProduct temp = (ExtendedCDProduct) cdInventory.getItem(index);

        if (temp != null) {
            nameText.setText(temp.getName());
            nameText.setEditable(false);
            numberText.setText("" + temp.getItemNum());
            numberText.setEditable(false);
            genreText.setText(temp.getGenre());
            genreText.setEditable(false);
            priceText.setText(String.format("$%.2f", temp.getPrice()));
            priceText.setEditable(false);
            quantityText.setText("" + temp.getItems());
            quantityText.setEditable(false);
            valueText.setText(String.format("$%.2f", temp.getInventoryValue()));
        }

        totalValueText.setText(String.format("$%.2f", cdInventory.calculateTotalInventory()));

    }

    public Inventory getCdInventory() {
        return cdInventory;
    }

    public void setCdInventory(Inventory cdInventory) {
        this.cdInventory = cdInventory;
    }

    public static void main(String args[]) {

        InventoryProgramPart6 productGUI = new InventoryProgramPart6(); //This GUI object holds up to 4 CDs
        //Create the inventory
        Inventory cdInventory = new Inventory(10);
        try {
            //The following adds items to the inventory
            cdInventory.addCDProduct(new ExtendedCDProduct("Notting Hill", 1, 20, 9.95, "Soundtrack"));
            cdInventory.addCDProduct(new ExtendedCDProduct("In Your Dreams ", 2, 20, 9.95, "Classic Rock"));
            cdInventory.addCDProduct(new ExtendedCDProduct("Back in Black", 3, 20, 10.95, "Hard Rock"));
            cdInventory.addCDProduct(new ExtendedCDProduct("The Three Kinds", 4, 20, 19.95, "Blues"));
        } catch (Exception e) {
            System.out.println("No more space to add items to inventory");
        }
        //Sort the inventory
        cdInventory.sort();

        productGUI.setCdInventory(cdInventory);

        //The following makes the GUI appear on-screen
        productGUI.initialize();
        productGUI.setDefaultCloseOperation(EXIT_ON_CLOSE);
        productGUI.pack();
        productGUI.setSize(600, 275);
        productGUI.setResizable(false);
        productGUI.setLocationRelativeTo(null);
        productGUI.setVisible(true);

        return;

    }
/**
 * Implements the ActionListener interface. Invokes the appropriate methods based on which
 * button is pressed by the user.
 * @param e
 */
    public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand().equals(NEXT)) {
            displayNextItem();
        } else if (e.getActionCommand().equals(PREVIOUS)) {
            displayPreviousItem();
        } else if (e.getActionCommand().equals(FIRST)) {
            displayFirstItem();
        } else if (e.getActionCommand().equals(LAST)) {
            displayLastItem();
        } else if (e.getActionCommand().equals(SAVE)) {
            saveInventory();
        }  else if (e.getActionCommand().equals(SEARCH_GUI)) {
            displayGUIForSearch();
        } else if (e.getActionCommand().equals(ADD_GUI)) {
            displayGUIForAdd();
        } else if (e.getActionCommand().equals(ADD)) {
            add();
        } else if (e.getActionCommand().equals(MODIFY_GUI)) {
            displayGUIForModify();
        } else if (e.getActionCommand().equals(MODIFY)) {
            modify();
        } else if (e.getActionCommand().equals(DELETE)) {
            delete();
        }
    }
}



Is This A Good Question/Topic? 0
  • +

Replies To: Java Inventory Program Assignment

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10442
  • View blog
  • Posts: 38,677
  • Joined: 27-December 08

Re: Java Inventory Program Assignment

Posted 07 June 2014 - 01:22 PM

Once you write to a File, make sure to close() the stream. That will cause the stream to be flushed and the data to be committed to the File.
Was This Post Helpful? 0
  • +
  • -

#3 animae_damnatae  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 07-June 14

Re: Java Inventory Program Assignment

Posted 07 June 2014 - 01:35 PM

Yes, that helped the data get pushed to the file. I am getting the wrong data, but this is a step in the right direction. Thank you!
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10442
  • View blog
  • Posts: 38,677
  • Joined: 27-December 08

Re: Java Inventory Program Assignment

Posted 07 June 2014 - 01:37 PM

Glad I could help!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1