Part 1

Design a Java applet for drawing the spiral for a given winding number (that is, the number of full rotations) defined by the user. The equations defining a single rotation of the spiral are the following:

x = t·cos(2πt)
y = t·sin(2πt)

as t varies from 0 to 1. Here π = 3.14159... is the constant Math.PI. The applet should draw the spiral as soon as the user clicks the button and enters the winding number in the opened dialog box (must be a positive integer number).

Be sure to start the drawing of the spiral in the center of the yellowish area and scale the spiral by multiplying x and y by an appropriate value (depending on the number of full rotations) so that the spiral occupies the entire area of the panel.

Hint: Divide the range of t, that is the interval [0, 1], with N points ti into equal parts (N should be choosen appropriately), compute the values of xi and yi at each point ti by using the above formulas, and draw the line segments between points (xi-1, yi-1) and (xi, yi) for i=1,2,...,N. For two rotations, t has to vary from 0 to 2, and so on. In this case you will need 2N subdivision points, N per rotation, to make the spiral smoother. Set the applet size 300x330 pixels.

Part 2

Design a Java application that takes two strings passed as the command line parameters: a text string T (as the first parameter) and a query string Q (as the second parameter). The program should find all occurrences of the query string Q as a substring in the text string T and mark them by symbols "^".

For example if T="abcrdabcaabc" and Q="abc" then there are 3 occurrences of Q in T schematically shown below:

abcrdabcaabc
abc         
     abc    
         abc

In this case your program started from the command line as

java Ex2_2 abcrdabcaabc abc

should produce the following output:

abcrdabcaabc
^    ^   ^

Make sure that your program works for any nonempty strings T and Q, not just for the above example!

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.