Results 1 to 19 of 19
- 10-11-2011, 12:48 AM #1
Member
- Join Date
- Oct 2011
- Posts
- 38
- Rep Power
- 0
I need help i have 8 errors can someone pleasehelp me
can i get someone to help me with this:
class Cameras {
private String ItemNumber;
private String ProductName;
private double UnitsStock;
private double UnitPrice;
private String SerialNumber;
private double InventoryValue;
public Cameras (String item, String product, double units, double price, String serial) {
ItemNumber = item;
ProductName = product;
UnitsStock = units;
UnitPrice = price;
SerialNumber = serial;
}
public void setItemNumber (String item) {
this.ItemNumber = item;
}
public String getItemNumber() {
return ItemNumber;
}
public void setProductName (String product) {
this.ProductName = product;
}
public String getProductName() {
return ProductName;
}
public void setUnitsStock (double units) {
this.UnitsStock = units;
}
public double getUnitsStock() {
return UnitsStock;
}
public void setUnitPrice (double price) {
this.UnitPrice = price;
}
public double getUnitPrice() {
return UnitPrice;
}
public void setSerialNumber (String serial) {
this.SerialNumber = serial;
}
public String getSerialNumber() {
return SerialNumber;
}
public double getInventoryValue(){
return UnitsStock * UnitPrice;
}
public double calculateInventory(){
return UnitPrice * UnitsStock;
}
}
class Manufacturer extends Cameras {
private String manufacturerName;
public Camera(int ItemNumber, String ProductName, int UnitsStock, double UnitPrice, String ManufacturerName) {
ItemNumber = Item;
ProductName = Product;
UnitsStock = Units;
UnitPrice = UnitPrice;
ManufacturerName = mfgName;
}
public void setmanufacturerName(String mfgName) {
manufacturerName = mfgName;
}
public String getmanufacturerName() {
return manufacturerName;
}
public double calculateInventory(){
return ((UnitPrice * UnitsStock));
}
public double getcalculateRestockFee() {
return getInventoryValue();
}
}
- 10-11-2011, 01:18 AM #2
Member
- Join Date
- Oct 2011
- Posts
- 83
- Rep Power
- 0
Re: I need help i have 8 errors can someone pleasehelp me
This problem is in your constructor for Manufacturer. Change this line:
public Camera(int ItemNumber, String ProductName, int UnitsStock, double UnitPrice, String ManufacturerName) {
to this:
public Manufacturer(int ItemNumber, String ProductName, int UnitsStock, double UnitPrice, String ManufacturerName) {
The constructor is always named after the class it's in, NOT that class's superclass.
Furthermore, you must call the superclass's constructor in a class's constructor (in this case, call Cameras's constructor in Manufacturer's constructor). These means that each of the five parameters passed to Cameras's constructor must also be passed to Manufacturer's constructor, and the first line of Manufacturer's constructor must look something like this:
super(item,product,units,price,serial);
Finally, you cannot refer to private members of a class in its subclass. In order to do that, you must define their visibility as "protected" rather than "private".
- 10-11-2011, 04:21 AM #3
Member
- Join Date
- Oct 2011
- Posts
- 38
- Rep Power
- 0
Re: I need help i have 8 errors can someone pleasehelp me
this is my code i add some more and i got it to 8 errors now and i just cant find them i am so sorry i am new to all of this..
public class Cameras{
private int itemNumber;
private String productName;
private int unitsInStock;
private double price;
public Cameras() {
}
public Cameras(int itemNumber, String productName, int unitsInStock,
double price) {
this.itemNumber = itemNumber;
this.productName = productName;
this.unitsInStock = unitsInStock;
this.price = price;
}
public double calculateInventory() {
return this.unitsInStock * this.price;
}
public int getItemNumber() {
return itemNumber;
}
public String getProductName() {
return productName;
}
public int getUnitsInStock() {
return unitsInStock;
}
public double getPrice() {
return price;
}
public void setItemNumber(int itemNumber) {
this.itemNumber = itemNumber;
}
public void setName(String productName) {
this.productName = productName;
}
public void setUnitsInStock(int unitsInStock) {
this.unitsInStock = unitsInStock;
}
public void setPrice(double price) {
this.price = price;
}
}
class Manufacturer extends Cameras {
private String manufacturerName;
public Manufacturer(int itemNumber, String productName, int unitsInStock,double price, String ManufacturerName); { [ missing body or declare abstract]
^
super(itemNumber, productName, unitsInStock, price);[call to super must be first statement in constructor]
^
this.ManufacturerName = ManufacturerName; [can not find symbol]
^ ^
}
public double calculateRestockFee() {
return super.calculateInventory() * .05;
}
public double calculateInventory() { [unitInstock has private access in Cameras]
return this.unitsInStock * this.price;
^ ^
}
public String getManufacturerName(){ [can not find symbol]
return ManufacturerName;
^
}
public void setManufacturerName(String ManufacturerName){ [can not find symbol]
this.ManufacturerName = ManufacturerName;
^
}
}Last edited by MikeJ39; 10-11-2011 at 03:38 PM. Reason: adding the errors in
-
Re: I need help i have 8 errors can someone pleasehelp me
You're not telling us what errors you're seeing which is making it hard to help you. Also you'll want to edit your posts above and add code tags so that your code is readable. To do this, add the tag [code] above your code block, and the tag [/code] below your code block:
- 10-11-2011, 04:41 PM #5
Member
- Join Date
- Oct 2011
- Posts
- 38
- Rep Power
- 0
Re: I need help i have 8 errors can someone pleasehelp me
OK i got all the errors fixed all but one now and that is in public static void main(String[] args);
^
now what do i do?
- 10-11-2011, 04:57 PM #6
Re: I need help i have 8 errors can someone pleasehelp me
tell us wich error you get....
that'll help a lot
- 10-11-2011, 05:02 PM #7
Member
- Join Date
- Oct 2011
- Posts
- 38
- Rep Power
- 0
Re: I need help i have 8 errors can someone pleasehelp me
ok i got the first done now if you look at the last post i have the errors maked with ^ but i got the body one fix now i need to fix the rest
- 10-11-2011, 06:50 PM #8
Re: I need help i have 8 errors can someone pleasehelp me
we mean that you should show us the error that you get when you run the program...
prob an exception... like a nullPointerException,...
tell us wich one it is, it'll make it easier for us to search where the problem might be..
- 10-11-2011, 06:58 PM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,394
- Blog Entries
- 7
- Rep Power
- 17
Re: I need help i have 8 errors can someone pleasehelp me
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 10-11-2011, 07:10 PM #10
Member
- Join Date
- Oct 2011
- Posts
- 38
- Rep Power
- 0
Re: I need help i have 8 errors can someone pleasehelp me
ok this is my code: the errors i am getting is line 105 missing body, or declare abstract [public Manufacturer(int itemNumber, String productName, int unitsInStock,double price, String ManufacturerName); {
^
and then on line 107 [ Error call to super must be first statement in constructor[ super(itemNumber, productName, unitsInStock, price);
^
then on line 119 their are 2 errors public double calculateInventory() {
return this.unitsInStock * this.price;
^ ^
Java Code:class Cameras{ public static void main(String[] args){ } private int itemNumber; private String productName; private int unitsInStock; private double price; public Cameras() { } public Cameras(int itemNumber, String productName, int unitsInStock, double price) { this.itemNumber = itemNumber; this.productName = productName; this.unitsInStock = unitsInStock; this.price = price; } public double calculateInventory() { return this.unitsInStock * this.price; } public int getItemNumber() { return itemNumber; } public String getProductName() { return productName; } public int getUnitsInStock() { return unitsInStock; } public double getPrice() { return price; } public void setItemNumber(int itemNumber) { this.itemNumber = itemNumber; } public void setName(String productName) { this.productName = productName; } public void setUnitsInStock(int unitsInStock) { this.unitsInStock = unitsInStock; } public void setPrice(double price) { this.price = price; } } class Manufacturer extends Cameras { private String manufacturerName; public Manufacturer(int itemNumber, String productName, int unitsInStock,double price, String ManufacturerName); { super(itemNumber, productName, unitsInStock, price); this.manufacturerName = manufacturerName; } public double calculateRestockFee() { return super.calculateInventory() * .05; } public double calculateInventory() { return this.unitsInStock * this.price; } public String getManufacturerName(){ return manufacturerName; } public void setManufacturerName(String ManufacturerName){ this.manufacturerName = manufacturerName; } }Last edited by Fubarable; 10-11-2011 at 07:16 PM. Reason: code tags added
-
Re: I need help i have 8 errors can someone pleasehelp me
Code tags were added to your post above, but it's still difficult to read as you've posted unformatted or poorly formatted code.
- 10-11-2011, 07:51 PM #12
Member
- Join Date
- Oct 2011
- Posts
- 83
- Rep Power
- 0
Re: I need help i have 8 errors can someone pleasehelp me
You have a superfluous semicolon in line 105. Remove that and the first two errors should be fixed.
For the other error, the following method:
should go in the Cameras class, not the Manufacturer class. This is because unitsInStock and price are declared as private in the Cameras class, and are not visible in Manufacturer. Also, the two "this." in that method are unnecessary, though they won't break the program. Same with the "super." in line 115.Java Code:public double calculateInventory() { return this.unitsInStock * this.price; }
- 10-11-2011, 07:59 PM #13
Member
- Join Date
- Oct 2011
- Posts
- 38
- Rep Power
- 0
Re: I need help i have 8 errors can someone pleasehelp me
ok i am so lost with this all did you make changes to the code i put in?
- 10-11-2011, 08:07 PM #14
Member
- Join Date
- Oct 2011
- Posts
- 83
- Rep Power
- 0
Re: I need help i have 8 errors can someone pleasehelp me
Fubarable did not make any changes to the code itself, he just added [code] tags around it, making it slightly more readable. Apply the changes I mentioned in my previous post and your program should work (at least, it should compile successfully).
- 10-11-2011, 08:37 PM #15
Member
- Join Date
- Oct 2011
- Posts
- 38
- Rep Power
- 0
Re: I need help i have 8 errors can someone pleasehelp me
ok i got that fixed and now i have another code for inventory. could you check it out for me please because i am getting 10 errors when i try to compile....
Most of the errors are the same in each line as follows:
error: cannot find symbol
products[0] = new manufacturer(500, "PowerShot", 10, 800, "Canon");
------------------^
__________________________________________________ _____________________
The other error I am getting on one line is as follows:
error: incompatible types
Manufacturer manufacturer = products[i];
------------------------------------^
- 10-11-2011, 08:58 PM #16
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,394
- Blog Entries
- 7
- Rep Power
- 17
Re: I need help i have 8 errors can someone pleasehelp me
If you'd used those [code] ... [/code] tags those little carets would've ended up where they belong; it was already suggested to you to do so. Tip: read what the compiler had to say; the folks who implemented that compiler did their best to make those error messages as clear as possible.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 10-11-2011, 10:41 PM #17
Member
- Join Date
- Oct 2011
- Posts
- 38
- Rep Power
- 0
Re: I need help i have 8 errors can someone pleasehelp me
ok Jos i have a new code and i am getting 11 errors on it can you please help me with this i tried everything
error: cannot find symbol
Java Code:Supplier[] products = new Supplier[5]; ^
- 10-11-2011, 10:42 PM #18
Member
- Join Date
- Oct 2011
- Posts
- 83
- Rep Power
- 0
-
Re: I need help i have 8 errors can someone pleasehelp me
Similar Threads
-
First Java Program-Compile Errors (errors are posted)-simple GUI
By cc11rocks in forum AWT / SwingReplies: 4Last Post: 01-04-2011, 12:36 AM -
errors
By santosh chauhan in forum New To JavaReplies: 5Last Post: 07-26-2010, 07:59 PM -
Errors?
By Jamison5213 in forum New To JavaReplies: 4Last Post: 12-30-2009, 12:14 AM -
getting errors
By ravikumar in forum Threads and SynchronizationReplies: 3Last Post: 08-23-2009, 02:50 PM -
What is the difference between Semantic Errors and Logical Errors?
By tlau3128 in forum New To JavaReplies: 3Last Post: 03-08-2009, 01:51 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks