I have been working on this program for about a week and for some reason it works fine until i start adding buttons. I needed to modify my program to navigate buttons (First, Previous, Next and Last) to the GUI that allows the user to move to the first item, the previous item, the next item, and the last item in the inventory. If the first item is displayed and the user clicks on the Previous button, the last item should be displayed. If the last item is displayed and the user clicks on the Next button, the first item should displayed. The thing is my I keep getting error's. I think it is my packages or my imports. I must be missing something but I am not sure what?
Here is my code:I also have my product classimport java.awt.*; import javax.swing.*; import java.text.NumberFormat; import java.util.Locale; import java.util.Arrays; public class InventoryPart5 { public static Printer[] sortArray(Printer[] printers) { String[] productName = new String[printers.length]; Printer[] serialNumber = new Printer [printers.length]; for (int i = 0; i < printers.length; i++) { productName[i] = printers[i].getProductName(); } Arrays.sort(productName); for (int i = 0; i < printers.length; i++) { for (int j = 0; j < productName.length; j++) { if (printers[i].getProductName().equalsIgnoreCase(productName[j])) { serialNumber[j] = printers[i]; } } } return serialNumber; } public static double totalInventory(Printer[] printers) { double total = 0; for (int i = 0; i < printers.length; i++) { total += printers[i].totalInventory(); } return total; } public static void main (String args[]) { NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US); //create inventory items in array Printer brother = new Printer("P1101", "Brother Inkjet Muliti-function Printer", 12, 217.60, "BroLM200"); Printer canon = new Printer("P1102","Canon Bubble Jet Photo Printer", 13, 1249.98, "CanJPH300"); Printer dell = new Printer("P1103", "Dell Multi-Function Laser Printer", 3, 149.99, "DelMFL400"); Printer hp = new Printer("P1104","HP LaserJet Printer" , 5, 149.99, "HPL500"); Printer lexmar = new Printer("P1105","Lexmar CLP Printer", 10, 299.98, "LexCLP600"); final Printer[] printerList = new Printer[5]; printerList[0] = brother; printerList[1] = canon; printerList[2] = dell; printerList[3] = hp; printerList[4] = lexmar; //calculate inventory total double totalInventory = totalInventory(printerList); //initialize the JTextArea Class and set the parameters final JTextArea textArea = new JTextArea(7, 15); textArea.setText(""); textArea.setEditable(false); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new GridLayout(1, 3)); JButton firstButton = new JButton("First"); buttonPanel.add(firstButton); firstButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { printerIndex = 0; prepareDisplay(printerList[printerIndex], textArea); } }); JButton lastButton = new JButton("Last"); buttonPanel.add(lastButton); lastButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { printerIndex = (printerList.length - 3); prepareDisplay(printerList[printerIndex], textArea); } }); JLabel logoLabel = new JLabel (new ImageIcon("CompanyLogo.jpg")); JPanel logoPanel = new JPanel(); logoPanel.add(logoLabel); JPanel centerPanel = new JPanel(); centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.Y_AXIS)); centerPanel.add(prepareDisplay(printerList[printerIndex], textArea)); //prepare the text that will be displayed in the GUI for (int i = 0; i < printerList.length; i++ ) { textArea.append(printerList[i]); } //initialize the GUI window and set the parameters JFrame frame = new JFrame(); frame.setLayout(new BorderLayout()); frame.add(logoPanel, BorderLayout.NORTH); frame.add(buttonPanel, BroderLayout.SOUTH); frame.add(CenterPanel, BorderLayout.CENTER); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); textArea.append("\nTotal Inventory: " + nf.format(totalInventory)); }//end main }//end Iventory classMy errors are on these lines won't copy and paste because Im using textPad unfortunately. I am getting errors like: can't find symbol for:import java.text.NumberFormat; import java.util.Locale; import java.util.Arrays; class Printer { //declare class variables private String itemNumber; private String productName; private int unitsInStock; private double unitPrice; private double totalInventory; private String serialNumber; private double restockFee; NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US); //class constructor public Printer (String itemNumber, String productName, int unitsInStock, double unitPrice, String serialNumber){ this.itemNumber = itemNumber; this.productName = productName; this.unitsInStock = unitsInStock; this.unitPrice = unitPrice; this.serialNumber = serialNumber; this.restockFee = restockFee; } //get and set methods //item number public String getItemNumber(){ return itemNumber; } public void setItemNumber(String itemNumber){ this.itemNumber = itemNumber; } //printer name public String getProductName(){ return productName; } public void setProductName(String productName){ this.productName = productName; } //available units public int getUnitsInStock(){ return unitsInStock; } public void setUnitsInStock (int unitsInStock){ this.unitsInStock = unitsInStock; } //price public double getUnitPrice(){ return unitPrice; } public void setUnitPrice (double unitPrice){ this.unitPrice = unitPrice; } //calculate the total inventory public double totalInventory() { return unitPrice * unitsInStock; } public double restockFee() { return unitPrice * .05; } //out put the variables with a toString method public String toString () { return "Item Number: " + itemNumber + "\nProduct Name: " + productName + "\nUnits In Stock: " + unitsInStock + "\nPrice : " + nf.format(unitPrice) + "\nTotal Value: " + nf.format(totalInventory()) + "\nSerial Number: " + serialNumber + "\nRestock Fee: " + nf.format(restockFee()); } }//end Printer class class Laser extends Printer { //class variables public String serialNumber; public double restockFee; public static final double RESTOCK_FEE_PERCENTAGE = .05; //class constructor public Laser (String itemNumber, String productName, int unitsInStock, double unitPrice, double totalInventory, String serialNumber) { super(itemNumber, productName, unitsInStock, unitPrice, serialNumber); this.serialNumber = serialNumber; //calculate the restock fee restockFee = unitPrice * RESTOCK_FEE_PERCENTAGE; } //get and set methods public String getSerialNumber() { return serialNumber; } public void setSerialNumber(String serialNumber) { this.serialNumber = serialNumber; } public double getRestockFee() { return restockFee; } // output restock fee and serial number public String toString () { return super.toString() + "\n" + "Serial Number: " + serialNumber + "Restock Fee:" + nf.format(getRestockFee()); } }
1) printerIndex = 0;
2) prepareDisplay(printerList[printerIndex], textArea);
3) method prepareDisplay(Printer, javax.swing.JTextArea)
4) location Class Inventory 5 centerPanel.add(prepareDisplay(printerList[printerIndex], textArea));
And so many more. I really think I am missing a package.