Hello all, can someone take a look at my inventory program code for part 3 of the program mod. The program outputs, but I am still experiencing a few errors. If someone could take a look and let me know what to change I would greatly appreciate it.

This is my assignment:

Modify the Inventory Program to use a GUI. The GUI should display the information one product at a time, including the item number, the name of the product, the department in which the product belongs, 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.

// Fig 3.0:  Inventory.java
// This program calculates inventory value

import java.util.Scanner;
import java.util.Arrays;

public class Inventory
{

     // main method begins program execution
     public static void main(String args[] )
     {
          // create Scanner to obtain input from command window
          Scanner input = new Scanner( System.in );

          // display a welcome message to the InventoryProgramPart3 user
          System.out.println( "Welcome to Inventory Program Part 3!" );

          // office supplies

          Camera[] myCamera = new Camera[100]; // an array of 100 supplies


          myCamera[0] = new Camera(0,"Sony",4000, 60, 200.00 );
          myCamera[1] = new Camera(1,"Toshiba",3000, 50, 150.00 );
          myCamera[2] = new Camera(2,"Phillips",2000, 40, 100.00 );

          // display the inventories one at a time
         
          Camera.showInventory();
          Camera.showInventory();
             

          // sort cameras by name
          for ( int i = 0; i < args.length; i++ )
          System.out.println( args[i] + ", " );

          double array[] = { 100.00, 150.00, 200,00 };
          double total = 0;

          // add each element's value to total
          for ( int counter = 0; counter < array.length; counter++)
               total += array[ counter ];
          System.out.printf( "\nTotal inventory value is: $%.2f\n", total );

          System.out.println( "\nThank you for using Inventory Program Part 3!\n" );

     } // end method main

    private Inventory() {
    }

} // end class Inventory


class Camera
{
     private String UnitName = new String();
     private int UnitNumber;
     private int NumberofUnits;
     private double UnitPrice;

   

     // set supplies number
     public void setUnitName( String Name )
     {
          this.UnitName = Name;
     } // end method set unit name

     // return unit name
     public String getUnitName()
     {
          return UnitName;
     } // end method get unit name

     // set supplies name
     public void setUnitNumber( int Number)
     {
          this.UnitNumber = Number;
     } // end method set unit number

     // return unit number
     public String getUnitNumber()
     {
          return UnitNumber;
     } // end method get unit number

     // set number of units
     public void setNumberofUnits( int Units )
     {
          this.NumberofUnits = Units;
     } // end method set number of units

     // return number of units
     public int getNumberofUnits()
     {
          return NumberofUnits;
     } // end method get supplies units

     // set supplies price
     public void setUnitPrice( double price )
     {
          this.UnitPrice = price;
     } // end method set unit price

     // return unit price
     public double getUnitPrice()
     {
          return UnitPrice;
     } // end method get unit price

     // calculate unit price inventory value
     public double getValue()
     {
          return getNumberofUnits() * getUnitPrice();
     } // end method supplies inventory value

    // four-argument constructor
     Camera( String Name, int Number, int Units, double price )
     {
          UnitName = Name;
          UnitNumber = Number;
          NumberofUnits = Units;
          UnitPrice = Price;
     } // end four-argument constructor

    // display inventory
     public void showInventory()
     {
          System.out.println(); // outputs blank line

          System.out.println( "Product Name:  "+getUnitName() );
          System.out.println( "Product Number:  "+getUnitNumber() );
          System.out.println( "Units in Stock:  "+getNumberofUnits() );
          System.out.printf( "Unit Price:  $%.2f", getUnitPrice());

          Camera myCamera = new Camera
               (0, "Sony", 60, 200.0, "Toshiba" );

          System.out.println( "\nManufacturer:  "+Camera.getCameraManufacturer() );

          // value() method and display the value
          System.out.printf( "\nInventory value of "+getUnitName()+ " is = $%.2f\n",
               getValue() );

    } // end display inventory

} // end class Camera


 class InventoryProgram extends Inventory

{
     // holds the supplies manufacturer
     private String CameraManufacturer;

     // five-argument constructor
     InventoryProgram( String Name, int Number, int Units,
          double price, String manufacturer )
     {
          super(Name, Number, Units, Price );
          CameraManufacturer = manufacturer;
     } // end five-argument constructor

