Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8630497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:04:36+00:00 2026-06-12T09:04:36+00:00

I have a test code for an ADT of LinkedList, which implements interface NumList.java,

  • 0

I have a test code for an ADT of LinkedList, which implements interface NumList.java, and is implemented in a NumLinkedList.java, and am using it in a NumSet.java.

I am trying to make it so that my NumSet has methods where I can create a set from a double array input, and use intercept/union and print methods to use and print the data.

but my test code is showing that my test NumSet values are empty, namely testProof and testProof2.

So now my testProof is returning an empty variable, which means nothing is saving into it.

static public NumSet intersect(NumSet S1, NumSet S2) //check 2nd for and if//
{
    NumSet intersectAnswer = new NumSet();

    for (int i = 0; i < S1.set.size()-1; i++)
    {
        for(int j = 0; j < S2.set.size()-1; j++)
        {
            double FUZZ = 0.0001;
            if (Math.abs(S1.set.lookup(i) - S2.set.lookup(j)) < FUZZ) // double values, this is more precise than ==.
                {
                    intersectAnswer.set.insert(1, S1.set.lookup(i));
                }
        }
    }

    return intersectAnswer;

}

is the method for testProof, and the following is where testProof is defined.

public static void main(String[] args)
{
    double[] a = {1.3,2,3,4,101.9};
    double[] b = {3,7,13,901,-29.1,0.05};

    NumArrayList test;
    test = new NumArrayList();
    test.printTest(); //runs test code in NumList


    //ok below is running. what is wrong with intersect?
    NumSet test2;
    test2 = new NumSet(a);
    NumSet test4;
    test4 = new NumSet(b);
    NumSet testProof;
    NumSet testProof2;

    test2.print(); //print out test 2
    System.out.println();
    test4.print();
    System.out.println();
    testProof = intersect(test2,test4);

I have initialized as

public class NumSet
{
private NumList set;

    public NumSet(double[] sth)
    {
        //moves elements of sth into set.
        set = new NumLinkedList();
        for(int i = 0; i < sth.length; i++)
        {
            set.insert(0,sth[i]);
        }
        set.removeDuplicates();
    }

    public NumSet()
    {
        set = new NumLinkedList();
    }

int numSet = 0;

and my intercept, union and print are below:

public NumSet intersect(NumSet S1, NumSet S2) //check 2nd for and if//
{
    NumSet intersectAnswer = new NumSet();

    for (int i = 0; i < S1.set.size()-1; i++)
    {
        for(int j = 0; j < S2.set.size()-1; j++)
        {
            if (S1.set.lookup(i) == S2.set.lookup(j))
                {
                intersectAnswer.set.insert(0, S1.set.lookup(i));
                }
        }
    }

    // intersectAnswer.set.removeDuplicates();  unnecessary, sets are already removed of duplicates
    return intersectAnswer;

}

public NumSet union(NumSet S1, NumSet S2)
{   //check logic.
    NumSet unionAnswer = new NumSet();

    for (int i = 1; i < S1.set.size()+1; i++)
    {
        unionAnswer.set.insert(1, S1.set.lookup(i));
    }

    for (int i = 1; i < S2.set.size()+1; i++)
    {
        unionAnswer.set.insert(1, S2.set.lookup(i)); 
    }
    unionAnswer.set.removeDuplicates();
    return unionAnswer;
}

public void print() 
{
    for (int i = 0; i < set.size()-1; i++)
    {
        System.out.print(set.lookup(i) + ",");

    }
    System.out.print(set.lookup(set.size()-1));
}

the lookup and size are referred to from my NumLinkedList.java and are as below

public int size() // measure size of list by counting counter++;
{


    return nItem; 
}


public double lookup(int i) 
{
    if( i <0 || i >= size()) //cannot lookup nonexistant object
    {
        System.out.println("out of bounds " + i + " < 0 or > " + size() );
        //how do I break out of this loop?
        System.out.println("just returning 0 for the sake of the program");

        return 0;
    }

    if(i == 0)
    {
        return head.value;
    }

    double answer = 0;
    Node currNode = head;
    for(int j = 0; j < i+1; j++) //move to ith node and save value
    {
        answer = currNode.value;    
        currNode = currNode.next;   
    }

    return answer;
}

and finally my test code is as below, where testProof and testProof2 are.

public static void main(String[] args)
{
    double[] a = {1.3,2,3,4,101.9};
    double[] b = {3,7,13,901,-29.1,0.05};

    NumArrayList test;
    test = new NumArrayList();
    test.printTest(); //runs test code in NumList


    //ok below is running. what is wrong with intersect?
    NumSet test2;
    test2 = new NumSet(a);
    NumSet test4;
    test4 = new NumSet(b);
    NumSet testProof;
    NumSet testProof2;

    test2.print();
    System.out.println();
    testProof = test2.intersect(test2, test4);
    System.out.println("tried intersect");
    testProof.print(); 
    System.out.println();
    System.out.println("tried test.print()");
    testProof2 = test2.union(test2,test4);
    System.out.println("tried union");
    testProof2.print(); 
    System.out.println();
    System.out.println("NumSet ran fully.");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:04:37+00:00Added an answer on June 12, 2026 at 9:04 am

    I’d suggest you implement you NumSet Class with integer values rather than double values while you debug because comparing two double values tends to add some unneeded complexity to your code at this debug stage.

    You might want to look at your removeDuplicates() method, I think that might hold the answer to your problem. Unfortunately I don’t see it within the code you posted.

    Actually, this part of code within the intersect() method is destined to fail from the start,

    if (S1.set.lookup(i) == S2.set.lookup(j))
    

    Because of your use of doubles, == is a very imprecise method of comparing two different values, a better way would be to allow for a certain amount of precision error, i.e.

    double final FUZZ = 0.0001
    if (Math.abs(S1.set.lookup(i) - S2.set.lookup(j)) < FUZZ )
        //...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some test code that i'm just trying to use to figure out
I have a test code using simple_dom_html: <?php include 'simple_html_dom.php'; $content = '<img src=name1.jpg
I have written some test code for comparing the performance of using direct property
i have test code using : $ adb -s emulator-5554 shell # df df
I have this test code that just saves an XML file to a folder.
Say I have a test like: void TestSomething(int someParam) { // Test code }
I have the following test code use Data::Dumper; my $hash = { foo =>
I have the following test-code: CREATE TABLE #Foo (Foo int) INSERT INTO #Foo SELECT
I have a test of C++ code that in most runs passes, but in
I have the code below in my test code in many places: // //

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.