EX 1: What is wrong with the following program? EX 2: What is wrong in the follo
ID: 3572929 • Letter: E
Question
EX 1:
What is wrong with the following program?
EX 2:
What is wrong in the following code?
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.
public class ShowErrors public static void main(String args) Showerrors t new Show Errors(5) public class ShowErrors f public void method1() Circle c System. out.println ("What is radius c new Circle (e) public class ShowErrors public static void main(Stringlj args) ShowErrors t new ShowErrors0 t.x() (b) public class ShowErrors public static void mainCStringO args) C ct new C(5.0) System.out.println(c.value) class C int valueExplanation / Answer
a. public class ShowErrors
{
public static void main(String[] args)
{
ShowErrors t = new ShowErrors(S); //The variable S is not defined.
}
}
b. public class ShowErrors
{
public static void main(String[] args)
{
ShowErrors t = new ShowErrors();
t.x(); //Method x() is not defined.
}
}
c. public class ShowErrors
{
public void method1()
{
Circle c;
System.out.println("What is radius " + c.area()); //Method getRadius is not defined. Even if it is defined in the Circle class, the variable c have not been initialized.
c = new Circle();
}
}
d. public class ShowErrors
{
public static void main(String[] args)
{
C c = new C(5.0); //The C constructor is not defined with specified number of parameters.
System.out.println(c.value);
}
}
class C
{
int value = 2;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.