Join 150,068 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,808 people online right now. Registration is fast and FREE... Join Now!
I need help with the following errors. (the arrow is suppose to be under the red character) Thank you. C:\Users\Michael\Desktop\inventory2\Inventory1Test.java:20: cannot find symbol symbol : method getRating() location: class Inventory1 System.out.printf( "\nMovie Rating: \t%s", DVD[i].getRating()); ^ C:\Users\Michael\Desktop\inventory2\Inventory1Test.java:37: cannot find symbol symbol : method getRating() location: class Inventory1 System.out.pringf( "\nMovie Rating: \t%s", DVD[i].getRating()); ^ C:\Users\Michael\Desktop\inventory2\Inventory1Test.java:48: cannot find symbol symbol : method getValueRestockingFee(Inventory1[]) location: class Inventory1 Double restockingFee = DVD[0].getValueRestockingFee(DVD); ^ 3 errors
CODE
//Overloaded constructors used to initialize inventory import java.lang.String; public class Inventory1Test { public static void main( String args[] ) { Inventory1[] DVD = new DVD[4];
DVD[0] = new DVD( "1", "Star Wars", "PG", 232, 5, 13.45); DVD[1] = new DVD("2", "Cars", "G", 233, 7, 12.23 ); DVD[2] = new DVD("3", "Fantastic Four", "PG", 234, 8, 18.45); DVD[3] = new DVD("4", "Batman", "PG-13", 235, 2, 10.88);
System.out.println( "\nInventory of DVD Movies: " );
for (int i = 0; i < DVD.length; i++) { System.out.printf( "\nItem #%s ", DVD[i].getItems()); System.out.printf( "\nTitle of Movie: \t%s", DVD[i].getVideo()); System.out.printf( "\nMovie Rating: \t%s", DVD[i].getRating()); System.out.printf( "\nItem Number: \t\t%s", DVD[i].getNumber()); System.out.printf( "\n# of Items in Stock: \t%s", DVD[i].getStock()); System.out.printf( "\nPurchase Price: \t$%s", DVD[i].getPrice()); System.out.printf( "\nInventory Value: \t$%s\n\n", DVD[i].getValue());
}//end
DVD[0].SortInventory1(DVD); System.out.println( "\nSorted Inventory of DVD Movies:"); for (int i = 0; i < DVD.length; i++) { System.out.printf( "\nItem #%s ", DVD[i].getItems()); System.out.printf( "\nTitle of Movie: \t%s", DVD[i].getVideo()); System.out.pringf( "\nMovie Rating: \t%s", DVD[i].getRating()); System.out.printf( "\nItem Number: \t\t%s", DVD[i].getNumber()); System.out.printf( "\n# of Items in Stock: \t%s", DVD[i].getStock()); System.out.printf( "\nPurchase Price: \t$%s", DVD[i].getPrice()); System.out.printf( "\nInventory Value: \t$%s\n\n", DVD[i].getValue()); }//end
Since you've subclassed Inventory1, so your array should be of the same type as your subclass i.e. a DVD array not an Inventory1 array. Confusingly, you've now got an array of type Inventory1 but named DVD, the same as your subclass.
Change it to something like
DVD[] stockArray = new DVD[4];
And then you'll need to update all your references to the DVD array to the new variable name.
CODE
//Overloaded constructors used to initialize inventory import java.lang.String; public class Inventory1Test { public static void main( String args[] ) { DVD[] stockArray = new DVD[4];
stockArray[0] = new DVD( "1", "Star Wars", "PG", 232, 5, 13.45); stockArray[1] = new DVD("2", "Cars", "G", 233, 7, 12.23 ); stockArray[2] = new DVD("3", "Fantastic Four", "PG", 234, 8, 18.45); stockArray[3] = new DVD("4", "Batman", "PG-13", 235, 2, 10.88);
System.out.println( "\nInventory of DVD Movies: " );
for (int i = 0; i < stockArray.length; i++) { System.out.printf( "\nItem #%s ", stockArray[i].getItems()); System.out.printf( "\nTitle of Movie: \t%s", stockArray[i].getVideo()); System.out.printf( "\nMovie Rating: \t%s", stockArray[i].getRating()); System.out.printf( "\nItem Number: \t\t%s", stockArray[i].getNumber()); System.out.printf( "\n# of Items in Stock: \t%s", stockArray[i].getStock()); System.out.printf( "\nPurchase Price: \t$%s", stockArray[i].getPrice()); System.out.printf( "\nInventory Value: \t$%s\n\n", stockArray[i].getValue());
}//end
stockArray[0].SortInventory1(stockArray); System.out.println( "\nSorted Inventory of DVD Movies:"); for (int i = 0; i < stockArray.length; i++) { System.out.printf( "\nItem #%s ", stockArray[i].getItems()); System.out.printf( "\nTitle of Movie: \t%s", stockArray[i].getVideo()); System.out.pringf( "\nMovie Rating: \t%s", stockArray[i].getRating()); System.out.printf( "\nItem Number: \t\t%s", stockArray[i].getNumber()); System.out.printf( "\n# of Items in Stock: \t%s", stockArray[i].getStock()); System.out.printf( "\nPurchase Price: \t$%s", stockArray[i].getPrice()); System.out.printf( "\nInventory Value: \t$%s\n\n", stockArray[i].getValue()); }//end
What am I doing wrong with the restocking fee part? I am getting the following error:
C:\Users\Michael\Desktop\java1\Inventory1Test.java:28: cannot find symbol symbol : method getValueRestockingFee(DVD[]) location: class DVD Double restockingFee = library[i].getValueRestockingFee(library);
QUOTE(cutegrrl @ 3 Jun, 2008 - 01:30 AM)
Generally, it's usually a good idea to post all the code if possible and to give a brief summary of the program. It will allow us to better help you.
With that said, you've declared your array incorrectly. It should be like the following:
java
// type[] variableName = new type[size]; DVD[] library = new DVD[4];
Also, in your second error you incorrectly wrote System.out.pringf.
Here is the code with aforementioned errors fixed:
java
package temp; import java.lang.String; public class Inventory1Test { public static void main( String args[] ) { DVD[] library = new DVD[4];
library[0] = new DVD( "1", "Star Wars", "PG", 232, 5, 13.45); library[1] = new DVD("2", "Cars", "G", 233, 7, 12.23 ); library[2] = new DVD("3", "Fantastic Four", "PG", 234, 8, 18.45); library[3] = new DVD("4", "Batman", "PG-13", 235, 2, 10.88);
System.out.println( "\nInventory of DVD Movies: " );
for (int i = 0; i < library.length; i++) { System.out.printf( "\nItem #%s ", library[i].getItems()); System.out.printf( "\nTitle of Movie: \t%s", library[i].getVideo()); System.out.printf( "\nMovie Rating: \t%s", library[i].getRating()); System.out.printf( "\nItem Number: \t\t%s", library[i].getNumber()); System.out.printf( "\n# of Items in Stock: \t%s", library[i].getStock()); System.out.printf( "\nPurchase Price: \t$%s", library[i].getPrice()); System.out.printf( "\nInventory Value: \t$%s\n\n", library[i].getValue());
}//end
library[0].SortInventory1(library); System.out.println( "\nSorted Inventory of DVD Movies:"); for (int i = 0; i < library.length; i++) { System.out.printf( "\nItem #%s ", library[i].getItems()); System.out.printf( "\nTitle of Movie: \t%s", library[i].getVideo()); System.out.printf( "\nMovie Rating: \t%s", library[i].getRating()); System.out.printf( "\nItem Number: \t\t%s", library[i].getNumber()); System.out.printf( "\n# of Items in Stock: \t%s", library[i].getStock()); System.out.printf( "\nPurchase Price: \t$%s", library[i].getPrice()); System.out.printf( "\nInventory Value: \t$%s\n\n", library[i].getValue()); }//end
I think it's mensahero's second suggestion - I can't see that you have written a getValueRestockingFee method anywhere, so that's why it can't be found.
Or it might be declared in the Inventory1 class that you still haven't posted with a different parameter list. Anyway, it is difficult to guess from this. Either way it would be easier if you told us what your function is supposed to do.
Also, a method like Double CalculateTotalInventoryValue(Inventory1[] product) that does not use any member attribute should be declared static, so it is easier to use (DVD.CalculateTotalInventoryValue(library) )
Okay here is my whole code everything is running the way it is suppose to (i think:-) ) My problem is with the restocking fee. Any help would be most greatful!! I have been working on this for days. Thank you
CODE
//inventory part 1 import java.lang.String; public class Inventory1 { protected String items; protected String video; protected int number; protected int stock; protected double price; protected double value;
public Inventory1( String i, String v, int n, int s, double p ) { setItems(i); setVideo(v); setNumber(n); setStock(s); setPrice(p); }//end Inventory1 five-argument constructor
public Inventory1( Inventory1 inventory) { this( inventory.getItems(), inventory.getVideo(), inventory.getNumber(), inventory.getStock(), inventory.getPrice() ); }//end Inventoryconstructor with a Inventory object argument
public void setInventory1( String i, String v, int n, int s, double p ) { setItems( i ); setVideo( v ); setNumber( n ); setStock( s ); setPrice( p ); }//end method setInventory
public void setItems( String i ) { items = ( i ); }//end method setItems
public void setVideo( String v ) { video = ( v ); }//end method setVideo
public void setNumber( int n ) { number = ( n ); }//end method setNumber
public void setStock( int s ) { stock = ( s ); }//end method setStock
public void setPrice(double p ) { price = ( p ); }//end method setPrice
public String getItems() { return items; }//end method getItems
public String getVideo() { return video; }//end method getVideo
public int getNumber() { return number; }//end method getNumber
public int getStock() { return stock; }//end method getStock
public double getPrice() { return price; }//end method getPrice
public class DVD extends Inventory1 { // Holds the rating of the movie private String movierating; private String items; private String video; private int number; private int stock; private double price;
private double value;
public DVD( String items, String video, String rating, int number, int stock, double price ) { super( items, video, number, stock, price ); movierating = rating;
}
public String getRating() { return movierating; } public Double CalculateTotalInventoryValue(Inventory1[] product) { Double total = 0.0; for(int index = 0; index < product.length; index++) { Inventory1 inv = product[index]; total += inv.getValue(); }
return total; }
public double getItemValue() { return super.getValue() * 1.05; }
// Simply gets the base class's value, and figures out the 5% restocking fee only public double getRestockingFee() { return super.getValue() * .05; }
public Inventory1[] SortInventory1 (Inventory1[] theInventory1) { Inventory1 tmp;
for (int index = 0; index < theInventory1.length; index++) { for (int anotherindex = index + 1; anotherindex< theInventory1.length; anotherindex++) { String s1 = theInventory1[index].getVideo(); String s2 = theInventory1[anotherindex].getVideo(); if( s1.compareTo(s2) > 0) { tmp = theInventory1[index]; theInventory1 [index] = theInventory1[anotherindex]; theInventory1 [anotherindex] = tmp; } } } return theInventory1; } }//end class DVD
CODE
//Overloaded constructors used to initialize inventory import java.lang.String;
public class Inventory1Test {
public static void main( String args[] ) { DVD[] library = new DVD[4];
library[0] = new DVD( "1", "Star Wars", "PG", 232, 5, 13.45); library[1] = new DVD("2", "Cars", "G", 233, 7, 12.23 ); library[2] = new DVD("3", "Fantastic Four", "PG", 234, 8, 18.45); library[3] = new DVD("4", "Batman", "PG-13", 235, 2, 10.88);
System.out.println( "\nInventory of DVD Movies: " );
for (int i = 0; i < library.length; i++) { System.out.printf( "\nItem #%s ", library[i].getItems()); System.out.printf( "\nTitle of Movie: \t%s", library[i].getVideo()); System.out.printf( "\nMovie Rating: \t\t%s", library[i].getRating() ); System.out.printf( "\nItem Number: \t\t%s", library[i].getNumber()); System.out.printf( "\n# of Items in Stock: \t%s", library[i].getStock()); System.out.printf( "\nPurchase Price: \t$%s", library[i].getPrice()); System.out.printf( "\nInventory Value: \t$%s\n\n", library[i].getValue());
}//end
library[0].SortInventory1(library); System.out.println( "\nSorted Inventory of DVD Movies:"); for (int i = 0; i < library.length; i++) { System.out.printf( "\nItem #%s ", library[i].getItems()); System.out.printf( "\nTitle of Movie: \t%s", library[i].getVideo()); System.out.printf( "\nMovie Rating: \t\t%s", library[i].getRating() ); System.out.printf( "\nItem Number: \t\t%s", library[i].getNumber()); System.out.printf( "\n# of Items in Stock: \t%s", library[i].getStock()); System.out.printf( "\nPurchase Price: \t$%s", library[i].getPrice()); System.out.printf( "\nInventory Value: \t$%s\n\n", library[i].getValue());
Or it might be declared in the Inventory1 class that you still haven't posted with a different parameter list. Anyway, it is difficult to guess from this. Either way it would be easier if you told us what your function is supposed to do.
Also, a method like Double CalculateTotalInventoryValue(Inventory1[] product) that does not use any member attribute should be declared static, so it is easier to use (DVD.CalculateTotalInventoryValue(library) )