Java Programming homework

profileBell0216
fall2013_assignment_4.doc

North Carolina A&T State University

ITT 240-01- Java

Fall - 2013

Assignment 4

· Due on Monday November 4th.

· Soft copy to be sent by e-mail or posted to Bb.

· Source file(s) is/are required

· Output screen snapshots also are required

· Word document explains the answers for each part.

· Please write your name and student ID at the top of the word document

Programming Exercises

EX 1:

What is wrong with the following program?

image1.png

EX 2:

What is wrong in the following code?

image2.png

Programming Exercises

EX 1:

(The MyInteger class) Design a class named MyInteger. The class contains:

· An int data field named value that stores the int value represented by this object.

· A constructor that creates a MyInteger object for the specified int value.

· A get method that returns the int value.

· Methods isEven(), isOdd(), and isPrime() that return true if the value is even, odd, or prime, respectively.

· Static methods isEven(int), isOdd(int), and isPrime(int) that return true if the specified value is even, odd, or prime, respectively.

· Static methods isEven(MyInteger), isOdd(MyInteger), and isPrime(MyInteger) that return true if the specified value is even, odd, or prime, respectively.

· Methods equals(int) and equals(MyInteger) that return true if the value in the object is equal to the specified value.

· A static method parseInt(int) that converts a string to an int value.

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

EX 2:

(The Account class) Design a class named Account that contains:

· An int data field named id for the account (default 0).

· A double data field named balance for the account (default 0).

· A double data field named annualInterestRate that stores the current interest rate (default 0).

· A Date data field named dateCreated that stores the date when the account was created.

· A no-arg constructor that creates a default account.

· The accessor and mutator methods for id, balance, and annualInterestRate.

· The accessor method for dateCreated.

· A method named getMonthlyInterestRate() that returns the monthly interest rate.

· A method named withDraw that withdraws a specified amount from the account.

· A method named deposit that deposits a specified amount to the account.

Draw the UML diagram for the class. Implement the class. Write a test program that creates an Account object with an account ID of 1122, a balance of 20000, and an annual interest rate of 4.5%. Use the withdraw method to withdraw $2500, use the deposit method to deposit $3000, and print the balance, the monthly interest, and the date when this account was created.

Reading Exercise

Read chapter 7. Propose 6 – 12 keywords. Compose 2 – 3 sentences to describe each chapter in a concise, comprehensive, and unambiguous manner.

PAGE

Dr. Naser El-Bathy Page 1