Sunday, August 2, 2009

Java and C++ code for this UML diagram?

could someone tell me what the simple class implementation code would be for both java and c++ with this UML diagram?





LibraryPatron Class





protected int PatronNumber


protected String Name


protected String Major


private String Status





LibraryPatron()


void Modify(LibraryPatron ThisPatron)


void InputData(int x)


void PrintMe()


int GetPatronNumber()

Java and C++ code for this UML diagram?
I don't know Java, so I'll just give the C++ half:





// The declaration:





#include %26lt;string%26gt;


class LibraryPatron


{


public:





LibraryPatron();


virtual ~LibraryPatron();





void Modify(const LibraryPatron %26amp; ThisPatron);


void InputData(int x);


void PrintMe() const;


int GetPatronNumber() const;





protected:





int PatronNumber;


std::string Name; // i use STL for all me strings, matey!


std::string Major;





private:





std::string Status;


};








// The implementation:


#include "LibraryPatron.h"


#include %26lt;stdio.h%26gt;





LibraryPatron


::LibraryPatron()


: PatronNumber(0)


{


}


LibraryPatron


::~LibraryPatron()


{


}





void


LibraryPatron


::Modify(const LibraryPatron %26amp; ThisPatron)


{


if( %26amp;ThisPatron == this ) return;


PatronNumber = ThisPatron.PatronNumber;


Name = ThisPatron.Name;


Major = ThisPatron.Major;


Status = ThisPatron.Status;


}





void


LibraryPatron


::InputData(int x)


{


// I have no clue what to do with "x", sorry....


}





void


LibraryPatron


::PrintMe() const


{


printf("PatronNumber = %d\n", PatronNumber);


printf("Name = %s\n", Name.c_str());


printf("Major = %s\n", Major.c_str());


printf("Status = %s\n", Status.c_str());


}





int


LibraryPatron


::GetPatronNumber() const


{


return PatronNumber;


}








As I said, I don't know java :(


No comments:

Post a Comment