Results 1 to 3 of 3
  1. #1
    MikeJ39 is offline Member
    Join Date
    Oct 2011
    Posts
    38
    Rep Power
    0

    Unhappy Error in my code

    Can someone please help me i have an error in my code.

    C:\Java Test>javac InventoryPart4.java
    InventoryPart4.java:125: error: cannot find symbol
    if (current = inv.size()-1)
    ^
    symbol: variable inv
    1 error


    Java Code:
    import java.awt.BorderLayout;
    import java.awt.FlowLayout;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.text.DecimalFormat;
    
    import javax.swing.BorderFactory;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    
    public class InventoryPart4 extends JFrame {
    	private static DecimalFormat currency = new DecimalFormat("$#,##0.00");
    
    
    	private JTextField itemNumberTF;
    	private JTextField productNameTF;
    	private JTextField unitsInStockTF;
    	private JTextField priceTF;
    	private JTextField supplierNameTF;
    	private JTextField restockFeeTF;
    	private JTextField valueOfInventoryTF;
    
    	
    	private JTextField totalValueOfInventoryTF;
    
    	private JButton FirstBT;
    	private JButton BackBT;
    	private JButton nextBT;
        private JButton lastBT;
    	
    	private Supplier[] products;
    
    	
    	private int current = 0;
    
    	
    	public static void main(String[] args) {
    	
    		new InventoryPart4();
    	}
    
    	
    	public InventoryPart4() {
    		super("Inventory Part 4");
    		setSize(500, 300);
    		setLocationRelativeTo(null);
    		setDefaultCloseOperation(EXIT_ON_CLOSE);
    
    		
    		products = new Supplier[5];
    
    		
    		products[0] = new Supplier(500, "STYLUS", 10, 800, "Olympus");
    		products[1] = new Supplier(200, "COOLPIX", 20, 650, "Nikon");
    		products[2] = new Supplier(300, "Powershot", 15, 890, "Canon");
    		products[3] = new Supplier(350, "Cyber-shot", 10, 1200, "Sony");
    		products[4] = new Supplier(400, "Easyshare", 80, 1500, "Kodak");
    
    		
    		sortArray();
    
    		
    		createComponents();
    
    		
    		setVisible(true);
    
    		
    		updateFields();
    	}
    
    	private void createComponents() {
    		JPanel p = new JPanel();
    		p.setLayout(new BorderLayout());
    		p.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    
    		p.add(createFieldsPanel(), BorderLayout.CENTER);
    		p.add(createButtonsPanel(), BorderLayout.SOUTH);
    
    		setContentPane(p);
    	}
    
    	private JPanel createButtonsPanel() {
    		JPanel p = new JPanel();
    		p.setLayout(new FlowLayout(FlowLayout.RIGHT));
           
    	    FirstBT = new JButton("First");
    		FirstBT.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				current = 0;
    				updateFields();
    			}
    		});
    		p.add(FirstBT);
    		
    	    BackBT = new JButton("Back");
    		BackBT.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				if (current > 0) {
    					current--;
    					updateFields();
    				}
    			}
    		});
    		p.add(BackBT);
    
    		nextBT = new JButton("Next");
    		nextBT.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				if (current < products.length - 1) 
    					current++;
    					updateFields();
    				
    			}
    		});
    		p.add(nextBT);
    		
            lastBT = new JButton("Last");
    		lastBT.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				if (current > inv.size()-1)
    				updateFields();
    				
    			}
    		});
    		p.add(lastBT);
    		return p;
    	}
    
    	
    	protected void updateFields() {
    		Supplier s = products[current];
    
    		itemNumberTF.setText(String.valueOf(s.getItemNumber()));
    		productNameTF.setText(s.getProductName());
    		unitsInStockTF.setText(String.valueOf(s.getUnitsInStock()));
    		priceTF.setText(currency.format(s.getPrice()));
    		supplierNameTF.setText(s.getSupplierName());
    		restockFeeTF.setText(currency.format(s.calculateRestockFee()));
    		valueOfInventoryTF.setText(currency.format(s.calculateInventory()));
    
    		totalValueOfInventoryTF.setText(currency.format(calculateInventory()));
    	}
    
    	private JPanel createFieldsPanel() {
    		JPanel p = new JPanel();
    		p.setLayout(new GridLayout(0, 2, 5, 5));
    
    		p.add(new JLabel("Item Number"));
    		itemNumberTF = new JTextField();
    		p.add(itemNumberTF);
    
    		p.add(new JLabel("Product Name"));
    		productNameTF = new JTextField();
    		p.add(productNameTF);
    
    		p.add(new JLabel("Units In Stock"));
    		unitsInStockTF = new JTextField();
    		p.add(unitsInStockTF);
    
    		p.add(new JLabel("Unit Price"));
    		priceTF = new JTextField();
    		p.add(priceTF);
    
    		p.add(new JLabel("Supplier Name"));
    		supplierNameTF = new JTextField();
    		p.add(supplierNameTF);
    
    		p.add(new JLabel("Restock Fee"));
    		restockFeeTF = new JTextField();
    		p.add(restockFeeTF);
    
    		p.add(new JLabel("Value Of Inventory"));
    		valueOfInventoryTF = new JTextField();
    		p.add(valueOfInventoryTF);
    
    		p.add(new JLabel(""));
    		p.add(new JLabel(""));
    
    		p.add(new JLabel("Value Of The Entire Inventory"));
    		totalValueOfInventoryTF = new JTextField();
    		p.add(totalValueOfInventoryTF);
    
    		return p;
    	}
    
    	
    	public double calculateInventory() {
    		double value = 0;
    		for (int i = 0; i < products.length; i++) {
    			value += products[i].calculateInventory();
    		}
    		return value;
    	}
    
    	
    	public void sortArray() {
    		int n = products.length; 
    		boolean swapped;
    		do {
    			swapped = false;
    			for (int i = 0; i < n - 1; i++) {
    				String name1 = products[i].getProductName();
    				String name2 = products[i + 1].getProductName();
    				if (name1.compareToIgnoreCase(name2) > 0) {
    					
    					Supplier temp = products[i];
    					products[i] = products[i + 1];
    					products[i + 1] = temp;
    					swapped = true;
    				}
    			}
    			n = n - 1;
    		} while (swapped);
    	}
    }

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,528
    Blog Entries
    7
    Rep Power
    20

    Default Re: Error in my code

    I did a text search on "inv" but I can't find that variable either ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    milovan is offline Senior Member
    Join Date
    Jan 2011
    Location
    Belgrade, Serbia
    Posts
    301
    Rep Power
    4

Similar Threads

  1. error code help please..
    By andnlou2678 in forum New To Java
    Replies: 7
    Last Post: 10-07-2011, 12:11 AM
  2. error in code
    By Akap in forum New To Java
    Replies: 4
    Last Post: 01-31-2011, 06:37 AM
  3. error in this code
    By gradiente99 in forum Eclipse
    Replies: 11
    Last Post: 07-20-2010, 05:58 PM
  4. Error Code???
    By andmartha in forum New To Java
    Replies: 11
    Last Post: 10-04-2008, 02:16 AM
  5. Pls help with a code error.
    By saytri in forum New To Java
    Replies: 8
    Last Post: 12-24-2007, 08:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •