this is my first post here. I'm a student taking AP Computer Science in high school. For a project, I have to draw a picture of a basketball. Okay, easy enough. The problem is that I have to do this using correct Composition and Inheritance. I can't just throw a bunch of graphics methods in the main class. I've got all the basic code down, but here is what I need help with...
- I want class
Basketball
to inherit everything from super-classCircle
. Did I do that correctly by extending classCircle
in the classBasketball
heading? - Inside of class
Basketball
, how can I link to class Lines and classAirValve
in order to show proper composition?
As you can see, I understand the concepts but I don't understand how to make them happen very well.
import java.awt.*;
import java.applet.*;
import java.util.*;
import java.awt.Color;
import java.awt.Graphics;
/* The point of this lab is to draw a basketball using one example of
* proper inheritance and two examples of proper composition.
*/
public class Basketball extends Circle
{
public static void main(String[] args)
{
Lines line = new Lines();
AirValve airvalve = new AirValve();
}
}
class Lines
{
public Lines()
{
}
public void paintLine(Graphics g)
{
g.drawArc(300, 275, 200, 275, 295, 135); //left arc
g.drawLine(650, 150, 650, 650); //middle line
g.drawLine(400, 400, 900, 400); //cross line
g.drawArc(800, 275, 200, 275, 245, -135); //right arc
}
}
class Circle
{
public Circle()
{
}
public void paintCirc(Graphics g)
{
g.setColor(Color.orange);
g.fillOval(400, 150, 500, 500);
}
}
class AirValve
{
public AirValve()
{
}
public void paintAV(Graphics g)
{
g.setColor(Color.black);
g.fillOval(645, 625, 10, 10);
}
}