Professional Documents
Culture Documents
Req 36 Screening Questions - v3
Req 36 Screening Questions - v3
Req 36 Screening Questions - v3
Question 1
Write a java class that implements the following interface:
public interface Range {
/**
* Create a new Range object representing an integer interval starting from
'from' and 'to', both limits inclusive
*/
public Range newRange(int from,int to);
/**
* Return if 'value' is in the range defined by this object
*/
public boolean isIn(int value);
/**
* Return the minimum value in range
*/
public int min();
/**
* Return the maximum value in range
*/
public int max();
/**
* Add range 'r' to this range, and return 'this'.
* 'r' and this may denote disjoint ranges, for instance:
* r.newRange(1,5).add(r.newRange(8,10)) denotes a range
* including 1,2,3,4,5,8,9,10
*/
public Range add(Range r);
}
Your java class must be named RangeImplem, and must have a default contructor.
Example:
RangeImplem r=new RangeImplem();
Question 2
Optimize and correct any errors in this block of code.
/**
* Given there are 50000 items in the input String array, the
* function must add all array items to outputString and then return
* the outputString. if forceUpperCase is true, the return string must be upper
case.
*/
public String addStringItems(String[] items, boolean forceUpperCase) {
String returnValue="";
for(int i = 0; i < items.length; i++) {
returnValue+=items[i];
}
return forceUpperCase?returnValue.toUpperCase():returnValue;
}
Question 3
Using the Java Collections Framework:
Change the optimized function implementation from question #2 above.
Have the code:
1. add each array item to a Collection implementation
2. iterate over the Collection and return all values as a concatenated
3. if forceUpperCase is true, returned value must be all upper case
Tell me why you chose the container implementation that you did.
Is the optimized function thread safe?
Is the unoptimized function thread safe?
If not, how can you make it thread safe?
Question 4
Write a function:
public List<String> combine(Iterator<String> itr1,Iterator<String> itr2);
Question 5
Write a class:
public class Conversion {
/**
* Convert a base-10 integer to an 8-bit two's complement binary number, and
return the binary number.
*/
public String base10to2(String base10) {
...
}
/**
* Return 2's complement negative of the given base10 number and return the
binary number
*/
public String negBase2(String base10) {
...
}
}
Must be able to handle any base-10 integer that is submitted as command line
argument, even negative numbers.
Provide suitable error handling.
Question 6
You are writing a web service to search customer objects:
public class Customer {
String name;
String lastName;
...
List<Address> addresses;
}
public class Address {
String street1;
String street2;
String state;
...
}