We help IT Professionals succeed at work.

Convert C++ Code to Java

ZURINET
ZURINET asked
on
Medium Priority
646 Views
Last Modified: 2012-06-21
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

Comment
Watch Question

Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
you need to convert the base class as well
Java2D already has a heaps of classes you may be able to use instead
CERTIFIED EXPERT
Top Expert 2016
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

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
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

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

    private long height;
    private long width;
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
You're also going to need the SOMLTopology class

And you'll need to subclass L2DTopology to actually use it.
CERTIFIED EXPERT
Top Expert 2016

Commented:
>>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

Author

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

Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
and your othr class should be:


public abstract class L2DTopology extends SOMLTopology {

you could probably make SOMLTopology an interface actually

Author

Commented:
The message const =0;
is not relevant in Java?
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
nope
CERTIFIED EXPERT
Top Expert 2016

Commented:
>>
The message const =0;
is not relevant in Java?
>>

No - there's no equivalent in Java
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.