     // set camera manufacturer
     public void setCameraManufacturer( String manufacturer )
     {
          this.CameraManufacturer = manufacturer;
     } // end method set supplies manufacturer

     // return camera manufacturer
     public String getCameraManufacturer()
     {
         return CameraManufacturer;
     } // end method get supplies manufacturer

     // add 5% restocking fee
     public double getPrice()
     {
          return super.getValue() * 1.05;
     } // end method return camera manufacturer

     // calculate restocking fee
     public double getRestockingFee()
     {
          return super.getValue() * .05;
     } //end method calculate restocking fee

     //return String representation of CameraManufacturer
    @Override
     public String toString()
     {
          String formatString = "Manufacturer:  %s";
          formatString += "Restocking Fee:  $%.2f";
          formatString = String.format( formatString, CameraManufacturer,
               super.getPrice() * 0.05 );
          return( formatString + super.toString() );
     } // end toString()

     // display inventory
     public void showInventory()
     {
          super.showInventory();
          System.out.println( toString() );
          System.out.println( "\nManufacturer:  "+getCameraManufacturer() );

          // Display value plus restocking fee
          System.out.printf( "\nInventory value of "+CameraName+ " is = $%.2f\n",
               getRestockingFee() );

     } // end method display inventory

} // end class manufacturer

you might also want to describe and post the errors you get and the result you're expecting to get

line 24,25,26:
You have incoorectly made 5 parameters for the constructor, but in fact the Camera constructor requests 4 arguments:
Camera( String Name, int Number, int Units, double price ) // see line 120

...

According line 30,31: Camera.showInventory();
The showInventory() method must be a static since you use the class name Camera as the handle, but actually the showInventory() is not static.

Hello, I am trying to compile my Inventory Program part 3, I am experience one error
in my code, which is the "Price" in my InventorProgram subclass. Can someone take a look and inform me any changes that need to be made. The inventory program should store camera inventory, allow data retreival, calculate inventory value with a 5% restocking fee, and display the output. If someone could take a look I would really appreciate it. Thanks for your help.

// Fig 3.0: Inventory.java
// This program calculates inventory value

import java.util.Scanner;
import java.util.Arrays;

public class Inventory
{

     // main method begins program execution
     public static void main(String args[] )
     {
          // create Scanner to obtain input from command window
          Scanner input = new Scanner( System.in );

          // display a welcome message to the InventoryProgramPart3 user
          System.out.println( "Welcome to Inventory Program Part 3!" );

          // Camera Inventory

          Camera[] myCamera = new Camera[100]; // an array of 3 cameras


          myCamera[0] = new Camera(0,"Sony",4000, 60, 200.00 );
          myCamera[1] = new Camera(1,"Toshiba",3000, 50, 150.00 );
          myCamera[2] = new Camera(2,"Phillips",2000, 40, 100.00 );

          // display the inventories one at a time

         

          // sort cameras by name
          for ( int i = 0; i < args.length; i++ )
          System.out.println( args[i] + ", " );

          double array[] = { 100.00, 150.00, 200,00 };
          double total = 0;

          // add each element's value to total
          for ( int counter = 0; counter < array.length; counter++)
               total += array[ counter ];
          System.out.printf( "\nTotal inventory value is: $%.2f\n", total );

          System.out.println( "\nThank you for using Inventory Program Part 3!\n" );

     } // end method main

    private Inventory() {
    }

    void showInventory() {

    }

    double getValue() {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    double getPrice() {
        throw new UnsupportedOperationException("Not yet implemented");
    }


} // end class Inventory


class Camera
{

    private static String getCameraManufacturer() {
        throw new UnsupportedOperationException("Not yet implemented");
    }
     private String UnitName = new String();
     private int UnitNumber;
     private int NumberofUnits;
     private double UnitPrice;

    Camera(int i, String string, int i0, int i1, double d) {
       
    }

     // set unit name
     public void setUnitName( String Name )
     {
          this.UnitName = Name;
     } // end method set unit name

     // return unit name
     public String getUnitName()
     {
          return UnitName;
     } // end method get unit name

     // set supplies name
     public void setUnitNumber( int Number)
     {
          this.UnitNumber = Number;
     } // end method set unit number

