Create a hierarchy of Java classes as demonstrated below:
MyLine is_a MyShape:
MyPolygon is_a MyShape:
MyCircle is_a MyShape:
MyShape is the hierarchyβs superclass and inherits the Java class Object. By using JavaFX graphics and the class hierarchy, the user should be able to draw a geometric configuration. For example, an image of alternating concentric circles and inscribed hexagons can be generated, as shown in the assignment sheet. The following additional requirements must be met:
- The code is applicable to canvases of variable height and width.
- The dimensions of the shapes are proportional to the smallest dimension of the canvas.
- The hexagons and circles are filled with different colors of your choice, specified through a MyColor enum reference type.
Β
[2] Solution Methods
Β
Class MyShape
MyShape was built to be the superclass of MyLine, MyPolygon, and MyCircle. It initializes two private integer variables that hold an x and y coordinate, as well as a private color variable. The constructor gives a value to these private variables when called. The class contains 3 getter methods and 3 setter methods. The getter methods are getX(), getY(), and getColor(), which returns the x coordinate, y coordinate, and shape color respectively. The setter methods are setX(), setY(), and setColor(), which sets the x coordinate, y coordinate, and shape color respectively. The imports are for the graphics context, which helps draw the shape, and the color.
There are two more methods: toString(), which prints out the MyShape object and its properties in a certain format, and draw(GraphicsContext gc). The draw method takes a graphics context variable as its parameter and only fills the color of the shape.
Β
Β
Class MyLine
MyLine is an extension of MyShape, and it starts off with 4 private integers specifically for this class. These integers represent the x and y coordinates of two points. The constructor calls super in order to obtain a color for the line, and then continues to assign values for the coordinates of the two points of the line. The class contains 2 getter methods. The first is getLength(), which uses the distance formula and returns the distance between the two points, and the second method is get_xAngle(), which returns the angle in degrees via arc tangent formula. The imports are for the graphics context, which helps draw the shape, and the color.
There are two more methods: toString(), which prints out the MyLine object and its properties in a certain format, and draw(GraphicsContext gc). The draw method takes a graphics context variable as its parameter and draws a line between two points.
Β
Β
Class MyCircle
MyCircle is an extension of MyShape, and it has a private double variable for radius. The constructor sets up the center point and the color of the circle via the super call. It also sets the radius on the next line. There are 3 getter methods, each one involving the radius variable. The getArea() method returns the area of the circle using the standard pi multiplied by the radius squared. The getPerimeter() method returns the perimeter of the circle by multiplying the radius by 2 times pi. The getRadius() method simply returns the radius. The imports are for the graphics context, which helps draw the shape, and the color.
There are two more methods: toString(), which prints out the MyCircle object and its properties in a certain format, and draw(GraphicsContext gc). The draw method takes a graphics context variable as its parameter and fills the circle a certain color.
Β
Β
Class MyPolygon
MyPolygon is an extension of MyShape, and it goes more in depth than the other classes. It has 4 private variables: one double variable for the radius, one integer variable for the number of sides, and two arrays to store x and y coordinates. The constructor starts off with calling super in order to have a center point as well as a color for the polygon. Furthermore, the radius and sides are set accordingly, and two arrays are created to store the x and y coordinates respectively for each corner of the polygon. The angle is determined from dividing 2 times pi by the number of sides. By using this angle, the points around the polygon can be determined by using the appropriate trigonometric formulas. The imports are for the graphics context, which helps draw the shape, and the color.
There are 6 getter methods, each returning a double value that describes a property of the polygon. The first is getRadius(), which simply returns the distance from the center point to one corner of the polygon. Next is getArea(), which returns an area that was calculated using a formula that works for every normal polygon. The method getPerimeter() multiplies the side length by the number of sides, and returns the perimeter. The following method, getApothem(), returns the apothem, which is the distance from the center point to the middle of one side of the polygon. This is calculated by multiplying the radius by the cosine of 180 degrees divided by the number of sides. A simple getAngle() method returns the angle between two corners of the polygon. The final method, getSide(), returns the length of one side of the polygon. This is found by multiplying 2 times the radius by the sin of the angle between two corners of the polygon.
There are two more methods: toString(), which prints out the MyPolygon object and its properties in a certain format, and draw(GraphicsContext gc). The draw method takes a graphics context variable as its parameter and fills the polygon a certain color. It also scribes each side of the polygon and creates a perimeter that is the same color as the inside of the polygon.
Β
Β
Class Main
Main is where objects from the other classes are created and drawn. There are multiple imports used here. The first import is javafx.application.Application, which is used to create a separate extended application that holds the graphics all together. Next is javafx.scene.Scene, which holds the content inside the window. The import javafx.stage.Stage is the window itself with functions such as minimize, maximize, resize, and close. Next is the import javafx.scene.canvas.Canvas, which is basically the drawing board. The graphics context comes from javafx.scene.canvas.GraphicsContext, and it behaves like a pen that draws and fills shapes, lines, and colors. The final import is javafx.scene.layout.StackPane, which is a layout for the elements that allows them to be stacked on top of each other instead of horizontally or vertically.
There are two final integer values in the beginning of the class, which are for determining the window width and height. These can be changed to whatever values the user likes, as long as it is an integer. A stage is set up with the title βAssignment 1β, as well as a canvas for the graphics context to draw on. The line width of the graphics context was set for 3 just because of preference.
A series of objects were made to mimic the figure shown on the assignment sheet. Alternating polygons and circles of different colors were made, each one using the radius or apothem of the shape before it. This was to insure that each shape was inscribed with the one outside of it. Lastly, two diagonal black lines were drawn on top of the sequence of shapes to complete the picture. The properties of each object were printed via their respective toString() methods.
Β
Β
Enum MyColor
MyColor imports javafx.scene.paint.Color in order to pass custom RGBA (red, green, blue, and opacity) values and obtain an actual value for the color in hexadecimal. The enum has multiple predefined colors ranging across the spectrum, each having its own unique RGBA values. The private integers r, g, b, a hold values for red, green, blue, and the opacity respectively. The constructor takes in custom values that will be assigned to the private variables.
The function getCol() returns a color by using the Color.rgb method from javafx.scene.paint.Color. An example of this being used is executing MyColor.CYAN.getCol(), which will return the color for cyan.
Β
[3] Codes Developed
ββ MyShape.java ββ
| /* βββββββββββββββββββ- |
| Class MyShape is the hierarchyβs superclass and inherits the |
| Java class Object. An implementation of the class defines a |
| reference point (x, y) and the color of the shape. |
| βββββββββββββββββββ- */ |
| package βsampleβ; |
| import βjavafx.scene.canvas.GraphicsContextβ; |
| import βjavafx.scene.paint.Colorβ; |
| public class βMyShape { |
| Β Β βprivate int βxβ, βyβ; β// Point of shape in pixels |
| Β Β βprivate βColor βcolorβ; |
| Β Β βMyShapeβ(βint βxβ, int βyβ, βColor color){ |
| Β Β Β Β Β Β βthisβ.βx β= xβ; |
| Β Β Β Β Β Β thisβ.βy β= yβ; |
| Β Β Β Β Β Β thisβ.βcolor β= colorβ; |
| Β Β β} |
| Β Β βpublic int βgetXβ(){ βreturn βxβ; β} |
| Β Β βpublic int βgetYβ(){ βreturn βyβ; β} |
| Β Β βpublic βColor βgetColorβ(){ βreturn βcolorβ; β} |
| Β Β βpublic void βsetXβ(βint βx){ βthisβ.βx β= xβ; β} |
| Β Β βpublic void βsetYβ(βint βy){ βthisβ.βy β= yβ; β} |
| Β Β βpublic void βsetColorβ(Color color){ βthisβ.βcolor β= colorβ; β} |
| Β Β βpublic βString βtoStringβ(){ |
| Β Β Β Β Β Β βreturn βString.βformatβ(ββββ Shape Properties βββ\nβ%15s (%d,%d)β\nβ%15s β |
| + getColor(),β |
| Β Β Β Β Β Β Β Β Β Β Β Β Β Β ββStart Point:ββ,βxβ,βyβ,ββColor:ββ)β; |
| Β Β β} |
| Β Β βpublic void βdrawβ(GraphicsContext gc){ |
| Β Β Β Β Β Β gc.setFill(βcolorβ)β; |
| Β Β Β Β Β Β βgc.fill()β; |
| Β Β β} |
| } |
Β
ββ MyLine.java ββ
| /* βββββββββββββββββββ- |
| Class MyLine inherits class MyShape. The MyLine object is a |
| straight line defined by the endpoints (x1, y1) and (x2, y2). |
| The MyLine object may be of any color. |
| βββββββββββββββββββ- */ |
| package βsampleβ; |
| import βjavafx.scene.canvas.GraphicsContextβ; |
| import βjavafx.scene.paint.Colorβ; |
| public class βMyLine βextends βMyShape { |
| Β Β βprivate int βx1β, βy1β, βx2β, βy2β; β// Coordinates of two points of line |
| Β Β βMyLineβ(βint βx1β, int βx2β, int βy1β, int βy2β, βColor color){ |
| Β Β Β Β Β Β βsuperβ(β0β, β0β, βcolor)β; |
| Β Β Β Β Β Β thisβ.βx1 β= x1β; |
| Β Β Β Β Β Β thisβ.βx2 β= x2β; |
| Β Β Β Β Β Β thisβ.βy1 β= y1β; |
| Β Β Β Β Β Β thisβ.βy2 β= y2β; |
| Β Β β} |
| Β Β βpublic double βgetLengthβ(){ |
| Β Β Β Β Β Β βreturn βMath.βsqrtβ(Math.βpowβ(βx2β-βx1β,β2β) + Math.βpowβ(βy2β-βy1β,β2β))β; |
| Β Β β} |
| Β Β βpublic double βget_xAngleβ(){ |
| Β Β Β Β Β Β βreturn βMath.βtoDegreesβ(Math.βatanβ((βy2β-βy1β)/(βx2β-βx1β)))β; |
| Β Β β} |
| Β Β β@Override |
| Β Β βpublic βString βtoStringβ(){ |
| Β Β Β Β Β Β βreturn βString.βformatβ(ββββ Line Properties βββ\nβ%15s (%d,%d)β\nβ%15s |
| (%d,%d)β\nβ%15s %fβ\nβ%15s %fβ\nβ%15s ββ+βsuperβ.getColor()β, |
| Β Β Β Β Β Β Β Β Β Β Β Β Β Β ββPoint 1:ββ,βx1β,βy1β,ββPoint 2:ββ,βx2β,βy2β,ββLine |
| Length:ββ,βgetLength()β,ββAngle:ββ,βget_xAngle()β,ββColor:ββ)β; |
| Β Β β} |
| Β Β β@Override |
| Β Β βpublic void βdrawβ(GraphicsContext gc){ |
| Β Β Β Β Β Β gc.setStroke(βsuperβ.getColor())β; |
| Β Β Β Β Β Β βgc.strokeLine(βx1β,βy1β,βx2β,βy2β)β; |
| Β Β β} |
| } |
Β
ββ MyCircle.java ββ
| /* βββββββββββββββββββ- |
| Class MyCircle inherits class MyShape.Β The MyCircle object |
| is defined by its center (x, y) and radius r, and may be |
| filled with a color. |
| βββββββββββββββββββ- */ |
| package βsampleβ; |
| import βjavafx.scene.canvas.GraphicsContextβ; |
| import βjavafx.scene.paint.Colorβ; |
| public class βMyCircle βextends βMyShape { |
| Β Β βprivate double βradiusβ; |
| Β Β βMyCircleβ(βint βxβ, int βyβ, double βradiusβ, βColor color){ |
| Β Β Β Β Β Β βsuperβ(xβ,βyβ,βcolor)β; |
| Β Β Β Β Β Β thisβ.βradius β= radiusβ; |
| Β Β β} |
| Β Β βpublic double βgetAreaβ(){ |
| Β Β Β Β Β Β βreturn βMath.βPI β* Math.βpowβ(βradiusβ, β2β)β; |
| Β Β β} |
| Β Β βpublic double βgetPerimeterβ(){ |
| Β Β Β Β Β Β βreturn β2 β* Math.βPI β* βradiusβ; |
| Β Β β} |
| Β Β βpublic double βgetRadiusβ(){ βreturn βradiusβ; β} |
| Β Β β@Override |
| Β Β βpublic βString βtoStringβ(){ |
| Β Β Β Β Β Β βreturn βString.βformatβ(ββββ Circle Properties βββ\nβ%15s %fβ\nβ%15s |
| %fβ\nβ%15s %fβ\nβ%15s ββ+βsuperβ.getColor()β, |
| βRadius:ββ,βgetRadius()β,ββArea:ββ,βgetArea()β,ββPerimeter:ββ,βgetPerimeter()β,ββColor:ββ)β; |
| Β Β β} |
| Β Β β@Override |
| Β Β βpublic void βdrawβ(GraphicsContext gc){ |
| Β Β Β Β Β Β gc.setFill(βsuperβ.getColor())β; |
| Β Β Β Β Β Β βgc.fillOval(βsuperβ.getX() β βradiusβ, superβ.getY() β βradiusβ, β2 β* βradiusβ, β2 |
| * βradiusβ)β; |
| Β Β Β Β Β Β β//gc.strokeRect(super.getX() β radius, super.getY() β radius, 2 * |
| radius, 2 * radius); |
| Β Β β} |
| } |
Β
ββ MyPolygon.java ββ
| /* βββββββββββββββββββ- |
| Class MyPolygon inherits class MyShape. The MyPolygon object |
| is a regular polygon defined by the integer parameter, Nβ |
| the number of the polygonβs equal side lengths and equal |
| interior angles, and the center (x, y) and radius, r, of the |
| circle in which it is inscribed. The MyPolygon object may |
| be filled with a color. |
| βββββββββββββββββββ- */ |
| package βsampleβ; |
| import βjavafx.scene.canvas.GraphicsContextβ; |
| import βjavafx.scene.paint.Colorβ; |
| public class βMyPolygon βextends βMyShape { |
| Β Β βprivate double βradiusβ; |
Β
| Β Β private int βsidesβ; |
| Β Β double βxpβ[]β; |
| Β Β double βypβ[]β; |
| Β Β βMyPolygonβ(βint βxβ, int βyβ, double βradiusβ, int βsidesβ, βColor color){ |
| Β Β Β Β Β Β βsuperβ(xβ,βyβ,βcolor)β; |
| Β Β Β Β Β Β thisβ.βradius β= radiusβ; |
| Β Β Β Β Β Β thisβ.βsides β= sidesβ; |
| Β Β Β Β Β Β βxp β= βnew doubleβ[sides]β; |
| Β Β Β Β Β Β βyp β= βnew doubleβ[sides]β; |
| Β Β Β Β Β Β double βang = (β2 β* Math.βPIβ)/sidesβ; |
| Β Β Β Β Β Β for β(βint βi = β0β; βi < sidesβ; β++i){ |
| Β Β Β Β Β Β Β Β Β Β βxpβ[i] = x + (radius*(-β1 β* Math.βsinβ(i*ang)))β; |
| Β Β Β Β Β Β Β Β Β Β βypβ[i] = y + (radius*(-β1 β* Math.βcosβ(i*ang)))β; |
| Β Β Β Β Β Β β} |
| Β Β } |
| Β Β βpublic double βgetRadiusβ(){ βreturn βradiusβ; β} |
| Β Β βpublic double βgetAreaβ(){ |
| Β Β Β Β Β Β βreturn βMath.βpowβ(βradiusβ,β2β) * βsides β* Math.βsinβ(getAngle()) * β0.5β; |
| Β Β β} |
| Β Β βpublic double βgetPerimeterβ(){ βreturn βsides β* getSide()β; β} |
| Β Β βpublic double βgetApothemβ(){ βreturn βradius β* Math.βcosβ(Math.βtoRadiansβ(β180 β/ |
| sidesβ))β; β} |
| Β Β βpublic double βgetAngleβ(){ βreturn βMath.βPIβ/βsidesβ; β} |
| Β Β βpublic double βgetSideβ(){ βreturn β2 β* βradius β* Math.βsinβ(Math.βPIβ/βsidesβ)β; β} |
| Β Β β@Override |
| Β Β βpublic βString βtoStringβ(){ |
| Β Β Β Β Β Β βreturn βString.βformatβ(ββββ Polygon Properties βββ\nβ%15s %fβ\nβ%15s |
| %fβ\nβ%15s %fβ\nβ%15s %fβ\nβ%15s %fβ\nβ%15s ββ+βsuperβ.getColor()β, |
| βRadius:ββ,βgetRadius()β,ββArea:ββ,βgetArea()β,ββPerimeter:ββ,βgetPerimeter()β, |
| Β Β Β Β Β Β Β Β Β Β Β Β Β Β ββAngle:ββ,βgetAngle()β,ββApothem:ββ,βgetApothem()β,ββColor:ββ)β; |
| Β Β β} |
| Β Β β@Override |
| Β Β βpublic void βdrawβ(GraphicsContext gc){ |
| Β Β Β Β Β Β gc.setFill(βsuperβ.getColor())β; |
| Β Β Β Β Β Β βgc.setStroke(βsuperβ.getColor())β; |
| Β Β Β Β Β Β βgc.setLineWidth(β3β)β; |
| Β Β Β Β Β Β βgc.strokePolygon(βxpβ, βypβ, βsidesβ)β; |
| Β Β Β Β Β Β βgc.fillPolygon(βxpβ, βypβ, βsidesβ)β; |
| Β Β β} |
| Β Β βpublic void βborderβ(GraphicsContext gc){ |
| Β Β Β Β Β Β gc.setStroke(Color.βBLACKβ)β; |
| Β Β Β Β Β Β for β(βint βi = β1β; βi < βsidesβ; β++i){ |
| Β Β Β Β Β Β Β Β Β Β gc.strokeLine(βxpβ[i-β1β]β, βypβ[i-β1β]β, βxpβ[i]β, βypβ[i])β; |
| Β Β Β Β Β Β β} |
| Β Β Β Β Β Β gc.strokeLine(βxpβ[βsidesβ-β1β]β, βypβ[βsidesβ-β1β]β, βxpβ[β0β]β, βypβ[β0β])β; |
| Β Β β} |
| } |
Β
ββ Main.java ββ
| /* Ashraq Khan // CS 22100 Assignment 1 // 09/21/2020 */ |
| package βsampleβ; |
| /* Imports */ |
| import βjavafx.application.Applicationβ; |
| import βjavafx.scene.Sceneβ; |
| import βjavafx.scene.canvas.Canvasβ; |
| import βjavafx.scene.canvas.GraphicsContextβ; |
| import βjavafx.scene.layout.StackPaneβ; |
| import βjavafx.stage.Stageβ; |
| /* Driver class */ |
| public class βMain βextends βApplication { |
| Β Β β// Sets boundaries of stage |
| Β Β βfinal int βWIDTH β= β1000β; |
| Β Β final int βHEIGHT β= β600β; |
| Β Β β@Override |
| Β Β βpublic void βstartβ(Stage primaryStage) { |
| Β Β Β Β Β Β βtry β{ |
| Β Β Β Β Β Β Β Β Β Β β// Sets up primary stage, canvas, and graphics context |
| Β Β Β Β Β Β Β Β Β Β βprimaryStage.setTitle(ββAssignment 1β³β)β; |
| Β Β Β Β Β Β Β Β Β Β βCanvas canvas = βnew βCanvas(βWIDTHβ, βHEIGHTβ)β; |
| Β Β Β Β Β Β Β Β Β Β βGraphicsContext gc = canvas.getGraphicsContext2D()β; |
| Β Β Β Β Β Β Β Β Β Β βgc.setLineWidth(β3β)β; |
| Β Β Β Β Β Β Β Β Β Β β// Prints alternate hexagons and circles of different colors |
| Β Β Β Β Β Β Β Β Β Β βMyPolygon hexGray = βnew βMyPolygon(βWIDTHβ/β2β,βHEIGHTβ/β2β, |
| 200β,β6β,βMyColor.βGREYβ.getCol())β; |
| Β Β Β Β Β Β Β Β Β Β βhexGray.draw(gc)β; |
| Β Β Β Β Β Β Β Β Β Β βMyCircle circleY = βnew βMyCircle(βWIDTHβ/β2β,βHEIGHTβ/β2β, |
| hexGray.getApothem()β, βMyColor.βYELLOWβ.getCol())β; |
| Β Β Β Β Β Β Β Β Β Β βcircleY.draw(gc)β; |
| Β Β Β Β Β Β Β Β Β Β βMyPolygon hexGreen = βnew βMyPolygon(βWIDTHβ/β2β,βHEIGHTβ/β2β, |
| circleY.getRadius()β, β6β,βMyColor.βLIMEβ.getCol())β; |
| Β Β Β Β Β Β Β Β Β Β βhexGreen.draw(gc)β; |
| Β Β Β Β Β Β Β Β Β Β βMyCircle circleP = βnew βMyCircle(βWIDTHβ/β2β,βHEIGHTβ/β2β, |
| hexGreen.getApothem()β, βMyColor.βHOTPINKβ.getCol())β; |
| Β Β Β Β Β Β Β Β Β Β βcircleP.draw(gc)β; |
| Β Β Β Β Β Β Β Β Β Β βMyPolygon hexBlue = βnew βMyPolygon(βWIDTHβ/β2β,βHEIGHTβ/β2β, |
| circleP.getRadius()β,β6β,βMyColor.βCYANβ.getCol())β; |
| Β Β Β Β Β Β Β Β Β Β βhexBlue.draw(gc)β; |
| Β Β Β Β Β Β Β Β Β Β βhexGray.border(gc)β; |
| Β Β Β Β Β Β Β Β Β Β β// Lists properties of all shapes |
| Β Β Β Β Β Β Β Β Β Β βSystem.βoutβ.println(hexGray + βββ\n\nββ β+ circleY + βββ\n\nββ β+ hexGreen + |
| ββ\n\nββ β+ circleP + βββ\n\nββ β+ hexBlue + βββ\n\nβββ)β; |
| Β Β Β Β Β Β Β Β Β Β βMyLine line1 = βnew βMyLine(β0β,βWIDTHβ,β0β,βHEIGHTβ,βMyColor.βBLACKβ.getCol())β; |
| Β Β Β Β Β Β Β Β Β Β βMyLine line2 = βnew βMyLine(β0β,βWIDTHβ,βHEIGHTβ,β0β,βMyColor.βBLACKβ.getCol())β; |
| Β Β Β Β Β Β Β Β Β Β βline1.draw(gc)β; |
| Β Β Β Β Β Β Β Β Β Β βline2.draw(gc)β; |
| Β Β Β Β Β Β Β Β Β Β βgc.strokeRect(β0β, β0β, βWIDTHβ, βHEIGHTβ)β; |
| Β Β Β Β Β Β Β Β Β Β β// Lists properties of all lines |
| Β Β Β Β Β Β Β Β Β Β βSystem.βoutβ.println(line1 + βββ\n\nββ β+ line2 + βββ\n\nβββ)β; |
| Β Β Β Β Β Β Β Β Β Β β// Sets stack pane and scene for image to appear on |
| Β Β Β Β Β Β Β Β Β Β βStackPane root = βnew βStackPane(canvas)β; |
| Β Β Β Β Β Β Β Β Β Β βScene scene = βnew βScene(rootβ,βWIDTHβ,βHEIGHTβ)β; |
| Β Β Β Β Β Β Β Β Β Β βprimaryStage.setScene(scene)β; |
| Β Β Β Β Β Β Β Β Β Β βprimaryStage.show()β; |
| Β Β Β Β Β Β β} βcatchβ(Exception e) { |
| Β Β Β Β Β Β Β Β Β Β e.printStackTrace()β; |
| Β Β Β Β Β Β β} |
| Β Β } |
| Β Β βpublic static void βmainβ(String[] args) { |
| Β Β Β Β Β Β βlaunchβ(args)β; |
| Β Β β} |
| } |
Β
ββ MyColor.java ββ
| /* βββββββββββββββββββ- |
| Enum MyColor sets up pre-made colors of varying RGB values |
| and opacities. These will be used to color shapes and lines. |
| βββββββββββββββββββ- */ |
| package βsampleβ; |
| import βjavafx.scene.paint.Colorβ; |
| public enum βMyColor{ |
| Β Β βREDβ(β255β,β0β,β0β,β255β)β, βBLUEβ(β0β,β0β,β255β,β255β)β, |
| Β Β βLIMEβ(β0β,β255β,β0β,β255β)β, βCYANβ(β0β,β255β,β255β,β255β)β, |
| Β Β βGREENβ(β0β,β128β,β0β,β255β)β, βGREYβ(β128β,β128β,β128β,β255β)β, |
| Β Β βMAGENTAβ(β255β,β0β,β255β,β255β)β, βPURPLEβ(β128β,β0β,β128β,β255β)β, |
| Β Β βVIOLETβ(β148β,β0β,β211β,β255β)β, βYELLOWβ(β255β,β255β,β0β,β255β)β, |
| Β Β βWHITEβ(β255β,β255β,β255β,β255β)β, βBLACKβ(β0β,β0β,β0β,β255β)β, |
| Β Β βHOTPINKβ(β255β,β105β,β180β,β255β)β; |
| Β Β private int βrβ,βgβ,βbβ,βaβ; β// Value for red, green, blue, and opacity |
| Β Β βMyColorβ(βint βrβ, int βgβ, int βbβ, int βa){ βthisβ.βr β= rβ; thisβ.βg β= gβ; thisβ.βb β= bβ; |
| thisβ.βa β= aβ; β} |
| Β Β βpublic βColor βgetColβ() { βreturn βColor.βrgbβ(βrβ, βgβ, βbβ, β(βdoubleβ)(βaβ/β255β))β; β} |
| } |
Β
Β
[4] Outputs Produced
Β



