CMSC 131 (Loops/Arrays/Classes) =============================== 1. Write a for loop and a while loop that print the even numbers from 0 up to (including ) an specified maximum value. 2. Write a do while that computes the sum of the square roots from 1 up to a specified maximum value. 3. Write a nested while loop pair that generates the following triangular set of * for a particular number of rows. For example, for five rows we will have: * ** *** **** ****** 4. Write a nested do while pair that generates the multiplication table for an specified maximum value. For example, for a value of 3 we will have: 0 0 0 0 0 1 2 3 0 2 4 6 0 3 6 9 You can assume the table will have a minimum size of one row and one column. 5. Write a piece of code that computes the factorial. The definition of N factorial is: N! -> N * (N - 1)! 6. Write a piece of code that determines whether two arrays of doubles have the same elements. For example, given the following arrays: int[] a = {1.0, 4.5, 8.9, 10.0}; int[] b = {4.5, 1.0, 10.0, 8.9}; int[] c = {1.0, 4.5}; we can see that a and b are the only arrays that have the same elements. 7. Write a piece of code that determines whether the elements of an array are contained in a second array. For example, given the following two arrays: int[] a = {10, 20}; int[] b = {5, 7, 20, 3, 10}; we can see that all the elements of a are present in b. 8. Write a piece of code that appends the contents of one array to to the end of another. A new array (with a length corresponding to sum of the lengths of the originals arrays) should be created. 9. Write a piece of code that given an array creates a new array where each element with index k corresponds to the sum of elements from the original array starting at index 0 up to index k. For example, given the following array: int[] a = {10, 4, 12, 6}; the new array will have the elements: {10, 14, 26, 32} 10. Write a Java class named RandomValuesArray that satisfies the following specifications: a. A constructor with the signature: RandomValuesArray(int maxElements, int maxRandomValue) which creates an array of size maxElements and initializes it with random values from 0 up to (including) maxRandomValue. b. Define the necessary instance variables associated with the class. c. A public method called reInitialized which updates the set of random values in the array. d. A public method toString that allow us to print the contents of the array. e. A public method getMaximum returning the maximum value in the array. f. A public method getNumberEven returning the number of even values in the array. g. A main method that creates an instance of the RandomValuesArray class and uses the methods defined above. 11. Write a Java class named Student that allow us to manipulate a student's record. The following are the specifications associated with the class: a. A constructor with the signature: Student(String theName, double[] theScores) which keeps track of a set of scores passed in. b. Define the necessary instance variables associated with the class. c. A public method called getNumeric grade that returns the numeric grade associated with the student. d. A public method called getLetterGrade with the following signature: char getLetterGrade(double[] theCutoffs) The method will return a letter grade based on the cutoffs provided. For example, the cutoffs array could have the following values: 90, 80, 70, 60 Based on this values a numeric grade of 92 will return an A. e. An appropriate toString() method for the class. f. A main method that creates an instance of the Student class and uses the methods defined above. 12. For this exercise you will use the Student class you previously developed. Write a class named Section representing a college course section. The specifications associated with the class are: a. A constructor with the signature: public Section(String theCourseName, int theMaxSize) which will create an array of Student objects. b. Define the necessary instance variables associated with the class. c. A method called addStudent which will add a Student object to the next available entry in the array. The signature of the method will be: public void addStudent(Student theStudent) d. A method called removeStudent that will remove a Student object by setting the array entry corresponding to the student to null. e. The appropriate toString() for the class. 13. Design Problem In the above exercises there were references to a Section and Student class. For this problem we want you to think about the set of classes necessary to fully implement a registration system. The following issues must be taken into account: a. A school has several sections for a course. b. Each section has a professor assigned to it. c. The school has several courses. d. A professor can teach different courses and different sections of a course. e. A student can be registered in different courses at the same time. f. A course can have one or more TAs assigned to it. g. Each section must be assigned a room. h. Students add and drop courses and change sections. i. Students must be billed for the course they are taking. Come up with a design (by defining the necessary classes) that allow us to deal with the specifications provided above. Feel free to add any data members and methods you think are necessary. Make sure you specify any assumptions you make in your design. Remember, you don't need to implement the code; just specify which classes are needed, which methods each class should have, and the data members associated with each class.