-
classes and methods...
i am having a bit of trouble making this work
Code:
import java.awt.*;
import java.applet.Applet;
public class transport extends Applet{
skateboard Skateboard1;
skateboard Skateboard2;
motorbike Motorbike1;
bike Bicycle1;
bike Bicycle2;
car Car1;
car Car2;
public void init(){
this.setLayout(new Gridlayout(7.1));
Skateboard1=new skateboard();
add(Skateboard1);
Skateboard2=new skateboard();
add(Skateboard2);
Motorbike1=new motorbike();
add(Motorbike1);
Bicycle1=new bike();
add(Bicycle1);
Bicycle2=new bike();
add(Bicycle2);
Car1=new car();
add(Car1);
Car2=new car();
add(Car2);
}
public class vehicle extends Panel{//vehicle class, main class
Label make=new Label();
Label model=new Label();
Label colour=new Label();
Label cost=new Label();
Label length=new Label();
public class motorbike extends vehicle{// Motorbike class
Label engine=new Label();
Label fuel=new Label();
Label height=new Label();
Label regno=new Label();
Label acceleration=new Label();
motorbike(){
super();
make.setText("Make is: UNKNOWN");
model.setText("Model is: UNKNOWN");
colour.setText("colour is: UNKNOWN");
cost.setText("cost is: UNKNOWN");
length.setText("length is: UNKNOWN");
engine.setText("engine is: UNKNOWN");
fuel.setText("fuel is: UNKNOWN");
height.setText("height is: UNKNOWN");
regno.setText("reistration is: UNKNOWN");
acceleration.setText("acceleration is: UNKNOWN");
add(make);
add(model);
add(colour);
add(cost);
add(length);
add(engine);
add(fuel);
add(height);
add(regno);
add(acceleration);
}
public class car extends motorbike{// Car class, Subclass of motorbike
Label passengers=new Label();
car(){
super();
passengers.setText("Number of passengers is: UNKNOWN");
add(passengers);
}
}
}
public class unpowered extends vehicle{//unpowered class
Label weight=new Label();
unpowered(){
super();
weight.setText("Weight is: UNKNOWN");
add(weight);
}
public class skateboard extends unpowered{//skateboard class, subclass of unpowered
Label width=new Label();
skateboard(){
super();
width.setText("Width is: UNKNOWN");
add(width);
}
}
public class bike extends unpowered{//bike class, subclass of unpowered
Label gears=new Label();
bike(){
super();
gears.setText("The number of gears is: UNKNOWN");
add(gears);
}
}
}
}
}
i cant seem to fix the errors, maily about the super(); bits, and the beginning variables. what have i done wrong?
-
Please post any error messages you're getting.
ArchAngel.
O:-)
-
javac transport.java
transport.java:6: cannot resolve symbol
symbol : class skateboard
location: class transport
skateboard Skateboard1;
^
transport.java:7: cannot resolve symbol
symbol : class skateboard
location: class transport
skateboard Skateboard2;
^
transport.java:8: cannot resolve symbol
symbol : class motorbike
location: class transport
motorbike Motorbike1;
^
transport.java:9: cannot resolve symbol
symbol : class bike
location: class transport
bike Bicycle1;
^
transport.java:10: cannot resolve symbol
symbol : class bike
location: class transport
bike Bicycle2;
^
transport.java:11: cannot resolve symbol
symbol : class car
location: class transport
car Car1;
^
transport.java:12: cannot resolve symbol
symbol : class car
location: class transport
car Car2;
^
transport.java:15: cannot resolve symbol
symbol : class Gridlayout
location: class transport
this.setLayout(new Gridlayout(7.1));
^
transport.java:16: cannot resolve symbol
symbol : class skateboard
location: class transport
Skateboard1=new skateboard();
^
transport.java:18: cannot resolve symbol
symbol : class skateboard
location: class transport
Skateboard2=new skateboard();
^
transport.java:20: cannot resolve symbol
symbol : class motorbike
location: class transport
Motorbike1=new motorbike();
^
transport.java:22: cannot resolve symbol
symbol : class bike
location: class transport
Bicycle1=new bike();
^
transport.java:24: cannot resolve symbol
symbol : class bike
location: class transport
Bicycle2=new bike();
^
transport.java:26: cannot resolve symbol
symbol : class car
location: class transport
Car1=new car();
^
transport.java:28: cannot resolve symbol
symbol : class car
location: class transport
Car2=new car();
^
transport.java:75: cannot reference this before supertype constructor has been called
super();
^
transport.java:94: cannot reference this before supertype constructor has been called
super();
^
transport.java:102: cannot reference this before supertype constructor has been called
super();
^
18 errors
not really sure how to fix them.. pardon if i am a n00b...
-
Well, it's clear from the error message that it can't find skateboard (by the way, classes in Java typically have a first capital letter - Skateboard).
You've written your hierarchy in a very strange way, using nested classes. Why? Is it some form of requirement?
If you want to leave it like that, then you'll have to create instances of other classes before you can reach a class from which skateboard is visible.
ArchAngel.
O:-)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks