Reference no: EM133959002
Introduction to Computer Science
Question 1. The following assignment question refers to "10.5 Case Study: Designing the Course Class" in your textbook.
Revise the methods, draw the UML diagram and write a test program that tests all the revised and added methods and displays the students in the course after each test as described in the programming exercise 10.9.
** 10.9 (The Course class) Revise the Course class as follows:
Revise the getStudents ( ) method to return an array whose length is the same as the number of students in the course. (Hint: create a new array and copy students to it.)
The array size is fixed in Listing 10.6. Revise the addStudent method to automatically increase the array size if there is no room to add more students. This is done by creating a new larger array and copying the contents of the current army to it.
Implement the dropStudent method.
Add a new method named cl ear ( ) that removes all students from the course.
Write a test program that creates a course, adds three students, removes one, and displays the students in the course.
Question 2. Define the MyRectangle2D class that contains the following data fields and methods, draw the UML diagram for the class then implement the class. Write a test program that creates a MyRectangle2D object rl and do all the activities as described in the programming exercise
10.13.
* 10.1 3 (Geometry: the MyRec t angle2D class) Define the MyRect angl e2D class that contains:
Two doubt e data fields named x and y that specify the center of the rectangle with getter and setter methods. (Assume the rectangle sides are parallel to x- or y-axis.)
The data fields width and height with getter and setter methods.
A no-arg constructor that creates a default rectangle with (0, 0) for (x. y) and 1 for both width and height.
A constructor that creates a rectangle with the specified x. y. width, and height.
A method getArea ( ) that returns the area of the rectangle.
A method getPeri meter ( ) that returns the perimeter of the rectangle.
A method contai ns (doubl e x. double y) that returns true if the specified point (x, y) is inside this rectangle (see Figure 10.24a).
A method contai ns (MyRectangl e2D r) that returns t rue if the specified rectangle is inside this rectangle (see Figure 10.246).
A method overlaps (MyRectangl r) that returns t rue if the specified rectangle overlaps with this rectangle (see Figure 10.24c).
10.2 1 (Divisible by 5 or 6) Find the first It) numbers greater than Long . MAX_VALUE that are divisible by 5 or 6.
(a) (b) (c) (d)

FIGURE 10.24 A point is inside the rectangle. (b) A rectangle is inside another rectangle. (c) A rectangle overlaps another rectangle. (d) Points are enclosed inside a rectangle. Get AI-free online assignment help from experienced academic experts.
Draw the UML diagram for the class then implement the class. Write a test program that creates a MyRectangle2D object r1 (now MyRectangle2D (2. 2. 5.5 , 4 . 9 ) ), displays its area and perimeter. and displays the result of r1. contai ns (3 , 3), r1 contai ns (new MyRectangle2D(4 , 5, 10 .5, 3 .2) hand rl .overlaps (now MyRectangl e2D (3 , 5, 2.3, 5.4) ).
Question 3. Write a Java program as described in the programming exercise 10.21. Hint: Use BigIntemr class.
10.2 1 (Divisible by 5 or 6) Find the first It) numbers greater than Long . MAX_VALUE that are divisible by 5 or 6.