Write a method called average that accepts two integer parameters and returns their average as a floating point value. Ans


Write a method called drawCircle that draws a circle based on



Download 18.11 Kb.
Page3/5
Date16.12.2020
Size18.11 Kb.
#54714
1   2   3   4   5
7 short questions
7 short questions, 4 (2)
Write a method called drawCircle that draws a circle based on

the method’s parameters: a Graphics object through which to

draw the circle, two integer values representing the (x, y) coordinates

of the center of the circle, another integer that represents

the circle’s radius, and a Color object that defines the circle’s

color. The method does not return anything

Ans

public void drawCircle (Graphics page, int x, int y,

int radius, Color shade)

{

page.setColor (shade);



page.drawOval (x-radius, y-radius, radius*2,

radius*2);

}

EX 7.7 Overload the drawCircle method of Exercise 7.6 such that if the

Color parameter is not provided, the circle’s color will default to

black.

Ans

public void drawCircle (Graphics page, int x, int y,

int radius)

{

page.setColor (Color.black);



page.drawOval (x-radius, y-radius, radius*2,

radius*2);

}


Download 18.11 Kb.

Share with your friends:
1   2   3   4   5




The database is protected by copyright ©ininet.org 2024
send message

    Main page