By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,083 Members | 1,608 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,083 IT Pros & Developers. It's quick & easy.

Java "Inventory program" help

P: 6
I am new to Java and am having problems getting my program to compile correctly.

My assignment is as follows;
Choose a product that lends itself to an inventory (for example, products at your workplace, office supplies, music CDs, DVD movies, or software).
Create a product class that holds the item number, the name of the product, the number of units in stock, and the price of each unit.
Create a Java application that displays the product number, the name of the product, the number of units in stock, the price of each unit, and the value of the inventory (the number of units in stock multiplied by the price of each unit). Pay attention to the good programming practices in the text to ensure your source code is readable and well documented.

Here is what I have so far
Expand|Select|Wrap|Line Numbers
  1.  
  2. /** 
  3.   *@author Greg Hamilton
  4.   *Program was changed 31 Aug 07
  5.   *The purpose of this program is to create a product class that holds an item number, name of the DVD movie, number of units in stock
  6.   *and the price of each unit
  7. */
  8.  
  9.    import java.util.Scanner;
  10.    import java.io.*;
  11.    import java.util.*;
  12.  
  13.  
  14.    public class Dvd extends Object
  15.  
  16.     {
  17.  
  18.      private String dvdTittle;
  19.      private double dvdStock;
  20.      private double dvdPrice;
  21.      private double dvdItem;
  22.  
  23.      public Dvd( String tittle, double stock, double price, double item )
  24.  
  25.      {
  26.        //implicit call to Object constructor occurs here
  27.        dvdTittle = tittle;
  28.        dvdStock = stock;
  29.        dvdPrice = price;
  30.        dvdItem = item;
  31.       } //end four-argument constructor
  32.  
  33.  
  34.  
  35.       //set DVD name
  36.       public void setdvdTittle( String tittle )
  37.       {
  38.           dvdTittle = tittle;
  39.       } //end method setDvdTittle
  40.  
  41.       //return dvd Tittle
  42.       public String getDvdTittle()
  43.       {
  44.         return dvdTittle;
  45.       } //end method getDvdTittle
  46.  
  47.       //set Dvd stock
  48.       public void setDvdStock( double stock)
  49.       {
  50.        dvdStock = ( stock < 0.0 ) ? 0.0 : stock;
  51.       } //end method setDvdStock
  52.  
  53.       //return dvd stock
  54.       public double getDvdStock()
  55.       {
  56.         return dvdStock;
  57.       } //end method getDvdStock
  58.  
  59.      public void setDvdPrice( double price )
  60.      {
  61.         dvdPrice = ( price <0.0 ) ? 0.0 : price;
  62.      } //end method SetDvdPrice
  63.  
  64.      //return dvd price
  65.      public double getDvdPrice()
  66.      {
  67.        return dvdPrice;
  68.      } //end method get Dvd Price
  69.  
  70.      public void setDvdItem( double item )
  71.      {
  72.        dvdItem = ( item <0.0) ? 0.0 : item;
  73.      } //end method set dvd Item
  74.  
  75.      //return dvd item
  76.  
  77.      public double getDvdItem()
  78.      {
  79.        return dvdItem;
  80.      } //end method getDvdItem
  81.  
  82.  
  83.     // calculate inventory value
  84.     public double value()
  85.     {
  86.        return dvdPrice * dvdStock;
  87.  
  88.     } //end method value
  89.  
  90.     //instantiate Collection object
  91.         Dvd aDvd= new Dvd ("Dejavu", "10", "12.50", "101");  
  92.  
  93.  
  94.  
  95.      public static void main( String args[] )
  96.  
  97.        {
  98.  
  99.  
  100.  
  101.  
  102.       System.out.printf("%s %s\n", "Product Tittle is",
  103.          Dvd.gettittle() );
  104.       System.out.printf("%s %s\n", "The number of units in stock is", 
  105.          Dvd.getstock() );
  106.       System.out.printf("%s %s\n", "The price of each DVD is",
  107.          Dvd.getprice() );
  108.       System.out.printf("%s %s\n", "The item number is",
  109.          dvd.getitem() );
  110.       System.out.printf("%s %s\n", "The value of the inventory is",
  111.          Dvd.getvalue() );
  112.  
  113.       } //end main
  114.  
  115.    } //end class Dvd
  116.  
  117.  


