Java4
[Type here]
Course Title: Business Computer Languages
Course Code : IT 401
Assignment 4
Note :
· Due date: 01 /05 /2016
· 15 Marks Value 15/3 =5 Marks
· Copied assignment will be graded zero mark.
· Assignment submitted after due date will not be accepted; it will be considered to be late and will have zero mark.
Q1. Write the syntax for
· declaring an array holding 10 String values
· declaring an ArrayList holding String values. [1 Points]
Q2. Use a for loop to fill an Arraylist with the square of the numbers 1 to 10. The output should be ( 1, 4, 9, 16, ..100): [3 Points]
Q3. Rewrite the following loops, using the "for each" construct. Here data is an array of double values. [1 point]
for (int i = 0; i < data.length; i++)
sum = sum + data[i];
Q4. Write preconditions for the following methods. Do not implement the methods. [3 point]
a. public static double sqrt(double x)
b. public static String romanNumeral(int n)
c. public static String weekday(int day)
Q4. Define class cohesion and class coupling. [1 Points]
Q5. What is a static method ? What is a static variable ? Explain and provide examples. [2 Points]
Q6. What is an Immutable Class ? [1 Point]
Q7. Draw a memory diagram that shows why the following method can't swap two BankAccount objects. [3 point]
public static void falseSwap(BankAccount a, BankAccount b)
{
BankAccount temp = a;
a = b;
b = temp;
}