473,499 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

need help adding to existing code..

17 New Member
here's what i have to do:

Modify the Inventory Program so the application can handle multiple items. Use an array to store the items. The output should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price of each unit, and the value of the inventory of that product. In addition, the output should display the value of the entire inventory.
• Create a method to calculate the value of the entire inventory.
• Create another method to sort the array items by the name of the product.

here's my code that i have so far...

public class Inventory1 {

public static void main(String[] args) {

DVD dvd;

dvd = new DVD(1, "Frosty The Snowman", 5, 14.95);
System.out.println(dvd);

dvd = new DVD(2, "Charlie Brown Christmas", 7, 12.99);
System.out.println(dvd);

dvd = new DVD(3, "Rudolph The Red-Nosed Reindeer", 6, 19.99);
System.out.println(dvd);

dvd = new DVD(4, "The Grinch Who Stole Christmas",3, 10.99);
System.out.println(dvd);

} //end main
} // end class Inventory1

class DVD {
private int dvdItem;
private String dvdTitle;
private int dvdStock;
private double dvdPrice;

public DVD(int item, String title, int stock, double price) {
dvdItem = item;
dvdTitle = title;
dvdStock = stock;
dvdPrice = price;
} //end four-argument constructor

// set DVD Item
public void setDvdItem(int item) {
dvdItem = item;
} //end method set Dvd Item

//return DVD Item
public int getDvdItem() {
return dvdItem;
} //end method get Dvd Item

//set DVD Title
public void setDvdTitle(String title) {
dvdTitle = title;
} //end method set Dvd Title

//return Dvd Title
public String getDvdTitle() {
return dvdTitle;
} //end method get Dvd Title

public void setDvdStock(int stock) {
dvdStock = stock;
} //end method set Dvd Stock

//return dvd Stock
public int getDvdStock() {
return dvdStock;
} //end method get Dvd Stock

public void setDvdPrice(double price) {
dvdPrice = price;
} //end method setdvdPrice

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

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

public String toString() {

return String.format("item=%3d title=%-20s units=%d price=%.2f value=%.2f",
dvdItem, dvdTitle, dvdStock, dvdPrice, value());
}

} //end class DVD


any help would be appreciated....
Dec 4 '07 #1
9 1942
r035198x
13,262 MVP
So, have you gone through a tutorial on arrays yet?
Dec 4 '07 #2
Kiamari
17 New Member
So, have you gone through a tutorial on arrays yet?
i took a look at a few sites...but its still not clear to me.......do you know any sites?
Dec 4 '07 #3
r035198x
13,262 MVP
i took a look at a few sites...but its still not clear to me.......do you know any sites?
How about the horse's mouth?
Dec 4 '07 #4
Kiamari
17 New Member
How about the horse's mouth?
i saw this site already...but still dont know where to begin.....
Dec 4 '07 #5
Kiamari
17 New Member
ok, i'm trying to work on this.....and here is what i got for my code

