Welcome to Dream.In.Code
Become a Java Expert!

Join 150,408 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 951 people online right now. Registration is fast and FREE... Join Now!




Where am I screwing up?

 
Reply to this topicStart new topic

Where am I screwing up?, God I want to drop this class...

Trotter
14 Mar, 2008 - 09:16 PM
Post #1

New D.I.C Head
*

Joined: 11 Mar, 2008
Posts: 43


My Contributions
I have spent HOURS trying to get this blasted thing to work. I know that the problem is probably something super-simple... but I don't have anyone to teach me. My class is online, and is little or no help. I am here because I have nowhere else to turn.

No, I don't want pity. I want to learn how to do this so I can salvage my GPA and not have to repay for the class.

Anyway, the first part compiled:
CODE
// Inventory Program

public class Inventory // begin Inventory class
{

   private int itemNumber; // number of the item
   private String itemName; // name of the item
   private int itemQuantity; // quanity of item in stock
   private double itemPrice; // price of item

   public Inventory( int itemNumber, String itemName, int itemQuantity, double itemPrice) // constructor
   {
      this.itemNumber = itemNumber;
      this.itemName = itemName;
      this.itemQuantity = itemQuantity;
      this.itemPrice = itemPrice;
   }

   public void setItemNumber( int itemNumber )
   {
      this.itemNumber = itemNumber;
   }

   public int getItemNumber()
   {
      return this.itemNumber;
   }

   public void setItemName( String itemName )
   {
      this.itemName = itemName;
   }

   public String getItemName()
   {
      return this.itemName;
   }

   public void setItemQuantity( int itemQuantity )
   {
      this.itemQuantity = itemQuantity;
   }

   public int getItemQuantity()
   {
      return this.itemQuantity;
   }

   public void setItemPrice( double itemPrice )
   {
      itemPrice = itemPrice;
   }

   public double getItemPrice()
   {
      return this.itemPrice;
   }

   public double getInvValue()
   {
      return itemQuantity * itemPrice;
   }

} // end Inventory class


The other... well, it didn't:
CODE


// begin Inventory display application

public class InventoryDisplay
{

   // begin main method
   public static void main( String args[] )
   {

      // display item number
      System.out.printf( "Item number: \n%d\n",
         getItemNumber() );

      // display item name
      System.out.printf( "Item name: \n%s\n",
         getItemName() );

      // display item quantity in stock
      System.out.printf( "Item quantity: \n%d\n",
         getItemQuantity() );

      // display  item price
      System.out.printf( "Item price: $ %.2f\n",
         getItemPrice );

      // display inventory value
      System.out.printf( "Inventory value: $ %.2f\n",
         getInvValue );

      } // end main

} // end InventoryDisplay


I get "cannot find symbol" on each get statement. Yes, both are saved in the same directory, and I compiled the first and then the second. I am at a total loss for this.

I turned in the .java and .class files for Inventory, and the .java file for InventoryDisplay. Better something than nothing. I know it is screwed, but someone explain to me how and why, please.
User is offlineProfile CardPM
+Quote Post

clatcho
RE: Where Am I Screwing Up?
15 Mar, 2008 - 05:36 AM
Post #2

New D.I.C Head
*

Joined: 14 Feb, 2007
Posts: 32


My Contributions
It is something really simple that you are missing . . .

Your Error message 'cannot find symbol' that is being displayed in your InventoryDisplay class on each line

CODE


getItemNumber());



What is getItemNumber()) to the InventoryDisplay class ??? There are no methods within this class called getItemNumber(), that method is in the Inventory class.

mad.gif

So without actually writing the code for you, in English, you first need to create an instance of Inventory within the InventoryDisplay class then use that instance with the getWHATEVER method that you created
User is offlineProfile CardPM
+Quote Post

Trotter
RE: Where Am I Screwing Up?
15 Mar, 2008 - 05:59 AM
Post #3

New D.I.C Head
*

Joined: 11 Mar, 2008
Posts: 43


My Contributions
I don't want anyone to write my code for me. I didn't come here for that, so no need to worry about it. wink2.gif

I hear what you are saying, but I don't get it (no pun intended). I tried setting up a line just above the "// display item number" that said "Inventory myInventory = new Inventory();", but it kept giving me errors on it, as well. Namely, I get "cannot find symbol" under the "new" statement. I figured it was because I had split the two parts up, but putting them together doesn't work either.
User is offlineProfile CardPM
+Quote Post

letthecolorsrumble
RE: Where Am I Screwing Up?
15 Mar, 2008 - 06:37 AM
Post #4

Student of The Sun
Group Icon

Joined: 7 Nov, 2007
Posts: 550



Thanked: 1 times
My Contributions
"Inventory myInventory = new Inventory();" this statement, according to your Inventory class code, will give you an error. The constructor you are using is not defined in the class. The defined constructor is :

public Inventory( int itemNumber, String itemName, int itemQuantity, double itemPrice) // constructor

So, in your InventoryDisplay class, in the main method, you will need to
instantiate an object of the inventory class by a statement like:

Inventory inv = new Inventory(1,"Pencil",2,3.0);

when you want to call a non-static method of a class , you need to call it by using the object :

here: inv.getItemNumber();

Hope that clears some of your blockades.
User is offlineProfile CardPM
+Quote Post

Trotter
RE: Where Am I Screwing Up?
15 Mar, 2008 - 11:00 AM
Post #5

New D.I.C Head
*

Joined: 11 Mar, 2008
Posts: 43


My Contributions
Yes and no. I can see a little of the how, but the why still eludes me.

The whole thing with classes and such makes no sense to me whatsoever. I am used to a program being a friggin' program, and that's it. A program to me is self-supportive, having all that it needs to run. Using classes and whatnot messes with my mind.

I wish I had some decent resources that I could go through to explain it on a basic level, but all the tutorials I have found take flying leaps into the deep end. I need to learn to tread water before I go diving, ya know?
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 07:35PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month