• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 622
  • Last Modified:

Convert C++ Code to Java

Hallo all
I need to convert the attached code to JAVA

ps; Are there any converter tool/ tutorial /or guildline I can make use of

Thanks in Advance

class L2DTopology : public SOMLTopology
{
private:

	long	myHeight;	//
	long	myWidth;	//

	L2DTopology() {};	//privatized to force proper construction

public:

	L2DTopology(long Height, long Width)
	{
		myHeight = Height;
		myWidth  = Width;
	};

	virtual double LatticeDistance(long CellIndex1, long CellIndex2) const;		

	virtual unsigned long NumberOfCells() const { return (myHeight*myWidth); }	

	virtual ~L2DTopology() {};
};

Open in new window

0
ZURINET
Asked:
ZURINET
  • 6
  • 3
  • 3
2 Solutions
 
objectsCommented:
you need to convert the base class as well
Java2D already has a heaps of classes you may be able to use instead
0
 
CEHJCommented:
You can do something like the following. Note the comment (Java doesn't have an unsigned long)
public abstract class L2DTopology {
    private long height;
    private long width;

    private L2DTopology() {}

    public L2DTopology(long height, long width) {
	this.height = height;
	this.width = width;
    }
    public abstract double latticeDistance(long CellIndex1, long CellIndex2);

    public /*unsigned*/ long numberOfCells() { return (height*width); }	
}

Open in new window

0
 
ZURINETAuthor Commented:
Hi CEHJ

Thanks for the input..
Just a question..
If I call the method  
 public /*unsigned*/ long numberOfCells()

{
return (height*width);

}      

where would the height*width come from.. ?
Since the method numberOfCells() does not take any argument
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
objectsCommented:
it comes from the member vars provided to the constructor

    private long height;
    private long width;
0
 
objectsCommented:
You're also going to need the SOMLTopology class

And you'll need to subclass L2DTopology to actually use it.
0
 
CEHJCommented:
>>You're also going to need the SOMLTopology class

Not necessarily. Only if the whole original hierarchy needs modelling

>>where would the height*width come from.. ?
Since the method numberOfCells() does not take any arguments
>>

height and width are instance variables
0
 
ZURINETAuthor Commented:
Just one last help

If I have SOMLTopology see below..

If I have the java code.. I can do the rest..

Thanks in Advance


class SOMLTopology

{
public:

	SOMLTopology() {};

	virtual double LatticeDistance(long CellIndex1, long CellIndex2) const =0;
	virtual unsigned long NumberOfCells() const =0;

	virtual ~SOMLTopology() {};
};

Open in new window

0
 
objectsCommented:
public abstract class SOMLTopology {
   public abstract double LatticeDistance(long CellIndex1, long CellIndex2);
   public abstract long NumberOfCells();
}
0
 
objectsCommented:
and your othr class should be:


public abstract class L2DTopology extends SOMLTopology {

you could probably make SOMLTopology an interface actually
0
 
ZURINETAuthor Commented:
The message const =0;
is not relevant in Java?
0
 
objectsCommented:
nope
0
 
CEHJCommented:
>>
The message const =0;
is not relevant in Java?
>>

No - there's no equivalent in Java
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now