Expand|Select|Wrap|Line Numbers
  1. import java.util.*;
  2. class Inventory2 implements Comparable
  3.  
  4. {
  5.     private String dvdTitle;
  6.     private int dvdItem;
  7.     private int dvdStock;
  8.     private double dvdPrice;
  9.  
  10. }//end main method
  11.  
  12. class Dvd { // Constructor for the Dvd class
  13.    {
  14.       dvdTitle = "";
  15.       dvdItem  = 0.00;
  16.       dvdStock = 0.00;
  17.       dvdPrice = 0.00;
  18.    }
  19.  
  20.  
  21. public Dvd(String title, int item, int stock, double price) // Constructor for the Supplies class
  22.       {
  23.       this.title = title;
  24.       this.item = item;
  25.       this.stock = stock;
  26.       this.price = price;
  27.          }
  28.  
  29.    // set DVD Item
  30.     public void setDvdItem(int item) {
  31.         dvdItem = item;
  32.     } //end method  set Dvd Item
  33.  
  34.     //return DVD Item
  35.     public int getDvdItem() {
  36.         return dvdItem;
  37.     } //end method get Dvd Item
  38.  
  39.     //set DVD Title
  40.     public void setDvdTitle(String title) {
  41.         dvdTitle = title;
  42.     } //end method set Dvd Title
  43.  
  44.     //return Dvd Title
  45.     public String getDvdTitle() {
  46.         return dvdTitle;
  47.     } //end method get Dvd Title
  48.  
  49.     public void setDvdStock(int stock) {
  50.         dvdStock = stock;
  51.     } //end method set Dvd Stock
  52.  
  53.     //return dvd Stock
  54.     public int getDvdStock() {
  55.         return dvdStock;
  56.     } //end method get Dvd Stock
  57.  
  58.     public void setDvdPrice(double price) {
  59.         dvdPrice = price;
  60.     } //end method setdvdPrice
  61.  
  62.     //return DVD Price
  63.     public double getDvdPrice() {
  64.         return dvdPrice;
  65.     } //end  method get Dvd Price
  66.  
  67.     //calculate inventory value
  68.     public double value() {
  69.         return dvdPrice * dvdStock;
  70.     } //end method value
  71.  
  72.     public String toString() {
  73.  
  74.         return String.format("item=%3d   title=%-20s   units=%d   price=%.2f   value=%.2f",
  75.                              dvdItem, dvdTitle, dvdStock, dvdPrice, value());
  76.     }//end class DVD 
  77.  
  78.  
  79. public class Inventory2 {
  80.  
  81.     public static void main(String[] args) {
  82.  
  83.         System.out.println ("Inventory of DVD Movies:\n");
  84.  
  85.    Dvd [] supplies = new Dvds [3];
  86.  
  87.    Dvd d1 = new Dvd (1, "Frosty The Snowman", 5, 14.95);
  88.    Dvd d2 = new Dvd (2, "Charlie Brown Christmas", 7, 12.99);
  89.    Dvd d3 = new Dvd (3, "Rudolph The Red-Nosed Reindeer", 6, 19.99);
  90.    Dvd d4 = new Dvd (4, "The Grinch Who Stole Christmas", 3, 10.99);
  91.  
  92.    supplies[0] = d1;
  93.    supplies[1] = d2;
  94.    supplies[2] = d3;
  95.    supplies[3] = d4;
  96.  
  97.  
  98.    double total = 0.0;
  99.  
  100.    for(int i= 0; i < 3;i++)
  101.    {
  102.    total = total + supplies[i].calculateInvValue();
  103.    }
  104.  
  105.  
  106.  
  107.       for(Dvd d: supplies)
  108.       {
  109.       System.out.println(d);
  110.       System.out.println();
  111.     }
  112.  
  113. for(Dvd d: supplies)
  114.     {
  115.     System.out.println(d);
  116.     System.out.println();
  117.     }
  118.  
  119.  
  120.    System.out.println("Total Value is: $"+total);
  121.  
  122.  
  123. }}//end class Inventory2
here is the error i get..

reached end of file while parsing
}}//end class Inventory2
^
1 error

Process completed.



how do i fix that?
Dec 5 '07 #6
JosAH
11,448 Recognized Expert MVP
The compiler was happily parsing away (no syntax errors yet) and all of a sudden
there was no more input available. That indicates that you've omitted the last
right curly brackets and you should fix that. Also read the compiler diagnostic
message.

kind regards,

Jos
Dec 5 '07 #7
Kiamari
17 New Member
The compiler was happily parsing away (no syntax errors yet) and all of a sudden
there was no more input available. That indicates that you've omitted the last
right curly brackets and you should fix that. Also read the compiler diagnostic
message.

kind regards,

Jos
OMG!!

so, i added one more curly bracket to the very end of the code like this:

