473,385 Members | 1,185 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

help me with this union method

I am writing a method with header like this:

public Set<E> union (Set<E> other){

}

say I have a test method:
Expand|Select|Wrap|Line Numbers
  1. @Test
  2.     public void testUnion() {
  3.         ArraySet<Integer> a = new ArraySet<Integer>(10,20);
  4.         a.add(1);
  5.         a.add(3);
  6.         a.add(5);
  7.         a.add(7);
  8.         a.add(9);
  9.  
  10.         ArraySet<Integer> b = new ArraySet<Integer>(10,20);
  11.         b.add(2);
  12.         b.add(4);
  13.         b.add(6);
  14.         b.add(8);
  15.         b.add(10);
  16.  
  17.         Set<Integer> c = a.union(b);
  18.         assertEquals(10,c.size());
  19.         for (int i = 1; i<=c.size(); i++)
  20.             assertTrue(c.contains(i));
  21.     }
  22.  
how can I say the representation of a in the method body?? I know b can be represented as other in the union method head because the union method takes other as it's argument and that argument is b in this case. but what is a??
Feb 4 '07 #1
1 2127
Ganon11
3,652 Expert 2GB
a would be referenced as this. Since you have the function as public Set..., it will be defined for each object - in this case, for Set a. Thus, the method will be called with all the variables of a in place - thus, if you had a private data member called setElements, you would simply access them by typing setElements, or this.setElements.

If you wanted to convert this function to a static function (a.k.a. not dependent on any one set), you would change the header to have 2 arguments - your function call would then look something like this:

Expand|Select|Wrap|Line Numbers
  1. Set<Integer> c = Set.union(a, b);
And if the header was public static Set union(Set one, Set two), you would access each element as one.setElemtents and two.setElements.
Feb 5 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

28
by: stu_gots | last post by:
I have been losing sleep over this puzzle, and I'm convinced my train of thought is heading in the wrong direction. It is difficult to explain my circumstances, so I will present an identical...
5
by: joshnosh | last post by:
I have two tables tblLogin and tblTrades I have 3 fields in each table, for thr purpose of this question tblLogin Fields are MemberNo RegNo Country tblTrades fields are
5
by: Alicia | last post by:
Hello everyone based on the data, I created a union query which produces this. SELECT ,,, 0 As ClosedCount FROM UNION SELECT ,, 0 AS OpenedCount, FROM ORDER BY , ;
6
by: Jamal | last post by:
I am working on binary files of struct ACTIONS I have a recursive qsort/mergesort hybrid that 1) i'm not a 100% sure works correctly 2) would like to convert to iteration Any comments or...
3
by: JF | last post by:
I would like to automate a Union query going through the tables of my dataset using VBA: I have this code: ------------------------------------------------------------------- Sub ssql() Dim...
2
by: Matt Bob | last post by:
Thanks in advance for any help... I have a single table: Employees: Name DOB startdate dept ---------|----------|-------------|------------ Al 1/1/1940 4/5/2003 ...
2
by: memo | last post by:
hi im in a trouble with c++ i made a project with c but icant convert c ++ here is the code with c #include<stdio.h> #include<stdlib.h> #include <conio.h>
4
by: Thomas | last post by:
Hello, I am a CS student and I want to write simple lisp interpreter. The code should be entierly in C. I don't want to use any compiler generators like Bison or Yak, since wrinting this in...
8
by: Latina | last post by:
Hi, I am doing a program of overloaded methods. I want to get what is the union of the user set and S set and the user set and S1 set. I try it but it is not working. Can some one help me please?...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.