     // return unit number
   

     // set number of units
     public void setNumberofUnits( int Units )
     {
          this.NumberofUnits = Units;
     } // end method set number of units

     // return number of units
     public int getNumberofUnits()
     {
          return NumberofUnits;
     } // end method get number of units

     // set unit price
     public void setUnitPrice( double price )
     {
          this.UnitPrice = price;
     } // end method set unit price

     // return unit price
     public double getUnitPrice()
     {
          return UnitPrice;
     } // end method get unit price

     // calculate unit price inventory value
     public double getValue()
     {
          return getNumberofUnits() * getUnitPrice();
     } // end method camera inventory value

    public Camera(int UnitNumber, int NumberofUnits, double UnitPrice) {
        this.UnitNumber = UnitNumber;
        this.NumberofUnits = NumberofUnits;
        this.UnitPrice = UnitPrice;
    }

    // four-argument constructor

     Camera( String Name, int Number, int Units, double Price )
     {
          UnitName = Name;
          UnitNumber = Number;
          NumberofUnits = Units;
          UnitPrice = Price;
     } // end four-argument constructor

    // display inventory
     public void showInventory()
     {
          System.out.println(); // outputs blank line

          System.out.println( "Product Name:  "+getUnitName() );
          System.out.println( "Product Number:  "+getUnitNumber() );
          System.out.println( "Units in Stock:  "+getNumberofUnits() );
          System.out.printf( "Unit Price:  $%.2f", getUnitPrice());

         
               

          System.out.println( "\nManufacturer:  "+Camera.getCameraManufacturer() );

          // value() method and display the value
          System.out.printf( "\nInventory value of "+getUnitName()+ " is = $%.2f\n",
               getValue() );

    } // end display inventory

    private String getUnitNumber() {
        throw new UnsupportedOperationException("Not yet implemented");
    }

} // end class Camera





 class InventoryProgram extends Inventory

{
     // holds the Camera manufacturer
     private String CameraManufacturer;

     // five-argument constructor
     InventoryProgram( String Name, int Number, int Units,
          double price, String manufacturer )
     {
          super(Name, Number, Units, Price, manufacturer);
          CameraManufacturer = manufacturer;
     } // end five-argument constructor

     // set camera manufacturer
     public void setCameraManufacturer( String manufacturer )
     {
          this.CameraManufacturer = manufacturer;
     } // end method set camera manufacturer

     // return camera manufacturer
     public String getCameraManufacturer()
     {
         return CameraManufacturer;
     } // end method get camera manufacturer

     // add 5% restocking fee

    @Override
     public double getPrice()
     {
          return super.getValue() * 1.05;
     } // end method return camera manufacturer

     // calculate restocking fee
     public double getRestockingFee()
     {
          return super.getValue() * .05;
     } //end method calculate restocking fee

     //return String representation of CameraManufacturer
    @Override
     public String toString()
     {
          String formatString = "Manufacturer:  %s";
          formatString += "Restocking Fee:  $%.2f";
          formatString = String.format( formatString, CameraManufacturer,
               super.getPrice() * 0.05 );
          return( formatString + super.toString() );
     } // end toString()

     // display inventory

     public void showInventory(String showInventory, String CameraName)
     {
          super.showInventory();
          System.out.println( toString() );
          System.out.println( "\nManufacturer:  "+getCameraManufacturer() );

          // Display value plus restocking fee
          System.out.printf( "\nInventory value of "+CameraName+ " is = $%.2f\n",
               getRestockingFee() );

     } // end method display inventory

} // end class manufacturer
Member Avatar for coil

OK, a few things.

1. Please post the exact error.
2. There is no need to repost your entire code every single time. Only repost relevant sections. However, if you made significant changes, you should repost it

As for your GUI, I would assume you would be doing a standard window with Swing components. I'm not sure what your experience with Swing is, but I would review the API for the following:

-JFrame
-JTextField
-JLabel
-JButton (possibly)

What do you want your project to end up looking like, visually? How will the GUI read and display the information? That will get you a start.

The code in line 190 requests an Inventory construtor with 5 arguments. In fact there is no such a constructor with the same signature in the definition of class Inventory.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.