Question: All in java please! Q1: Display three distinct random cards (textbook Q14.3) Write a program that displays three cards randomly selected from a deck of

All in java please!

Q1: Display three distinct random cards (textbook Q14.3)

Write a program that displays three cards randomly selected from a deck of 52, as shown below.

The card image files are named 1.png, 2.png, . . . , 52.png and stored in the image/card directory. All three cards are distinct and selected randomly.

HINT: You can select random cards by storing the numbers 152 to an array list, perform a random shuffle introduced in textbook Section 11.12 or use Collections.shuffle(), and use the first three numbers in the array list as the file names for the image.

Q2: Display a string around a circle (textbook Q14.5)

Write a program that displays a string Welcome to Java around a circle, as shown below.

HINT: You need to display each character as a text object in the right location with appropriate rotation using a loop, add a blank space to separate the head and tail. Set a font for the text object.

In Java, the trigonometric functions like sin, cos, their parameter is an angle in radians, following normal mathematical convention, i.e, positive angle runs anticlockwise while negative angle runs clockwise. So, to distribute n characters evenly around a circle clockwise, negative angles are convenient. If we start the text at the left side of the circle with radius , then the coordinates of the location of a character with angle away from west can be calculated as below:

Character Location coordinates
=0+cos() =0sin()

By default, the origin or location of a character is its bottom-left corner.

To distribute character around a circle, then the angle between two consecutive characters is 2, counting clockwise from the west character (the 0-th character), the angle of the i-th character from west would be 2, so its angle for calculation is 2, its coordinates are

=0+cos(2)
=0sin(2)

After distributing the characters around a circle, it looks like below

Next we need to rotate each character to stand on the circle by calling its setRotate(double angle) method. However, here the angle is in degree, positive angle rotate clockwise while negative angle rotate counterclockwise which is contrary to mathematical convention. The first character needs to be rotated 90 degree counterclockwise, i.e. rotate 90 degree, the next character needs to be rotated 90+360, the i-th character needs to be rotated 90+360. After all characters are rotated, we get an acceptable layout as required shown at the beginning.

However, there is a subtle defect, if we show the circle, the defect becomes clear as below

If we don't rotate characters, it looks like

The defect comes from:

The location of a character is its bottom-left corner

The rotation pivot point is the center of the character

Extra credits

10% Extra credits are given for fixing the defect:

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!