Question
Please answer the TODO parts for each class to make the program works, there are total 7 classes and have 4 classes need to add
Please answer the "TODO" parts for each class to make the program works, there are total 7 classes and have 4 classes need to add some codes. Please answer the "TODO" parts as many as you can, thank you very much. Please add JUnit 4 when you test the codes below.
import java.util.ArrayList; import java.util.Collection;
//TODO: 5 "to do" items below
public class BucketList
private ArrayList
// TODO: check if the calculated indexToInsert is // outside of the allowed range. If it is too large, just // insert into the last bucket. If it is too small (negative) // then insert item into bucket 0.
(list.get(indexToInsert)).add(item); } /** * Adds all entries in the Collection c to this List of Buckets * @param c is a Collection of Entries */ @Override public void addAll(Collection
//TODO: add the contents of each bucket into the output ArrayList //Hint: our bucket's .getBucketContents() will get the contents //of that bucket in sorted order if they are stored in sorted order return output; } /** * Returns an ArrayList of the bucket contents of bucket i * @param i * @return */ @Override public ArrayList
return null; // temporary line } /** * Returns the number of buckets in this list of buckets * @return int */ @Override public int getNumBuckets(){ // Leave this alone. return list.size(); } /* * Shows contents of all buckets, each bucket in [ ] brackets. * Will show empty buckets as well. */ public String toString() { // Leave this alone StringBuilder output = new StringBuilder("["); for (SortedBucket
import java.util.ArrayList; import java.util.Collection;
/* Don't change this class */
public interface BucketListADT
void add(Entry
void addAll(Collection
public int getNumBuckets();
ArrayList
}
/* There is no need to modify this class. You may modify the class if you know what you are doing, and want to add functionality to it, for instance, adding mutators */
/** * A (key,value) pair class. Key is int type. * * * * @param
public int getKey() { return this.key; }
public V getValue() { return this.val; }
public String toString() { return this.getValue()+"="+this.getKey(); } }
import java.util.ArrayList;
public class MainClass {
public static void main(String[] args) {
// No modifications are needed in this main method. It is // here just to illustrate a typical usage of this BucketList // object and the resulting BucketSort method
// This example makes a list of 6 buckets. // Key values are grades, so range is: min=0 max=100 // It adds the 6 objects from the test file, plus // several randomly-generated students. // This file, as given, will have no errors or warnings // if the BucketList and SortedBucket classes are fully // implemented // Feel free to tinker with this file as you are developing.
BucketList
// add N more random students int N = 10; ArrayList
// add the whole class to the buckets b.addAll(allStudents); // display all buckets and their contents System.out.println(b); // display the final sorted order System.out.println(b.getSortedOrder()); }
}
import java.util.ArrayList;
//TODO: 1 "to do" item below
public class SortedBucket
private ArrayList
/** * Constructor. Instantiates a bucket, which will be a sorted * collection of Entries (with each Entry being a key,value pair) */ public SortedBucket() { // Don't touch. b = new ArrayList
/** * Adds entry t to bucket in proper sorter order */ @Override public void add(Entry
@Override public String toString() { // Don't touch. return b.toString(); } }
import java.util.ArrayList;
/* Don't change this class */
public interface SortedBucketADT
void add(Entry
ArrayList
}
// This file will pass all tests without errors when BucketList // and SortedBucket are implemented
// TODO: there are 3 "to do" items below
import static org.junit.Assert.*;
import java.util.ArrayList;
import org.junit.Before;
public class Test {
/* Declaration of the test objects */ BucketList
everyone.add(jim); everyone.add(val); everyone.add(C); everyone.add(B); everyone.add(A); everyone.add(Aplus);
}
/* Various tests follow */ @org.junit.Test public void test1() { // BucketList constructor takes (min,max,numBuckets) b = new BucketList
@org.junit.Test public void test2() { // BucketList constructor takes (min,max,numBuckets) b = new BucketList
//TODO: // Figure out (on paper?) where these 6 Entry objects should // be in the case of 5 buckets. Then build a test // like in test1() to check each of the 5 buckets // for the correct contents (and correct order of contents) // (Note that list4 and list5 in test1 had their elements // added so that the resulting list is in sorted order so // that testing the corresponding bucket is easier.
// Use whichever lists you need (see test1() ) /* ArrayList
list4.add(Aplus); // ... add rest of Entry objects */ assertTrue(b.getBucket(0).isEmpty() // complete this test // &&... (add ); }
@org.junit.Test public void test3() { // BucketList constructor takes (min,max,numBuckets) b = new BucketList
@org.junit.Test public void perfectStudentTest() { // test where an Entry named "perfect" with a score of 100 will // be placed in a BucketList which stores grades from 0 to 100 and // having 10 buckets. b = new BucketList
@org.junit.Test public void outOfBoundsTest1() { // tests if we can add an Entry with key value larger than max b = new BucketList
@org.junit.Test public void outOfBoundsTest2() { // tests if we can add an Entry with key value less than min b = new BucketList
@org.junit.Test public void additionalTest() { //TODO: Write an additional test that //is different from the above }
}
src (default package) BucketList.java DBucketListADT.java D Entry.java MainClass .java D SortedBucketjava DSortedBucketADT.java DTest.java JRE System Library [JavaSE-1.8] JUnit 4Step 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