• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 625
  • 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
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

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