Question: Draw a UML class diagram. Here is the code to write the class TestSnowman.Java public class TestSnowMan { //main() method. public static void main(String[] args)

Draw a UML class diagram. Here is the code to write the class

TestSnowman.Java

public class TestSnowMan

{

//main() method.

public static void main(String[] args)

{

//Call the Snowman()

Snowman sn = new Snowman();

}

}

Snowman.java

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.util.Scanner;

public class Snowman extends JFrame

{

//Declare the variables.

int x, y;

//Snowman() constructor

public Snowman()

{

//Title of the canvas.

super("I am Snowman");

//Create an object of the Scanner class

Scanner sc = new Scanner(System.in);

//Prompt the user to enter the x-coordinates.

System.out.print("Enter the x co-ordinates: ");

x = sc.nextInt();

//Prompt the user to enter the y-coordinates.

System.out.print("Enter the y co-ordinates: ");

y = sc.nextInt();

//Set size of the canvas.

setSize(1024, 1024);

//Make the canvas visible.

setVisible(true);

}

//calPaint() method to call the Paint() method

public void callPaint(Graphics g)

{

//Call the Paint() method.

paint(g);

}

//Paint() method to draw the snow man.

public void paint(Graphics g)

{

//Create an object of the Graphics2D class.

Graphics2D g2D = (Graphics2D) g;

//Set the width of the drawing pen.

g2D.setStroke(new BasicStroke(3));

//Background color.

g2D.setColor(Color.WHITE);

//Make a rectangle.

g2D.fillRect(0, 0, 1024, 768);

// Top Oval(Face)

g2D.setColor(Color.BLACK);

g2D.drawOval(x + 25, y - 80, 100 - 20, 100 - 20);

// Middle oval

g2D.setColor(Color.BLACK);

g2D.drawOval(x, y, 125, 125);

// Bottom oval

g2D.setColor(Color.BLACK);

g2D.drawOval(x - 10, y + 124, 125 + 20,

100 + 20);

// Buttons

g2D.setColor(Color.GREEN);

g2D.fillRect(x + 62, y + 20, 5, 5);

g2D.fillRect(x + 62, y + 35, 5, 5);

g2D.fillRect(x + 62, y + 50, 5, 5);

g2D.fillRect(x + 62, y + 65, 5, 5);

// Right hand

g2D.setColor(Color.BLACK);

g2D.drawLine(x + 5, y + 35, x - 100, y + 125);

g2D.drawLine(x - 70, y + 101, x - 120, y + 100);

g2D.drawLine(x - 83, y + 110, x - 64, y + 130);

// Left hand

g2D.drawLine(x + 120, y + 35, x + 205, y + 125);

g2D.drawLine(x + 180, y + 101, x + 235, y + 100);

g2D.drawLine(x + 190, y + 110, x + 180, y + 140);

// Scarf

int x3[] = { x + 10, x + 20, x + 105, x + 115 };

int y3[] = { y + 20, y + 5, y + 5, y + 20 };

g2D.setColor(Color.GREEN);

g2D.fillPolygon(x3, y3, 4);

String messag2De = "Frosty";

g2D.setColor(Color.BLACK);

g2D.drawString(messag2De, x + 30, y + 18);

//Scarf hanging.

int x4[] = { x + 115, x + 105, x + 200, x + 150 };

int y4[] = { y + 20, y + 5, y + 80, y + 70 };

g2D.setColor(Color.GREEN);

g2D.fillPolygon(x4, y4, 4);

// Eyes

g2D.setColor(Color.BLACK);

g2D.fillOval(x + 40, y - 40, 10, 10);

g2D.fillOval(x + 80, y - 40, 10, 10);

// Nose

int x1[] = { x + 65, x + 70, x + 40 };

int y1[] = { y - 35, y - 20, y };

g2D.setColor(Color.RED);

g2D.fillPolygon(x1, y1, 3);

// Mouth

g2D.setColor(Color.RED);

g2D.drawArc(x + 50, y - 33, 30, 30, 3, -150);

// Hat

int x2[] = { x + 20, x + 20, x + 30, x + 30,

x + 100, x + 100, x + 110, x + 110 };

int y2[] = { y - 50, y - 60, y - 60, y - 120,

y - 120, y - 60, y - 60, y - 50 };

g2D.setColor(Color.BLACK);

g2D.fillPolygon(x2, y2, 8);

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!