5 Replies - 519 Views - Last Post: 02 November 2011 - 07:38 AM Rate Topic: -----

#1 BadMagick   User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 31
  • Joined: 05-August 11

Two problems showing up with Inventory Program 2

Posted 02 November 2011 - 06:45 AM

What I have to do is make an array to store and bring up the DVDs. I am running into two errors I cannot figure out.
 public class Inventory2

 {




  private double ItemNumber; //to store Item number

  private String ItemName; //to store Item name

  private double UnitsInStock; //to store number of units in stock

  private double UnitPrice; //to store Unit price

  //private double InventoryValue; //to store Inventory value

  //private double TotalInventory; //to store Total Inventory value



  public Inventory()



    {

      this ("", 0.0, 0.0, 0.0);

    }



    public Inventory2 (String name, double number, double stock, double price)



     {

       ItemName = name;

       ItemNumber = number;

       UnitsInStock = stock;

       UnitPrice = price;

     }





      public void setItemName( String name )



      {




        ItemName = name;

      } //end method setItemName





      public String getItemName()



      {

        return ItemName;

      } //end method getItemName





      public void setItemNumber( int number )



      {

        ItemNumber = number;

      } //end method setItemNumber





      public double getItemNumber()



      {

        return ItemNumber;

      } //end method getItemNumber





      public void setUnitsInStock( double stock )



      {

        UnitsInStock = stock; //store the Units in stock

      } //end method setUnitsInStock





      public double getUnitsInStock()



      {

        return UnitsInStock;

      } //end getUnitsInStock





      public void setUnitPrice( double price )



      {

        UnitPrice = price;

      } //end method setUnitPrice





      public double getUnitPrice()



      {

        return UnitPrice;

      } //end getUnitPrice







      //public void setInventoryValue(double value)



      //{

      //  InventoryValue = value;

      //} //end method setInventoryValue





      //public double getInventoryValue()



      //{

      //  return InventoryValue;

      //} //end method to getInventoryValue



      public double getInventoryValue()



      {

        return UnitPrice*UnitsInStock;

      } //end method to getInventoryValue





      //public void setTotalInventory(double value)



      //{

      //TotalInventory = total;

      //} //end method setTotalInventory





      //public double getTotalInventory()





      //{



      //} //end method to getTotalInventory





 } //end class Inventory





import java.util.Arrays;


 public class Products



 {

     public static void main( String args[] )



     {





         Inventory myInventory = new Inventory();






             System.out.println();




         Inventory[] DVDs = new Inventory[5];



         DVDs[0] = new Inventory("I Am Legend", 54674, 15, 10.00);

         DVDs[1] = new Inventory("The 40 Year Old Virgin", 65415, 17, 25.00);

         DVDs[2] = new Inventory("Easy A", 97845, 35, 20.00);

         DVDs[3] = new Inventory("Fantastic Four", 5843, 10, 9.00);

         DVDs[4] = new Inventory("Dazed And Confused", 10547, 5, 15.00);





         for (int count = 0; count < DVDs.length; count++ ){

          DVDs[count] = count+1;



             System.out.printf("Product Name:  %s\n", DVDs[count].getItemName());

             System.out.printf("Item Number:  %4.2f\n", DVDs[count].getItemNumber());

             System.out.printf("Units In Stock:  %.2f\n", DVDs[count].getUnitsInStock());

             System.out.printf("Unit Price: $%4.2f\n", DVDs[count].getUnitPrice());

             System.out.printf("Inventory Value:  $%4.2f\n", DVDs[count].getInventoryValue());

             System.out.println(); //blank line to seperate products

          }

     }//end main



 }//end class Products





My errors are:
C:\Users\Colby and Erin\Desktop\Inventory PRogram\Inventory2.java:22: invalid method declaration; return type required
  public Inventory()
         ^
C:\Users\Colby and Erin\Desktop\Inventory PRogram\Inventory2.java:247: class, interface, or enum expected
import java.util.Arrays;
^
2 errors



I am not sure an enum is at all and the first problem I cannot figure out. Thanks for the help.

This post has been edited by BadMagick: 02 November 2011 - 06:46 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Two problems showing up with Inventory Program 2

#2 macosxnerd101   User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12316
  • View blog
  • Posts: 45,416
  • Joined: 27-December 08

Re: Two problems showing up with Inventory Program 2

Posted 02 November 2011 - 06:50 AM

For the first error, if that is supposed to be the constructor, it should match the name of the class- Inventory2.

For your second problem, each public class must be in its own .java file, named the same as its class.
Was This Post Helpful? 1
  • +
  • -

#3 BadMagick   User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 31
  • Joined: 05-August 11

Re: Two problems showing up with Inventory Program 2

Posted 02 November 2011 - 06:51 AM

Alright I am understanding a little more Thank You
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101   User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12316
  • View blog
  • Posts: 45,416
  • Joined: 27-December 08

Re: Two problems showing up with Inventory Program 2

Posted 02 November 2011 - 06:52 AM

Glad I could help! :)
Was This Post Helpful? 0
  • +
  • -

#5 BadMagick   User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 31
  • Joined: 05-August 11

Re: Two problems showing up with Inventory Program 2

Posted 02 November 2011 - 07:05 AM

Sorry to bother you again, but I thought I could do it. I am having trouble putting the Products class in a new file and making it work in tandem with the other file. Any help? What I did was make a new Products.java and saved it in the same folder, but it does not come up. Sorry
Was This Post Helpful? 0
  • +
  • -

#6 Fuzzyness   User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: Two problems showing up with Inventory Program 2

Posted 02 November 2011 - 07:38 AM

You need to make sure that they are in the same location, and then all that you have to do is create an object of the class in a different class. You see it many time with Driver classes. Here is an example of using Objects in different classes together:

Spoiler

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1