473,402 Members | 2,046 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Java "Inventory program" help

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
11 7666
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
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
JosAH
11,448 Expert 8TB
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
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
Dvd aDvd= new Dvd ("Dejavu", 10, 12.50, 101);


apart from these ,check spelling mistakes.
Sep 1 '07 #6
few more corrections:


call the methods like this
aDvd.getDvDTitle();
aDvd.getDVDStock();
Sep 1 '07 #7
//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
Thank you so much for the help! Everything works now.
Sep 1 '07 #9
JosAH
11,448 Expert 8TB
//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
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
JosAH
11,448 Expert 8TB
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

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

Similar topics

5
by: Tyler | last post by:
Hi ppl, I know it's forbidden to mention Java in this newsgroup but I've been presented with a problem which requires that my C++ program communicate with another java program. What is the...
6
by: David | last post by:
Hi, I am writing a C# program and want to run a java application and pass it a filename as a parameter. I want to be able to write a method in C# that will run this Java app for me. Eg. I want...
3
by: yoyojava | last post by:
here go to this link: http://staff.beaumont.k12.tx.us/jchauvi/CS2/CS2.html ..... then click on PROJECT:Bruin Grocery ... and i am done with everything except for step 5 and 6 the search methods.. i...
3
by: Begreen | last post by:
Hi All, I wrote a java program which outputs a xml file! But I would prefer this program to insert the DTD code on the fly, in the xml file when created! I want the xml file to look like...
1
by: feathers75 | last post by:
-------------------------------------------------------------------------------- First, Hello eveyone and I am new to Java. I am trying to create a Java program that will calculate a person...
16
by: Knute Johnson | last post by:
I'm trying to write a C wrapper to run a Java program. I need to distribute a CD with the Java runtime, my application and a C startup program. I've put the C wrapper program, my java app and the...
0
by: ccarter45 | last post by:
I need to write a program that goes through a seating chart row by row and find n consecutive seats in a row. If the seating charts has seats available, it must print out the message saying in what...
6
by: moongeegee | last post by:
I have compile my java program as myjava.class. And I can run as "java myjava" without any program. As now, I need to execute myjava.class in javascript. Please shed a light how to execut "java...
5
madzman23
by: madzman23 | last post by:
Hi guyz, I kinda new here and I dont know if there is post that similar to my question, because I really needed immediately I am posting my question. Can anyone here help me how to call a Java...
13
by: falconsx23 | last post by:
Hi, I need help with my java program. I am new with java, so go easy on me if this is a dumb question. Ok the question is "You will complete two methods for this exercise. The headers (and a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.