# Data Structures and Programming, Java Final Exam solution

1.   A (5 points)  Write a Java program that:à        Asks for an integer value n; à        Then asks for n number(s) from the user; à        Finally displays the average of all the numbers typed in by the user.        B (5 points)  Write a program segment in Java that sets the value of “int Number1” randomly from the following set:   {2, 4, 6, 20, 22}.        C (5 points)  Write a method Power(base, exponent) that returns the value of        (Assume that base is a positive, non-zero double and exponent is a double.)

6.   A (10 points) Write a program that creates a queue of integers.  After that it loads in 20 random integers between 1 and 6, and after the 20th number it prints out the content of the queue.  Finally, the program calculates and prints out the average of the values without losing the values from the queue!   (For the queue structure, consider Chapter 21, Data Structures.)   7. A (10 points) Create a class of Circle with attributes radius, X and Y that represent the Cartesian coordinates of the center point. Radius default value is 1, it must be positive for every circle.  Provide a member method Cross that returns true if two circles cross each other.  Otherwise it returns false.  Cross has a Circle object input parameter.