1.  (The MyDateTime class)Design a class named MyDateTime . The class contains :

·  Data fields year ,month ,date,hour, minute and second that represents a date and time

·  A no –arg constructor that creates MyDateTime object for the current time

·  A constructor that construct a MyDateTime object with the specified year ,month, date, hour, minute and second .

·  A constructor that construct a MyDateTime object with the specified elapsed timesince midnight, Jan 1 1970,in millisecond .(The data fields value will represents this time .)

·  The get and set methods for all the data fields .

Write a test program that creates to MyDateTime objects (new MyDateTime() and new MyDateTime(555550000))and display their year,month ,date,minute , second .

2.  (The BMI class)Add the following new constructor in the BMI class :

/** construct a BMI with the specified name , age , weight ,feet and inches */

Public BMI (String name, int age , double weight , int feet, int inches )

//KILOGRAMS_PER_POUND=0.45359237;

// METERS_PER_INCH=0.0254;

Formulae for BMI calculation:

Weight * KILOGRAMS_PER_POUND

((height * METERS_PER_INCH)*(height * METERS_PER_INCH))

If bmi<16 print seriously underweight

If bmi<18 print underweight

If bmi<24 print normal weight

If bmi<29 print overweight

If bmi<35 print seriously overweight

3.  (The MyDouble class) Design a class named MyDouble .The class contains :

·  A double data field named value that stores the double values represented by this object.

·  A constructor that creates a MyDouble object for the specied double value .

·  Methods intValue(), doubleValue() that return the int value and double value of this object.

·  Static methods parseDouble(String, int radix ) that parses a string into double value with the specified radix .For example, parseDouble(“5.45”, 10)returns 5.45 . parseDouble(“5.45 ”, 16)returns ???

·  Methods equals (double)and equals (MyDouble) that returns true if the value in the object is equal to the specified value .

Implement the class . write a client program that test all methods in the class

4.  (The MyPoint class) Design a class named MyPoint to represent a point with x-and y-coordinates. The class contains :

·  Two data fields x and y that represents coordinates with get methods .

·  A no-arg constructor that creates a point (0, 0)

·  A constructor that constructs a point with specified coordinates

·  Two get methods for data fields x and y respectively

·  A method named distance that returns the distance from this point to another point of MyPoint type .

·  A method named distance that returns the distance from this point to another point with specified x and y –coordinates.

Implements the class . Write a test program that creats to points(0,0) and (10, 30.5) and display the distance between them.

5.  (The QueueOfIntegers class)A stack is a data structure that holds objects in a last-in first-out fashion .A queue is a data structure that holds objects in a first-in first-out fashion . Design a queue class for integers , named QueueOfIntegers, with the following features:

·  A private data field of type int[] to store data in queue.

·  A method named dequeue() to retrieve and remove the first elment from the queue .

·  A method named enqueue (int) to add the element to the queue.

Draw the UML diagram for the class .Implement the class . Write a client program that tests all methods in the class.

6.  (Geometry: The Circle2D class )Define the Circle2D class that contains :

·  Two double data fields named x and ythat specify the center of the circle with get methods.

·  A data fields radius with a get method.

·  A no-arg constructor that creates a default circle with the (0,0) for (x,y)and 1 for radius .

·  A constructor that creates a circle with the specified x, y and radius .

·  A method getArea () that returns the area of the circle.

·  A method getPerimeter() that returns the perimeter of the circle.

·  A method contains(double x,double y)that returns true if the specified point(x,y)is inside this circle.

·  A method contains(Circle2D circle)that returns true if the specified circle is inside this circle.

·  A method overlaps(Circle2D circle)that returns true if the specified circle overlaps with this circle.

(a)  (b) (c)

(a)-A point is inside the circle.(b)-A circle is inside another circle.(c)-A circle overlaps another circle.

Implement the class. Write a test program that creates a Circle2D object c1(new Circle2D(2,2,5.5)),display its area & perimeter & displays the result of c1.contains(3,3),c1.contains(new Circle2D(4,5,10.5)),and c1.overlaps(new Circle2D(3,5,2.3)).

7-(The Person and Student classes ).Design the Student class that extends Person which implements an interface called Comparable. Implement the compareTo method in the Person class to compare persons in alphabetical order of their last name. Implement the compareTo method to compare students in alphabetical order of their major and last name. WAP with the following four methods

·  public static void sort(Comparable[] list)

·  public static void printList(Object[] object)

·  public static Comparable max(Comparable[] list)

·  main method :Test the sort, printList, and max methods using an array of four students.

8-(Displaying the prime numbers)Write a program that displays all the prime prime numbers less than 120 in decreasing order.Use the StackOfIntegers class to store the prime numbers and retrieve and display them in reverse order.

9-(Geometry: The Rectangle2D class )Define the Rectangle2D class that contains :

·  Two double data fields named x and ythat specify the center of the Rectangle with get & set methods.

·  A data fields Width & height with a get & set methods.

·  A no-arg constructor that creates a default rectangle with the (0,0) for (x,y)and 1 for both width & height .

·  A constructor that creates a rectangle with the specified x, y and radius .

·  A method getArea () that returns the area of the rectangle.

·  A method getPerimeter() that returns the perimeter of the rectangle.

