Question: Code for Oracle.jaa package MissingNumber; import java.lang.Math; public class Oracle { long [ ] data; / / Creates a new oracle, ready to be told

Code for Oracle.jaa
package MissingNumber;
import java.lang.Math;
public class Oracle {
long[] data;
// Creates a new oracle, ready to be told all numbers
//(in any order) from 1 to 1000000, except for one or two.
//
// Must run in O(1) time.
Oracle()
{
}
// Tells the oracle a number between 1 and 1000000 not yet told.
//
// Must run in O(1) time.
void tell(int i)
{
}
// If every number between 1 and 1000000 except one have
// been told, and no number has been told more than once,
// sets MissInt[0] equal to the one number not yet told.
//
// Otherwise has undefined behavior.
//
// Must run in O(1) time.
void missing_one(int[] MissInt)
{
}
// If every number between 1 and 1000000 except two have
// been told, and no number has been told more than once,
// sets MissInt[0] and MissInt[1] equal to the two numbers
// not yet told (where MissInt[0] MissInt[1]).
//
// Otherwise has undefined behavior.
//
// Must run in O(1) time.
void missing_two(int[] MissInt)
{
}
}
Code for MAintest.java
package MissingNumber;
import java.util.*;
import MissingNumber.Oracle;
public class MainTest {
public static void main(String[] args){
// Setup
int[] MissInt;
MissInt = new int[2]; // For missing numbers.
ArrayList V= new ArrayList();
// Test missing_one()
Oracle o1= new Oracle();
for (int i =1; i =999999; ++i)
o1.tell(i);
MissInt[0]=0;
o1.missing_one(MissInt);
test(MissInt[0]==1000000);
Oracle o2= new Oracle();
for (int i =2; i =1000000; ++i)
o2.tell(i);
MissInt[0]=0;
o2.missing_one(MissInt);
test(MissInt[0]==1);
Oracle o3= new Oracle();
o3.tell(1);
for (int i =3; i =1000000; ++i)
o3.tell(i);
MissInt[0]=0;
o3.missing_one(MissInt);
test(MissInt[0]==2);
Oracle o4= new Oracle();
V.clear();
for (int i =1; i =1000000; ++i)
V.add(i);
Collections.shuffle(V);
for (int i =0; i 999999; ++i)
o4.tell(V.get(i));
o4.missing_one(MissInt);
test(MissInt[0]== V.get(999999));
Oracle o5= new Oracle();
V.clear();
for (int i =1; i =1000000; ++i)
V.add(i);
Collections.shuffle(V);
for (int i =0; i 999999; ++i)
o5.tell(V.get(i));
o5.missing_one(MissInt);
test(MissInt[0]== V.get(999999));
System.out.println("Assignment complete.");
}
public static void test(Boolean a){
if (a) System.out.println("Found!!!");
else
{
System.out.println("Fail!");
}
return;
}
}
 Code for Oracle.jaa package MissingNumber; import java.lang.Math; public class Oracle {

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!