Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Programming Problem 2 – Characters Around a Circle Write a program that displays

ID: 3918066 • Letter: P

Question

Programming Problem 2 – Characters Around a Circle Write a program that displays a string “Welcome to Java” around the circle, as shown below. You need to display each character in the right location with appropriate rotation using a loop. Directions Create a class named Characters extends Application. Create a new pane. Create an object of Font class and define font features as bold, Times New Roman, regular and size of 35. Create a string of “Welcome to Java” Create a for loop to scan through each character of “Welcome to Java” string. Inside the for loop, create an instance of Text on the given coordinates containing the given characters by use constructor of Text(double x, double y, java.lang.String text) Use setFont( ) and setRotate( ) methods of Text class to define characters and their rotated positions Add text instance to the pane by using getChildren().add() method Create a scene with a specific size Set title to “Characters around circle” and display the stage The output should look like the screen below. Provide appropriate Java comments

Explanation / Answer

import javafx.application.Application;

import javafx.geometry.Point2D;

import javafx.scene.Scene;

import javafx.scene.layout.Pane;

import javafx.scene.text.Font;

import javafx.scene.text.FontWeight;

import javafx.scene.text.Text;

import javafx.stage.Stage;

/**

* A Java program that displays a string welcome to java around

*the circle. you need to display

*each character in the location with appropriate

*rotation using a loop.

*/

public class Ex35 extends Application{

@override

public void start(Stage primaryStage){

Pane pane=new Pane();

String[] java="My name is XXXXX".split("");

Font font=Font.font("Times New Roman",FontWeight.EXTRA_BOLD,30);

Point2D center=new Point2D(200,200);

double radius=100;

double angle=0;

double rotate=90;

for(int i=0; i<java.length; i++,angle+=22,rotate+=22){

double x=center.getX()+radius*Math.cos(Math.toRadians(angle));

double y=center.getY()+radius*Math.sin(Math.toRadians(angle));

Text text=new Text(x,y,java[i]);

text.setRotate(rotate);

text.setFont(font);

pane.getChildren().add(text);

}

Scene scene=new Scene(pane,400,400);

primaryStage.setTitle("My name is XXXXX");

primaryStage.setScene(scene);

primaryStage.show();

}

public static void main(String[] args){

Application.launch(args);

}

}