·  A method contains(double x,double y)that returns true if the specified point(x,y)is inside this rectangle.

·  A method contains(Rectangle 2D r)that returns true if the specified rectangle is inside this rectangle.

·  A method overlaps(Rectangle 2D r)that returns true if the specified rectangle overlaps with this rectangle.

(a) (b) ` (c)

(a)-A point is inside the rectangle.(b)-A rectangle is inside another rectangle.(c)-A rectangle overlaps another rectangle..

Implement the class .Write a test program that creates a Rectangle2D object r1(new Rectangle2D(2,2,5.5,4.9)),display its area & perimeter & displays the result of r1.contains(3,3),

r1.contains( new Rectangle2D(4,5,10.5,3.2)),and r1.overlaps(new Rectangle2D(3,5,2.3,5.4)).

10-(Geometry: The Triangle2D class ) Define the Triangle2D class that contains :

·  Three points named p1,p2 and p3 with the type MyPoint with get and set methods.

·  A no-arg constructor that creates a default triangle with the points (0,0) ,(1,1)and (2,5).

·  A constructor that creates a triangle with the specified points .

·  A method getArea () that returns the area of the triangle.

·  A method getPerimeter() that returns the perimeter of the triangle.

·  A method contains(MyPoint p)that returns true if the specified point p is inside this triangle.

·  A method contains(Triangle 2D t)that returns true if the specified triangle is inside this triangle.

·  A method overlaps(Triangle 2D t)that returns true if the specified triangle overlaps with this triangle

(a)-A point is inside the triangle.(b)-A triangle is inside another triangle.(c)-A triangle overlaps another triangle.

Implement the class .Write a test program that creates a Triangle2D object t1(new Triangle2D(newMypoint(2.5,2),newMypoint(4.2,3),new MyPoint(5,3.5))),display its area & perimeter & displays the result of t1.contains(3,3),r1.contains(new Triangle2D(newMypoint(2.9,2),newMyPoint(4,1),MyPoint(1,3.4))), and t1.overlaps(new Triangle2D(newMypoint(2,5.5),newMyPoint(4,-3),MyPoint(2,6.5)))

11-(Extending MYPoint),the MyPoint class was created to model a point in a two-dimensional space.

The MyPont class has the properties x and y that represents x- and y-coordinates,two get methods for x and y,and the methoed for returning the distance between two points. Create a class named ThreeDPoint to model a point in a three dimensional space. Let ThreeDPoint be derived from MyPoint with the following additional features:

·  A data field named z that represents the z-coordinate.

·  A no-arg constructor that constructs a point with coordinate(0,0,0).

·  A constructor that constructs a point with three specified coordinates.

·  A get method that returns the z value.

·  Override the distance method to return the distance between two points in the three dimensional space.

Implement the classes. Write a test program that creates two points(0,0,0) and (10,30,25.5) and display the distance between two points.

12-(The Person,Student,Employee,Faculty,and Staff classes)Design a class named Person and its two subclasses named Student and Employee. make Faculty and Staff subclasses of Employee. A person has a name, address, Phone number and email address.a student has a class status(freshman,sophomore,junior,or senior).Define the status as a constant.An employee has an office,salary, and date hired.Define a class named MyDate that contains the fields year,month, and day. A faculty member has office hours and a rank. A staff member has a title .Override the toString method in each class to display the class name and the person’s name.

Implement the classes. Write a test program that creates a Person,Student,Employee,Faculty,and Staff, and invokes their toString() methods.

13-(Finding prime numbers efficiently).The program finds a prime number by checking whether the number can be divided by 2,3,4,5,…….. and so on. If a divisor is found,the number is not a prime. Infact, there is no need to check all possible divisor. Note that if a number n is not a prime, you can always find two numbers p and q such that n=p*q, where p is a prime number. For ex-35 is not a prime because35=5*7,where 5 is prime,20 is not prime,because,20=2*10,where 2 is prime.This note leads to an efficient algorithim for finding prime numbers..You only need to check whether a numbers n is divisible by prime numbers less than n. If none of all smaller prime numbers is a divisor for n, n is prime. Write a program that displays all prime numbers less than 700,000.(Hint:Use an ArrayList to store all the prime numbers).

14-(Implementing MyStack using inheritance) Create a new stack class.

Implement MyStack.Write a test program that prompts the user to enter five strings and displays them in reverse order.

15-(Evaluating expressions)Write a program that evaluates an expression. For simplicity ,assume the operands are integers and operators are +,-,*, and /.

(Hint: Use the MyStack class to store the operands and operators ).\

16-(Design a class for complex numbers ).The complex numbers are the extension of the real numbers obtained by adjoining an imaginary unit, i, which satisfies i*i=-1.Every complex number can be written in the form of x+iy, where x and y are real numbers called the real part and the imaginary part of the complex number ,respectively.You can perform addition,subsraction,multiplication,division for complex numbers. For ex,

(4+2i)+ (2+3i)=(6+5i)

(4+2i)- (2+3i)=(2+-1i)

(4+2i)* (2+3i)=(2+16i)

(4+2i)/ (2+3i)=(1+0i)

Design a class for representing a complex numbers & the methods for performing complex number operations..Provide a toString() method that displays a complex number in the form of x+yi.