473,765 Members | 2,008 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Java "Inventory program" help

6 New Member
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\D esktop\Dvd.java [line: 90]
Error: C:\Documents and Settings\Greg\D esktop\Dvd.java :90: cannot find symbol
symbol : constructor Dvd(java.lang.S tring,java.lang .String,java.la ng.String,java. lang.String)
location: class Dvd
File: C:\Documents and Settings\Greg\D esktop\Dvd.java [line: 102]
Error: C:\Documents and Settings\Greg\D esktop\Dvd.java :102: cannot find symbol
symbol : method gettittle()
location: class Dvd
File: C:\Documents and Settings\Greg\D esktop\Dvd.java [line: 104]
Error: C:\Documents and Settings\Greg\D esktop\Dvd.java :104: cannot find symbol
symbol : method getstock()
location: class Dvd
File: C:\Documents and Settings\Greg\D esktop\Dvd.java [line: 106]
Error: C:\Documents and Settings\Greg\D esktop\Dvd.java :106: cannot find symbol
symbol : method getprice()
location: class Dvd
File: C:\Documents and Settings\Greg\D esktop\Dvd.java [line: 108]
Error: C:\Documents and Settings\Greg\D esktop\Dvd.java :108: cannot find symbol
symbol : variable dvd
location: class Dvd
File: C:\Documents and Settings\Greg\D esktop\Dvd.java [line: 110]
Error: C:\Documents and Settings\Greg\D esktop\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 7698
shaileshkumar
36 New Member
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
hamiltongreg
6 New Member
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 Recognized Expert MVP
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
shaileshkumar
36 New Member
in hurry i gave you some irrelevant answer.

Correct solution for your problem is:

you have declared public Dvd(String,Floa t ,.........)
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
shaileshkumar
36 New Member
Dvd aDvd= new Dvd ("Dejavu", 10, 12.50, 101);


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


call the methods like this
aDvd.getDvDTitl e();
aDvd.getDVDStoc k();
Sep 1 '07 #7
shaileshkumar
36 New Member
//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.prin tln("Product Tittle is"+ aDvd.getDvdTitt le() );
System.out.prin tln("The number of units in stock is"+
aDvd.getDvdStoc k() );
System.out.prin tln("The price of each DVD is"+ aDvd.getDvdPric e() );
System.out.prin tln( "The item number is"+ aDvd.getDvdItem ());
System.out.prin tln( "The value of the inventory is"+ aDvd.value() );

} //end main

} //end class Dvd
Sep 1 '07 #8
hamiltongreg
6 New Member
Thank you so much for the help! Everything works now.
Sep 1 '07 #9
JosAH
11,448 Recognized Expert MVP
//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

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

Similar topics

5
3095
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 best,simplest and quickest way to go about this? I was thinking, I could have my C++ program write data to a file and then my Java program pick it up from there but this is a little too
6
9135
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 to run the following command: java MyApplication filename.extension Can anyone help me?
3
2056
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 have posted my code so you can helpme with my search methods :D. DONT HELP ME WITH STEP 3 & 4 because I can already do those. JUST STEP 5 & 6 which is the serch methods is where I need help. Thanks a bunch.. only a real java genius should be able to...
3
4260
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 this:
1
3298
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 BMI based on user input of weight (in pounds) and heigh (in inches) and then display what the BMI is and give the a message that tells them where they fit plus I want to then be able to tell them how much weight they need to loss (or gain if...
16
3413
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 runtime directories in the same directory. It will run under MS XP or maybe Vista. I'm using MS Visual C++ Express 2005 for a compiler and I tried using the _execl and _spawnl functions. These all give me assertion errors and file not found...
0
1777
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 row and what seats. If there are no seats available, it must return the message: "There's no group of seats to satisfy your request." It must also print out the seating chart I need help on how to find the n consecutive seats and find the row and...
6
6857
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 myjava" in my javascript. Thanks a million.
5
10771
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 Program using the PHP. The PHP code should call a Java program that will extract all the data from the database, I know we can do this in PHP, but I want a more secure one so I want to make a prototype that will call the Java Program that get all the...
13
2130
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 comment that describes each one) are below: Create a main method that asks the user for the length of the array, uses readArray to read in the array, and uses printArray to print the resulting array." public static void readArray(int a,...
0
9404
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9835
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7379
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5277
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3926
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.