Expand|Select|Wrap|Line Numbers
  1. }}}//end class Inventory2
AND NOW I HAVE 32 ERRORS!!


Inventory2 is not abstract and does not override abstract method compareTo(java.lang.Object) in java.lang.Comparable
class Inventory2 implements Comparable

lines 23 - 94 have this beginning error... cannot find symbol
symbol : variable dvdTitle
location: class Dvd
dvdTitle = "";

lines 96 - 99 have this beginning error......operator + cannot be applied to double,Dvd.calculateInvValue
total = total + supplies[i].calculateInvValue();

another error....incompatible types
found : <nulltype>
required: double
total = total + supplies[i].calculateInvValue();
^
and another error...inner classes cannot have static declarations
public static void main(String[] args) {
^
^


do i have things in the wrong place?
Dec 5 '07 #8
r035198x
13,262 MVP
Those errors were there all along.
You just have to fix them. The compiler didn't report them earilier because it was failing to complete the compilaion process itself.
Dec 5 '07 #9
JosAH
11,448 Recognized Expert MVP
OMG!!

so, i added one more curly bracket to the very end of the code like this: [ ... ]
AND NOW I HAVE 32 ERRORS!! [ ... ]
do i have things in the wrong place?
Well, I'd say yes you have. A program text is not a linear text as in novels. First
the compiler tries to determine if the text by itself makes sense. As in:

"fridges chimneys over green fly ferocious".

This text most definitely doesn't make sense so the compiler can complain early.
If you submit this:

"ferocious green fridges fly over chimneys"

It makes sense syntactically so the compiler has to check the next 'level' of your
text. Can fridges be ferocious? Or green ? Can they fly? This is the 'short term
semantic analisys' performed by the compiler, i.e. it checks whether or not
methods exist or are reachable etc. etc. Your code violates a lot of constraints.
Securely check what the compiler has to say to you and one by one fix your mistakes.

kind regards,

Jos
Dec 5 '07 #10

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

Similar topics

3
4888
by: Raj | last post by:
Hi, I am trying to add some more information to the table which already has a lot a data (like 2-3000 records). The new information may be adding 2-3 new columns worth. Now my questions are:...
0
290
by: Justin | last post by:
I am having trouble adding some of my existing controls to my toolbox in VS.NET. Here's what is going on: 1). I have an existing project that is a Windows Control Library with a bunch of...
48
3180
by: Chad Z. Hower aka Kudzu | last post by:
A few of you may recognize me from the recent posts I have made about Indy <http://www.indyproject.org/indy.html> Those of you coming to .net from the Delphi world know truly how unique and...
1
5582
by: Christopher W. Douglas | last post by:
I am building a VB.NET application in Visual Studio.NET 2003. I have an existing project with code and forms I want to reuse in this project. If I am copying a module file, then Add Existing Item...
0
2820
by: Andre Viens | last post by:
Hello, I am using the following variation of code from <http://support.microsoft.com/default.aspx?scid=kb;EN-US;319340> to add icons to an imagelist for use in a listview: Private Structure...
4
2149
by: Mark | last post by:
Hello, When I add existing forms to a project how do I get the form code added and working too? If I load the form and .vb file the code is displayed, but the form does not recognize that the...
7
1771
by: Miro | last post by:
Im a VB Newbie so I hope I'm going about this in the right direction. I have a simple DB that has 1 Table called DBVersion and in that table the column is CurVersion ( String ) Im trying to...
8
1621
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi just wondering if anyone had any ideas on how to do this in C#. I am trying to get the total time of several start and stop time data entries. For example the input data looks like starttime...
29
2084
by: Ioannis Vranos | last post by:
Hi, I am currently learning QT, a portable C++ framework which comes with both a commercial and GPL license, and which provides conversion operations to its various types to/from standard C++...
0
7007
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...
0
7174
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7220
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
7388
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
5470
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
3099
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...
0
3091
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
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 ...
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.