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....
9 1942
So, have you gone through a tutorial on arrays yet?
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?
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?
How about the horse's mouth?
i saw this site already...but still dont know where to begin.....
ok, i'm trying to work on this.....and here is what i got for my code - import java.util.*;
-
class Inventory2 implements Comparable
-
-
{
-
private String dvdTitle;
-
private int dvdItem;
-
private int dvdStock;
-
private double dvdPrice;
-
-
}//end main method
-
-
class Dvd { // Constructor for the Dvd class
-
{
-
dvdTitle = "";
-
dvdItem = 0.00;
-
dvdStock = 0.00;
-
dvdPrice = 0.00;
-
}
-
-
-
public Dvd(String title, int item, int stock, double price) // Constructor for the Supplies class
-
{
-
this.title = title;
-
this.item = item;
-
this.stock = stock;
-
this.price = price;
-
}
-
-
// 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
-
-
-
public class Inventory2 {
-
-
public static void main(String[] args) {
-
-
System.out.println ("Inventory of DVD Movies:\n");
-
-
Dvd [] supplies = new Dvds [3];
-
-
Dvd d1 = new Dvd (1, "Frosty The Snowman", 5, 14.95);
-
Dvd d2 = new Dvd (2, "Charlie Brown Christmas", 7, 12.99);
-
Dvd d3 = new Dvd (3, "Rudolph The Red-Nosed Reindeer", 6, 19.99);
-
Dvd d4 = new Dvd (4, "The Grinch Who Stole Christmas", 3, 10.99);
-
-
supplies[0] = d1;
-
supplies[1] = d2;
-
supplies[2] = d3;
-
supplies[3] = d4;
-
-
-
double total = 0.0;
-
-
for(int i= 0; i < 3;i++)
-
{
-
total = total + supplies[i].calculateInvValue();
-
}
-
-
-
-
for(Dvd d: supplies)
-
{
-
System.out.println(d);
-
System.out.println();
-
}
-
-
for(Dvd d: supplies)
-
{
-
System.out.println(d);
-
System.out.println();
-
}
-
-
-
System.out.println("Total Value is: $"+total);
-
-
-
}}//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?
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
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: - }}}//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?
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.
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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:...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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++...
|
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...
|
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,...
| |
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...
|
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...
|
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,...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |