Reputation: 45
I need to create a linkedlist. I need to add a method to a class UnsortedBulbList to append to the linkedlist. However, I keep getting the error:Cannot find Symbol. I've been stuck on this for way too long... any help would be greatly appreciated!
'''
import java.util.Objects;
public class Bulb{
private String manufacturer;
private String partNumber;
private int wattage;
private int lumens;
public Bulb(String m, String p, int w, int l){
manufacturer = m;
partNumber = p;
wattage = w;
lumens = l;
}
public String getManufacturer(){
return manufacturer;
}
public String partNumber(){
return partNumber;
}
public int wattage(){
return wattage;
}
public int lumens(){
return lumens;
}
public void setManufacturer(String m){
if (m==null){
throw new IllegalArgumentException("Bad manufacturer");
}
manufacturer = m;
}
public void partNumber(String p){
if (p==null){
throw new IllegalArgumentException("Bad partNumber");
}
partNumber = p;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Bulb)) return false;
Bulb bulb = (Bulb) o;
return wattage == bulb.wattage &&
lumens == bulb.lumens &&
manufacturer.equals(bulb.manufacturer) &&
partNumber.equals(bulb.partNumber);
}
@Override
public int hashCode() {
return Objects.hash(manufacturer, partNumber, wattage, lumens);
}
public void wattage(int w){
if (w<0){
throw new IllegalArgumentException("Bad wattage");
}
wattage = w;
}
@Override
public String toString() {
return "Bulb{" +
"manufacturer='" + manufacturer + '\'' +
", partNumber='" + partNumber + '\'' +
", wattage=" + wattage +
", lumens=" + lumens +
'}';
}
public void lumens(int l){
if (l<0){
throw new IllegalArgumentException("Bad manufacturer");
}
lumens = l;
}
}
public class BulbList {
BulbNode first;
BulbNode last;
private int length;
public BulbList () {
BulbNode ln = new BulbNode();
first = ln;
last = ln;
length = 0;
}
public void append (Bulb s) {
BulbNode n = new BulbNode(s);
last.next = n;
last = n;
length++;
}
// public LinkedListIterator reset() {
// return new LinkedListIterator(first.next);
// }
}
public class UnsortedBulbList extends BulbList{
public UnsortedBulbList(){
}
void add(Bulb u){
u.append();
}
}
'''
When I run it, I get the error : Cannot find symbol symbol:method append Location: variable u of type bulb
Upvotes: 0
Views: 83
Reputation: 1014
The mistake here is that you are trying to use the append
method of the Bulb class, which doesn't exist. Instead, I think you wanted to call the append method of the parent class, like:
public class UnsortedBulbList extends BulbList{
public UnsortedBulbList(){
}
void add(Bulb u){
super.append(u);
}
}
Upvotes: 2