Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4533952
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:13:13+00:00 2026-05-21T14:13:13+00:00

The GUI should display all of the items in the inventory and include the

  • 0

The GUI should display all of the items in the inventory and include the item number, the name of the product, the number of units in stock, the price of each unit, and the value of the inventory of that product. In addition, the GUI should display the value of the entire inventory, the additional attribute, and the restocking fee. All dollar values should be displayed as currency (i.e. $D,DDD.CC).

When I compile my code I received the following error messages, which I am not sure how to correct.

C:\Documents and Settings\AdminUser\My Documents\InventoryPart4.java:162: class, interface, or enum expected
import java.awt.BorderLayout;
^
C:\Documents and Settings\AdminUser\My Documents\InventoryPart4.java:163: class, interface, or enum expected
import java.awt.FlowLayout;
^
C:\Documents and Settings\AdminUser\My Documents\InventoryPart4.java:164: class, interface, or enum expected
import java.awt.GridLayout;
^
C:\Documents and Settings\AdminUser\My Documents\InventoryPart4.java:165: class, interface, or enum expected
import java.awt.event.ActionEvent;
^
C:\Documents and Settings\AdminUser\My Documents\InventoryPart4.java:166: class, interface, or enum expected
import java.awt.event.ActionListener;
^
C:\Documents and Settings\AdminUser\My Documents\InventoryPart4.java:167: class, interface, or enum expected
import java.text.DecimalFormat;
^
C:\Documents and Settings\AdminUser\My Documents\InventoryPart4.java:169: class, interface, or enum expected
import javax.swing.BorderFactory;
^
C:\Documents and Settings\AdminUser\My Documents\InventoryPart4.java:170: class, interface, or enum expected
import javax.swing.JButton;
^
C:\Documents and Settings\AdminUser\My Documents\InventoryPart4.java:171: class, interface, or enum expected
import javax.swing.JFrame;
^
C:\Documents and Settings\AdminUser\My Documents\InventoryPart4.java:172: class, interface, or enum expected
import javax.swing.JLabel;
^
C:\Documents and Settings\AdminUser\My Documents\InventoryPart4.java:173: class, interface, or enum expected
import javax.swing.JPanel;
^
C:\Documents and Settings\AdminUser\My Documents\InventoryPart4.java:174: class, interface, or enum expected
import javax.swing.JTextField;
^
12 errors

Tool completed with exit code 1

Here is my code:

/**
 * Represents a product.
 */
public class Television {
    private int itemNumber;
    private String productName;
    private int unitsInStock;
    private double price;

    /**
     * Default constructor
     */
    public Television() {
    }

    /**
     * Handy constructor to initialize all attributes of the product.
     */
    public Television(int itemNumber, String productName, int unitsInStock,
            double price) {
        this.itemNumber = itemNumber;
        this.productName = productName;
        this.unitsInStock = unitsInStock;
        this.price = price;
    }

    /**
     * @return The value of the inventory (the number of units in stock
     *         multiplied by the price of each unit).
     */
    public double calculateInventory() {
        return this.unitsInStock * this.price;
    }

    /**
     * @return the itemNumber
     */
    public int getItemNumber() {
        return itemNumber;
    }

    /**
     * @return the product name
     */
    public String getProductName() {
        return productName;
    }

    /**
     * @return the unitsInStock
     */
    public int getUnitsInStock() {
        return unitsInStock;
    }

    /**
     * @return the price
     */
    public double getPrice() {
        return price;
    }

    /**
     * @param itemNumber
     *            the itemNumber to set
     */
    public void setItemNumber(int itemNumber) {
        this.itemNumber = itemNumber;
    }

    /**
     * @param name
     *            the product name to set
     */
    public void setName(String productName) {
        this.productName = productName;
    }

    /**
     * @param unitsInStock
     *            the unitsInStock to set
     */
    public void setUnitsInStock(int unitsInStock) {
        this.unitsInStock = unitsInStock;
    }

    /**
     * @param price
     *            the price to set
     */
    public void setPrice(double price) {
        this.price = price;
    }
}


/**
 * This class should inherit from the Product class. Recall that the extends
 * keyword is used in java to represent inheritance
 */
public class Supplier extends Computer {
    /** Supplier Name */
    private String supplierName;

    /**
     * Constructor should have 5 parameters:
     *
     * - Item Number
     *
     * - Product Name
     *
     * - Number of Units in Stock
     *
     * - Price of each Unit
     *
     * - Supplier Name
     */
    public Supplier(int itemNumber, String productName, int unitsInStock,
            double price, String supplierName) {
        /*
         * Note you will use the super keyword to invoke the constructor in your
         * Product class.
         */
        super(itemNumber, productName, unitsInStock, price);
        this.supplierName = supplierName;
    }