My complier does not like my Dvd aDVD = new Dvd(); statement. I filled in values to populate the data points required for the program.

The error codes that I get are as follows;

6 errors found:
File: C:\Documents and Settings\Greg\Desktop\Dvd.java [line: 90]
Error: C:\Documents and Settings\Greg\Desktop\Dvd.java:90: cannot find symbol
symbol : constructor Dvd(java.lang.String,java.lang.String,java.lang.St ring,java.lang.String)
location: class Dvd
File: C:\Documents and Settings\Greg\Desktop\Dvd.java [line: 102]
Error: C:\Documents and Settings\Greg\Desktop\Dvd.java:102: cannot find symbol
symbol : method gettittle()
location: class Dvd
File: C:\Documents and Settings\Greg\Desktop\Dvd.java [line: 104]
Error: C:\Documents and Settings\Greg\Desktop\Dvd.java:104: cannot find symbol
symbol : method getstock()
location: class Dvd
File: C:\Documents and Settings\Greg\Desktop\Dvd.java [line: 106]
Error: C:\Documents and Settings\Greg\Desktop\Dvd.java:106: cannot find symbol
symbol : method getprice()
location: class Dvd
File: C:\Documents and Settings\Greg\Desktop\Dvd.java [line: 108]
Error: C:\Documents and Settings\Greg\Desktop\Dvd.java:108: cannot find symbol
symbol : variable dvd
location: class Dvd
File: C:\Documents and Settings\Greg\Desktop\Dvd.java [line: 110]
Error: C:\Documents and Settings\Greg\Desktop\Dvd.java:110: cannot find symbol
symbol : method getvalue()
location: class Dvd


Thanks for any help that you can give me.
Aug 31 '07 #1
Share this Question
Share on Google+
11 Replies


P: 36
include the following piece of code in your code.
public Dvd()
{


}

The reason for this is compiler does not supply default constructor when there are parameterised constructors.
Also
you need not extend your class with Object class.
It happens by default.



with regards,
shailesh
Sep 1 '07 #2

P: 6
Thanks for the pointers. I removed the extension for the object class.

I don't mean to sound dense here, but when I added the public Dvd() and the braces in my code (at the end, before the print statments), I got a illegal start of expression error.

Is there a specific place that I should have added the public DVD() in?

Thanks again.

include the following piece of code in your code.
public Dvd()
{


}

The reason for this is compiler does not supply default constructor when there are parameterised constructors.
Also
you need not extend your class with Object class.
It happens by default.



with regards,
shailesh
Sep 1 '07 #3

Expert 10K+
P: 11,448
Thanks for the pointers. I removed the extension for the object class.

I don't mean to sound dense here, but when I added the public Dvd() and the braces in my code (at the end, before the print statments), I got a illegal start of expression error.

Is there a specific place that I should have added the public DVD() in?

Thanks again.
You don't need to add a no-args constructor Dvd(); the error at line 90 is raised
because you don't have a Dvd constructor that takes four Strings. Read that
error message carefully and you'll see that this is exactly what the compiler
is trying to tell you.

You do have a Dvd constructor that takes one string and three doubles. That
should ring a bell.

The new errors you got is because of mismatched curly brackets.

kind regards,

Jos
Sep 1 '07 #4

P: 36
in hurry i gave you some irrelevant answer.

Correct solution for your problem is:

you have declared public Dvd(String,Float ,.........)
but you have supplied all the strings as parameters in your code.


remove double quotes for all parameters except the first one.
Sep 1 '07 #5

P: 36
Dvd aDvd= new Dvd ("Dejavu", 10, 12.50, 101);


apart from these ,check spelling mistakes.
Sep 1 '07 #6

P: 36
few more corrections:


call the methods like this
aDvd.getDvDTitle();
aDvd.getDVDStock();
Sep 1 '07 #7

P: 36
//dear hamilton: you wont get any error now
//completely corrected & excecuted code

