Question
this is java problem. --------------------------------------------------------------------------------- public class Blob { private int coolnessFactor; public Blob(int coolnessFactor) { this.coolnessFactor = coolnessFactor; } public int getCoolnessFactor() { return
this is java problem.
---------------------------------------------------------------------------------
public class Blob {
private int coolnessFactor;
public Blob(int coolnessFactor) {
this.coolnessFactor = coolnessFactor;
}
public int getCoolnessFactor() {
return coolnessFactor;
}
@Override
public String toString(){
return "B(" + coolnessFactor + ")";
}
}
---------------------------------------------------------------
import java.util.ArrayList;
public class BinarySearchTester {
public static int binarySearch( ArrayList
// ---> WRITE THIS METHOD
// Write code here to implement as described in problem description.
// ***Need to write a recursive helper method also.
return 1;
}
public static void main( String[] args ) {
// Sample code to create a sorted Blob list with 5 twins (10 elements).
// You should make sure your code works with other numbers of twins.
ArrayList
printBlobList(blobs);
// ---> WRITE CODE HERE TO TEST
}
// You may use this method to build and return a sorted Blob
// list based on sum of coolness factor for each of the twins.
// Creates "numTwins" twins (i.e. 2*numTwins elements)
private static ArrayList
ArrayList
int cNess = 2;
for(int i=1; i
Blob b1 = new Blob(cNess);
cNess+=2;
Blob b2 = new Blob(cNess--);
blobs.add(b1);
blobs.add(b2);
}
return blobs;
}
// You may use this method to print a blob list in a way that
// emphasizes the twins and the sum of their coolness factors.
private static void printBlobList(ArrayList
StringBuilder sb = new StringBuilder("Sorted Blob list: ");
for(int i=0; i int cNess1 = blobs.get(i).getCoolnessFactor(); int cNess2 = blobs.get(i+1).getCoolnessFactor(); int twinPower = cNess1 + cNess2; sb.append(String.format("B(%d)+B(%d)=%d, ", cNess1, cNess2, twinPower)); } sb.delete(sb.length()-2, sb.length()); System.out.println(sb.toString()); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started