Results 1 to 3 of 3
Thread: Error in my code
- 10-19-2011, 09:31 PM #1
Member
- Join Date
- Oct 2011
- Posts
- 38
- Rep Power
- 0
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); } }
- 10-19-2011, 09:36 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
Re: Error in my code
I did a text search on "inv" but I can't find that variable either ...
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 10-19-2011, 09:58 PM #3
Senior Member
- Join Date
- Jan 2011
- Location
- Belgrade, Serbia
- Posts
- 227
- Rep Power
- 3
Similar Threads
-
error code help please..
By andnlou2678 in forum New To JavaReplies: 7Last Post: 10-07-2011, 12:11 AM -
error in code
By Akap in forum New To JavaReplies: 4Last Post: 01-31-2011, 06:37 AM -
error in this code
By gradiente99 in forum EclipseReplies: 11Last Post: 07-20-2010, 05:58 PM -
Error Code???
By andmartha in forum New To JavaReplies: 11Last Post: 10-04-2008, 02:16 AM -
Pls help with a code error.
By saytri in forum New To JavaReplies: 8Last Post: 12-24-2007, 08:10 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks