Mike. J. Thompson wrote:What is it you don't get?
You've been told to implement classes that evaluate those mathematical functions. Each of those classes must inherit from the class supplied by your tutor, and implement the abstract method f(...).
Pawel Pawlowicz wrote:Abstract method is a really simple thing. It's just a method without an implementation.
A class with at least one abstract method must be abstract. An abstract class can't be instantiated.
Any class extending abstract class must either
- be abstract itself
- provide implementation for all abstract methods.
So, you have to make a subclass of AbstractDrawFunction class and then write method double f(double x) with actual body.
So, you have to draw sin(x). So just write a method that returns a sine of a number(Math.sin(double) - but you might want to scale it a little).
Then you should write somethig in method paintComponent(Graphics g). This method is called when the component is drawn.
As it is in your abstract class it should contain general code for plotting any of your functions.
What information do you have available inside this method?
You have a Polygon and Graphic.
Graphic is a class with many methods that can draw and paint things on components. If only it contained a method that could draw polygons.
A quick look at the API and voilà! It does have one.
It is drawPolygon(Polygon p).
But there is a little problem with that one. It connects the last points with the first one.
So the graph looks like this:
But wait! There is another method with similiar name that will not connect the last point to the first one! Unfortunately it doesn't take an instance of Polygon, but it takes something you can get from the Polygon.
Can you find it? Take a look here.
Mike. J. Thompson wrote:What isn't it doing right? Is there an error? Does it just not look the way you expected?
Buda young wrote:exactly some of them don't look the like the ones on google I never toke trigonometry
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Ew. You guys are ugly with a capital UG. Here, maybe this tiny ad can help:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|