193k views
2 votes
create a class circle.java which is a simple abstraction of an on-screen circle (image). a circle should (initially) have the following: int x and int y the center point of the circle's on-screen location. these values represent the circle's (initial) location on screen. int radius the radius of the circle. color color the color of the circle. color is a class that is built into java, a software abstraction of color. you can create a new color using color's three-parameter constructor (e.g. new color(50, 100, 150)), where each integer is a value 0-255 (corresponding to red, green, and blue components, respectively). there are also pre-built colors in the color class that you can use, e.g. color.red or color.black. import: java.awt.color.

User Cyrusmith
by
7.2k points

1 Answer

3 votes

Step-by-step explanation:

I've written a basic Circle class and a Main class for testing it.

You will have to initialize the x and y yourself, since I don't know how big your screen is. It's just center of screen x/y - radius of circle. There is 2 constructor, one for color(r,g,b) and another for color(Color).

Review and test the code for yourself.

Rate 5 star, if this helped :)

Answer:

import java.util.*;

import java.awt.Color;//Must import Color class in Circle class

public class Main {

public static void main(String[] args) {

System.out.println("Creating circle: ");

Circle c1 = new Circle(9,8,7, 100, 100,0);//rgb value

c1.printCircle();

Circle c2 = new Circle(1,2,3, Color.red);//color value

c2.printCircle();

}

}

public class Circle{

private int x, y, radius;

private Color color;

//Constructor

//parameter: x, y, radius, color in RGB VALUE

public Circle(int x, int y, int radius, int r, int g, int b){

this.x=x;

this.y=y;

this.radius=radius;

color = new Color(r,g,b);

}

//Overloaded Constructor for color in strong VALUE

public Circle(int x, int y, int radius, Color color){

this.x=x;

this.y=y;

this.radius=radius;

this.color = color;

}

//Test function. can delete after testing

//Prints the x,y,radius, and color of circle

public void printCircle(){

System.out.printf("Circle: x:%d y:%d radius:%d color:%s\\",x, y, radius, color.toString());

}

}

User Drewag
by
7.8k points