    /**
     * This method returns the product of price and available units multiplied
     * by 5% ((price * product) * .05);
     */
    public double calculateRestockFee() {
        return super.calculateInventory() * .05;
    }

    /**
     * This method returns the product of price and available units plus the
     * restock fee.
     */
    public double calculateInventory() {
        return super.calculateInventory() + calculateRestockFee();
    }

    /**
     * @return the supplierName
     */
    public String getSupplierName() {
        return supplierName;
    }

    /**
     * @param supplierName
     *            the supplierName to set
     */
    public void setSupplierName(String supplierName) {
        this.supplierName = supplierName;
    }

}


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;

@SuppressWarnings("serial")
public class InventoryPart4 extends JFrame {
    private static DecimalFormat currency = new DecimalFormat("$#,##0.00");

    // Declares the TextFields used to display the value of each attribute of
    // the current product.
    private JTextField itemNumberTF;
    private JTextField productNameTF;
    private JTextField unitsInStockTF;
    private JTextField priceTF;
    private JTextField supplierNameTF;
    private JTextField restockFeeTF;
    private JTextField valueOfInventoryTF;

    // Declares a TextField to display the value of the entire inventory
    private JTextField totalValueOfInventoryTF;

    // Declare buttons to navigate through the products in the inventory
    private JButton priorBT;
    private JButton nextBT;

    // This array holds all products in the inventory.
    private Supplier[] products;

    // Indicates the index of the product displayed onto the screen.
    private int current = 0;

    /**
     * Starts the application
     *
     * @param args
     *            Not used by this application
     */
    public static void main(String[] args) {
        // Creates and displays the GUI
        new InventoryPart4();
    }

    /**
     * Creates a new instance of the GUI and displays the frame.
     */
    public InventoryPart4() {
        super("Inventory Part 4");
        setSize(500, 300);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(EXIT_ON_CLOSE);

        // Creates the array with 5 elements
        products = new Supplier[5];

        // Creates some products
        products[0] = new Supplier(0001, " Samsung UN46D6400",9,1599.99);
        products[1] = new Supplier(0002, " Vizio XVT553SV",6,1299.00);
        products[2] = new Supplier(0003, " Panasonic Viera TC-P50VT25",2,2079.99);
        products[3] = new Supplier(0004, " Sony Bravia KDL-55EX720",8, 1889.99);
        products[4] = new Supplier(0005, " LG Infinia 47LX9500",2,2099.00);

        // Sorts products by name
        sortArray();

        // Creates the visual components
        createComponents();

        // Shows the GUI
        setVisible(true);

        // Displays the first product
        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;
    }

    /**
     * Updates the fields to reflect the current product.
     */
    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;
    }

    /**
     * A method to calculate the value of the entire inventory. This method
     * should take in an array of type Television and should
     * traverse through all the elements of the array and calculate the
     * inventory.
     *
     * @return The value of the entire inventory.
     */
    public double calculateInventory() {
        double value = 0;
        for (int i = 0; i < products.length; i++) {
            value += products[i].calculateInventory();
        }
        return value;
    }

    /**
     * Sorts the products by name, using the Bubble Sort algorithm.

     */
    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) {
                    // swap
                    Supplier temp = products[i];
                    products[i] = products[i + 1];
                    products[i + 1] = temp;
                    swapped = true;
                }
            }
            n = n - 1;
        } while (swapped);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T14:13:13+00:00Added an answer on May 21, 2026 at 2:13 pm

    @Ben Torell’s answer is partially correct. Imports must be at the top of the class. I’m assuming these aren’t all in one file, though. Once I made a .java file for each (and generated a Computer class that you left out), the only remaining problem I see is that your constructor calls in the array of Suppliers are missing arguments for the last parameter, supplierName.

    Edit: Okay, per the comments below, there are actually a few more issues. Each of the get… methods is not defined in Television. So the calls to getItemNumber(), et al are also invalid. If you’re using a decent IDE (say, Eclipse) it will offer to generate these for you. Otherwise, define those methods in Television, add the missing argument to the constructor calls, and then you should be GTG.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a small Android app with a GUI that should display
I'm looking for an HTTP Proxy/GUI combination that should be installed locally on my
python 3.2.2 gtk3 3.2.2 python-gobject 3.0.2 I'm trying to display a GUI and do
I want a gui to display the values of my variables, so i can
I need my Java program to have two display modes: a GUI interface and
I have got a window that should display the following: JLablel Have you used
I am creating a GUI program using MVC which should look like this.. alt
Which gui development option gives a optimized and faster gui for Blackberry applications? BB
The GUI for managing plugins in Eclipse got a bit of an overhaul in
For GUI purposes I need by current state of state machine to enumerate possible

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.