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

    Default Have a New Error

    Java Code:
    C:\Java Test>javac CameraInventory3.java
    CameraInventory3.java:410: error: reached end of file while parsing
    }
     ^
    1 error
    
    C:\Java Test>


    Java Code:
    import java.util.Arrays;
    import java.util.Comparator;
    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 CameraInventory3{
    
    
        
       
        public static void main(String[] args)
        {
            
           
            Camera[] camera = new Camera[4];
            camera[0] = new Manufacturer(500, "PowerShot", 10, 800, "Canon");
    
    camera[1] = new Manufacturer(200, "STYLUS-5010", 20, 650, "Olympus");
    
    camera[2] = new Manufacturer(300, "Cyber-Shot", 15, 890, "Sony");
    
    camera[3] = new Manufacturer(350, "Point & Shoot", 10, 1200, "Nikon");
    
    camera[4] = new Manufacturer(400, "EASYSHARE SPORT", 80, 1500, "Kodak");
            
            Inventory invent = new Inventory(camera);
            
            
            invent.sortProd();
            
            for (int i = 0; i < invent.getSize(); i++)
            {
               
                Cam prod = (Cam)invent.get(i);
                
               
                System.out.println("Item Number: " + prod.getItemNumber());
                System.out.println("Product Name: " + prod.getName());
                System.out.println("Number Of Units: " + prod.getUnits());
                System.out.println("Number Of Megapixels: " + prod.getMegapx());
                System.out.printf("Price Per Unit: $%,.2f\n", prod.getPrice());
                System.out.printf("The value of the inventory: $%,.2f\n\n", prod.inventoryValue());
                System.out.printf("The value of the restocking fee: $%,.2f\n\n", prod.getRestockingFee());
            }
    
            System.out.printf("The total value: $%,.2f\n", invent.totalValue());
           
    
        }
    
    
    
    class Camera
    {
        
        private int itemNumber; 
        private String name; 
        private int units; 
        private double price;
        Cam cam;
        
        
        
            public Camera(Cam cam)
        {
            this.cam = cam;
        }
        
      
        public Camera()
        {
            itemNumber = 0;
            name = "";
            units = 0;
            price = 0;        
        }
        
       
        public Camera(int itemNumber, String name, int units, double price, double megapx)
        {
            this.itemNumber = itemNumber;
            this.name = name;
            this.units = units;
            this.price = price;
        }
        
        
        public double inventoryValue()
        {
            return units * price;
        }
    
       
        public int getItemNumber()
        {
            return itemNumber;
        }
        
        public void setItemNumber(int itemNumber)
        {
            this.itemNumber = itemNumber;
        }
        
        public String getName()
        {
            return name;
        }
        
        public void setName(String name)
        {
            this.name = name;
        }
        
        public int getUnits()
        {
            return units;
        }
        
        public void setUnits(int units)
        {
            this.units = units;
        }
        
        public double getPrice()
        {
            return price;
        }
        
        public void setPrice(double price)
        {
            this.price = price;
        }    
    }
    
    class Cam extends Camera
        {
           
            private double megapx;
             
            
            public Cam()
            {
                super();
                megapx = 0;
            }
             
           
            public Cam(int itemNumber, String name, int units, double price, double megapx)
            {
                super(itemNumber, name, units, price, megapx);
                this.megapx = megapx;
            }
             
           
            public double getRestockingFee()
            {
                return getPrice() * getUnits() * 0.05;
            }
             
           
            public double inventoryValue()
            {
                return getPrice() * getUnits();
            }
             
           
            public double getMegapx()
            {
                return megapx;
            }
         
            
            public void setMegapx(double megapx)
            {
                this.megapx = megapx;
            }
         
        }
    class Inventory
    {
        private Camera[] camera;
        
    
       
        public Inventory(Camera[] camera)
        {
            this.camera = camera;
        }
        
       
        public double totalValue()
        {
            double total = 0;       
            for (int i = 0; i < camera.length; i++)
                total += camera[i].inventoryValue();
            return total;
        }
        
        
        public void sortProd()
        {
            Comparator<Camera> comp = new Comparator<Camera>() {
                public int compare(Camera o1, Camera o2) {
                    return o1.getName().compareTo(o2.getName());
                }            
            };
            
            Arrays.sort(camera, comp);
        }
        
        
        public int getSize()
        {
            return camera.length;
        }
        
       
        public Camera get(int idx)
        {
            return camera[idx];
        }
    }
    
    
     
    
    public class InventoryPart3 extends JFrame {
    private static decimalFormat currency = new DecimalFormat("$#,##0.00");
    
    
    private JTextField itemNumberTF;
    private JTextField productNameTF;
    private JTextField unitsInStockTF;
    private JTextField priceTF;
    private JTextField ManufacturerNameTF;
    private JTextField restockFeeTF;
    private JTextField valueOfInventoryTF;
    
    private JTextField totalValueOfInventoryTF;
    
    private JButton priorBT;
    private JButton nextBT;
    
    private Manufacturer[] products;
    
    private int current = 0;
    
    
    public static void main(String[] args) {
    
    new InventoryPart3();
    }
    
    
    public InventoryPart3() {
    super("Inventory Part 3");
    setSize(500, 300);
    setLocationRelativeTo(null);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    
    Camera[] camera = new Camera[3];
    camera[1] = new Manufacturer(200, "STYLUS-5010", 20, 650, "Olympus");
    camera[2] = new Manufacturer(300, "Cyber-Shot", 15, 890, "Sony");
    camera[3] = 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 < camera.length - 1) {
    current++;
    updateFields();
    }
    }
    });
    p.add(nextBT);
    
    return p;
    }
    
    protected void updateFields() {
    manufacturer = camera[current];
     
    itemNumberTF.setText(String.valueOf(getItemNumber()));
    cameraNameTF.setText(getcameraName());
    unitsInStockTF.setText(String.valueOf(getUnitsInStock()));
    priceTF.setText(currency.format(getPrice()));
    manufacturerNameTF.setText(getManufacturerName());
    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 < camera.length; i++) {
    value += camera[i].calculateInventory();
    }
    return value;
    }
    
    
    public void sortArray() {
    int n = camera.length; 
    boolean swapped;
    do {
    swapped = false;
    for (int i = 0; i < n - 1; i++) {
    String name1 = camera[i].getcameraName();
    String name2 = camera[i + 1].getcameraName();
    if (name1.compareToIgnoreCase(name2) > 0) {
    
    Manufacturer temp = camera[i];
    camera[i] = camera[i + 1];
    camera[i + 1] = temp;
    swapped = true;
    }
    }
    n = n - 1;
    } while (swapped);
    }
    Last edited by sunde887; 10-16-2011 at 08:25 PM.

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default Re: Have a New Error

    You missed a bracket somewhere, double check your code and make sure each opening bracket has a matching close bracket. Also, when posting code please use code tags. [code] YOUR CODE HERE [/code]

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,457
    Blog Entries
    7
    Rep Power
    20

    Default Re: Have a New Error

    Quote Originally Posted by MikeJ39 View Post
    [code]
    C:\Java Test>javac CameraInventory3.java
    CameraInventory3.java:410: error: reached end of file while parsing
    }
    ^
    1 error
    Your compiler was happily doing its job while all of a sudden its input was exhausted, finished, no more; so your compiler complained about it. Probably you forgot one (or more?) right curly bracket(s) at the end of your code.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. java out of memory error-heap space error
    By elsanthosh in forum NetBeans
    Replies: 4
    Last Post: 06-15-2010, 09:31 AM
  2. Replies: 1
    Last Post: 03-10-2010, 01:53 PM
  3. Replies: 1
    Last Post: 12-05-2009, 07:28 AM
  4. Replies: 1
    Last Post: 10-26-2009, 04:38 PM
  5. Replies: 3
    Last Post: 01-23-2009, 08:53 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
  •