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

    Default I cant get my code to compile Need help please

    Java Code:
    C:\Java Test>javac CameraInventory4.java
    CameraInventory4.java:16: error: class InventoryPart4 is public, should be decla
    red in a file named InventoryPart4.java
    public class InventoryPart4 extends JFrame {
           ^
    CameraInventory4.java:35: error: cannot find symbol
            private Supplier[] products;
                    ^
      symbol:   class Supplier
      location: class InventoryPart4
    CameraInventory4.java:17: error: cannot find symbol
            private static DecimalFormat currency = new decimalFormat("$#,##0.00");
                                                        ^
      symbol:   class decimalFormat
      location: class InventoryPart4
    CameraInventory4.java:120: error: cannot find symbol
                    Manufacturer = products[current];
                    ^
      symbol:   variable Manufacturer
      location: class InventoryPart4
    CameraInventory4.java:122: error: cannot find symbol
                    itemNumberTF.setText(String.valueOf(s.getItemNumber()));
                                                        ^
      symbol:   variable s
      location: class InventoryPart4
    CameraInventory4.java:123: error: cannot find symbol
                    productNameTF.setText(s.getProductName());
                                          ^
      symbol:   variable s
      location: class InventoryPart4
    CameraInventory4.java:124: error: cannot find symbol
                    unitsInStockTF.setText(String.valueOf(s.getUnitsInStock()));
                                                          ^
      symbol:   variable s
      location: class InventoryPart4
    CameraInventory4.java:125: error: cannot find symbol
                    priceTF.setText(currency.format(s.getPrice()));
                                                    ^
      symbol:   variable s
      location: class InventoryPart4
    CameraInventory4.java:126: error: cannot find symbol
                    supplierNameTF.setText(s.getSupplierName());
                                           ^
      symbol:   variable s
      location: class InventoryPart4
    CameraInventory4.java:127: error: cannot find symbol
                    restockFeeTF.setText(currency.format(calculateRestockFee()));
                                                         ^
      symbol:   method calculateRestockFee()
      location: class InventoryPart4
    CameraInventory4.java:154: error: cannot find symbol
                    ManufacturerNameTF = new JTextField();
                    ^
      symbol:   variable ManufacturerNameTF
      location: class InventoryPart4
    CameraInventory4.java:155: error: cannot find symbol
                    p.add(ManufacturerNameTF);
                          ^
      symbol:   variable ManufacturerNameTF
      location: class InventoryPart4
    12 errors
    
    
    
    
    
    
    
    
    
    
    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 priorBT;
    	private JButton nextBT;
    
    	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);
    
    		
    		Camera[] camera = new Camera[4];
    products[0] = new Manufacturer(500, "PowerShot", 10, 800, "Canon");
    
    products[1] = new Manufacturer(200, "STYLUS-5010", 20, 650, "Olympus");
    
    products[2] = new Manufacturer(300, "Cyber-Shot", 15, 890, "Sony");
    
    products[3] = new Manufacturer(350, "Point & Shoot", 10, 1200, "Nikon");
    
    products[4] = new Manufacturer(400, "EASYSHARE SPORT", 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));
    
    		priorBT = new JButton("Prior");
    		priorBT.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				if (current > 0) {
    					current--;
    					updateFields();
    				}
    			}
    		});
    		p.add(priorBT);
    
    		nextBT = new JButton("Next");
    		nextBT.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				if (current < products.length - 1) {
    					current++;
    					updateFields();
    				}
    			}
    		});
    		p.add(nextBT);
    
    		return p;
    	}
    
    	
    	protected void updateFields() {
    		Manufacturer = 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(calculateRestockFee()));
    		valueOfInventoryTF.setText(currency.format(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("Manufacturer Name"));
    		ManufacturerNameTF = new JTextField();
    		p.add(ManufacturerNameTF);
    
    		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; // size;
    		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) {
    					
    					Manufacturer temp = products[i];
    					products[i] = products[i + 1];
    					products[i + 1] = temp;
    					swapped = true;
    				}
    			}
    			n = n - 1;
    		} while (swapped);
    	}
    }
    Last edited by pbrockway2; 10-15-2011 at 05:07 AM. Reason: code tags corrected

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: I cant get my code to compile Need help please

    1) You never answered my question from your previous thread. Doing so may motivate me and others to help you more because it shows you don't ignore what we say and we're not wasting our time.
    2) Please re-read how to use code tags (I showed you how in your previous thread), and then please edit your original post above so that it's readable. If you do this, more will take the time to read it and help you.
    3) The errors are telling you what's wrong, and it's actually not all that cryptic. For instance if it says it can't find a symbol, then you need to check if the variable that you're trying to use has been declared anywhere. If it says that the class needs to be in its own file, then perhaps you're java class name and the file name are not exactly the same (counting capitalization and spelling).
    Last edited by Fubarable; 10-15-2011 at 04:09 AM.

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

    Default Re: I cant get my code to compile Need help please

    dude i have i have to say is you are dam rude ok you really need how to talk to people.

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: I cant get my code to compile Need help please

    I have corrected your code tags. The closing tag is [/code] with a /.

    Dealing with syntax is frustrating to begin with. The compiler will fault you for every mistake and will insist on 100% correctness at each step. A few coping strategies are: take a break when you need it, compile often (every line if need be!) and correct every mistake as it occurs, and find reliable tutorial style sources that provide examples of a technology and actually take the time to read and try what they are talking about. (skim reading - and, worse, skim viewing - won't help develop a sense of syntax. Java etc are languages and you learn them by using them)

    I can't really add to what Fubarable has said with respect to the source file name and the variables. The source .java file really does have to have the same name as the class. Likewise if you use a class like Supplier, then there had better be a Supplier.java file somewhere. And if you use a variable like s then that variable has to be declared somewhere.

    If you think you do have the source files named correctly, say what they are named and their directory structure and what command you are using to compile the code. Others can then possibly see what is going wrong. Likewise make sure you understand Java's "declare it before you use it" rule, or ask.

    -----

    Your remarks about Fubarable were untrue, uncalled for and unhelpful. I hope they were just a sign of frustration: if they were a genuine expression of what you consider a productive way of making progress, you are very wrong.

  5. #5
    MikeJ39 is offline Member
    Join Date
    Oct 2011
    Posts
    38
    Rep Power
    0

    Default Re: I cant get my code to compile Need help please

    ok i got the rest fix but this one can you help me?

    Java Code:
    C:\Java Test>javac CameraInventory4.java
    CameraInventory4.java:34: error: <identifier> expected
            manufacturer = new Products[5];
    ^

  6. #6
    MikeJ39 is offline Member
    Join Date
    Oct 2011
    Posts
    38
    Rep Power
    0

    Default Re: I cant get my code to compile Need help please

    Java Code:
    C:\Java Test>javac CameraInventory4.java
    CameraInventory4.java:34: error: <identifier> expected
             manufacturer = new Products[5];
    ^

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: I cant get my code to compile Need help please

    The code in the error message does not match any code that you've posted above. So this is obviously from new code, and since the error message in isolation doesn't tell us enough to see what you're doing wrong, you may wish to post the new code that generated this error.

    And again, maybe it's morbid curiosity on my part, but I still would like to know if my suggestion from your previous thread was correct. It took some effort to go through your code and come up with my suggestion and that drives my curiosity.

    As for being rude, I don't think that asking for a reply from you when any of us have put in thought or effort to try to help you solve this is rude. I can't help if you don't agree.

Similar Threads

  1. Can't compile and run Java code
    By quicksun in forum New To Java
    Replies: 7
    Last Post: 02-25-2011, 01:58 PM
  2. Can not compile code , anyone help me fix it ?
    By batista11b5 in forum New To Java
    Replies: 3
    Last Post: 10-22-2010, 02:00 PM
  3. Code does not Compile
    By ustar in forum New To Java
    Replies: 13
    Last Post: 03-06-2010, 04:54 PM
  4. New to JAVA and code cant compile
    By Gayethiri_86 in forum New To Java
    Replies: 2
    Last Post: 03-05-2010, 06:43 AM
  5. Code will not compile
    By ShotGunRockets in forum New To Java
    Replies: 17
    Last Post: 05-10-2009, 03:31 AM

Posting Permissions

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