public class Dvd extends Object

{

private String dvdTittle;
private double dvdStock;
private double dvdPrice;
private double dvdItem;
public Dvd( String tittle, double stock, double price, double item )

{
//implicit call to Object constructor occurs here
dvdTittle = tittle;
dvdStock = stock;
dvdPrice = price;
dvdItem = item;
} //end four-argument constructor



//set DVD name
public void setdvdTittle( String tittle )
{
dvdTittle = tittle;
} //end method setDvdTittle

//return dvd Tittle
public String getDvdTittle()
{
return dvdTittle;
} //end method getDvdTittle

//set Dvd stock
public void setDvdStock( double stock)
{
dvdStock = ( stock < 0.0 ) ? 0.0 : stock;
} //end method setDvdStock

//return dvd stock
public double getDvdStock()
{
return dvdStock;
} //end method getDvdStock

public void setDvdPrice( double price )
{
dvdPrice = ( price <0.0 ) ? 0.0 : price;
} //end method SetDvdPrice

//return dvd price
public double getDvdPrice()
{
return dvdPrice;
} //end method get Dvd Price

public void setDvdItem( double item )
{
dvdItem = ( item <0.0) ? 0.0 : item;
} //end method set dvd Item

//return dvd item

public double getDvdItem()
{
return dvdItem;
} //end method getDvdItem


// calculate inventory value
public double value()
{
return dvdPrice * dvdStock;

} //end method value

//instantiate Collection object




public static void main( String args[] )

{

Dvd aDvd= new Dvd ("Dejavu", 10, 12.50, 101);


System.out.println("Product Tittle is"+ aDvd.getDvdTittle() );
System.out.println("The number of units in stock is"+
aDvd.getDvdStock() );
System.out.println("The price of each DVD is"+ aDvd.getDvdPrice() );
System.out.println( "The item number is"+ aDvd.getDvdItem());
System.out.println( "The value of the inventory is"+ aDvd.value() );

} //end main

} //end class Dvd
Sep 1 '07 #8

P: 6
Thank you so much for the help! Everything works now.
Sep 1 '07 #9

Expert 10K+
P: 11,448
//dear hamilton: you wont get any error now
//completely corrected & excecuted code
You know, this forum's policy is *not* to spoonfeed code; don't do this again.
If you had read the forum guidelines (see the 'Help' link in the top-right corner
of this page, you could have known this).

It's too late now, the OP has been spoonfed; don't do this again. I won't make
this an official warning, but please cooperate with this forum's guidelines.

kind regards,

Jos
Sep 1 '07 #10

P: 6
Sorry for creating a problem here with my questions.

I just wanted to let you know that the help I recived was invaluable to me. I had emailed my instructor for help (project was due Friday) and still haven't heard anything back.

I did not do well on the last project and this one was a real life saver for me.

I did not take it as being spoon feed with the posts (and in my case it helped me to figure out how close I was to what the code should have been). Seeing the full up code allowed me to regain my confidence and showed me where my thinking was flawed (quotes in wrong spots, mismatched {}).




You know, this forum's policy is *not* to spoonfeed code; don't do this again.
If you had read the forum guidelines (see the 'Help' link in the top-right corner
of this page, you could have known this).

It's too late now, the OP has been spoonfed; don't do this again. I won't make
this an official warning, but please cooperate with this forum's guidelines.

kind regards,

Jos
Sep 2 '07 #11

Expert 10K+
P: 11,448
Sorry for creating a problem here with my questions.
You're not the cause of the 'problem'; that would be anthropic reasoning (google
for that). The other poster just shouldn't have posted complete code. Maybe in
your particular case it has helped you (a bit?) Most of the time, people simply
copy and paste the code and turn it in as if it were their own.

That is cheating; suppose such a cheater graduates and becomes your coworker.
You most certainly don't want that because you'll end up with almost a double
job: your own task plus correcting the mess created by that coworker.

That is one of the main reasons we don't supply anyone with complete code.

kind regards,

Jos
Sep 2 '07 #12

Post your reply

Sign in to post your reply or Sign up for a free account.