Thread: translation!!

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    7

    translation!!

    Hey guys...i am trying to convert the java code into c++. i have tried to translate it but i am still new in java. can you guys help me out?
    thnx... gracias

    Code:
    public class Meatthemextdoor {
    
      private boolean opened;
      private List trueBent;
    
      public Girlsdoor() {
        this.opened = false;
        this.trueBent = new ArrayList();
      }
    
      public void addTrueBent(Bang bang) {
        trueBent.add(bang);
      }
    
      public List getTrueBent() {
        return trueBent;
      }
    
      public void opening() {
        System.out.println("The door is open now.");
        opened = true;
        
        final Timer timer = new Timer();
        timer.schedule(new TimerTask() {
          public void run() {
            closemebaby();
            timer.cancel();
          }
        }, 5000);
      }
    
      public void closemebaby() {
        System.out.println("The door is closed now.");
        opened = false;
      }
    
      public boolean isOpen() {
        return opened;                      
      }                  
    }

  2. #2
    Registered User Terran's Avatar
    Join Date
    May 2008
    Location
    Nashua, NH
    Posts
    100
    Is that "meat them ext door?" phonetics FTW!

    Seriously though, if you're new to Java, why are you working with C++?

    Not a whole lot of that code looks particularly ISO friendly to me...

    Edit: I have no idea what you're even trying to do from just looking at a snippet of code... You need to be clearer about the application and the context of your code.
    Last edited by Terran; 05-31-2008 at 01:56 PM. Reason: to be picky.

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    7
    Because i know c++ much better than Java. I have found different type of java codes.
    I havent posted all java code here. Normally the whole java code should do nothing than to open a door automatically if someone (a pet) wants to go outside and after a time the door should be closed automatically.

    I have uploaded the whole code here:
    http://rapidshare.com/files/119157253/Code.zip

  4. #4
    Registered User Terran's Avatar
    Join Date
    May 2008
    Location
    Nashua, NH
    Posts
    100
    Quote Originally Posted by impossible View Post
    Because i know c++ much better than Java. I have found different type of java codes.
    I havent posted all java code here. Normally the whole java code should do nothing than to open a door automatically if someone (a pet) wants to go outside and after a time the door should be closed automatically.

    I have uploaded the whole code here:
    http://rapidshare.com/files/119157253/Code.zip
    You still haven't explained what you're trying to do with the snippet of code. And if you know C++ better then Java you shouldn't have a problem translating classes, they're fairly basic ideas.

    Is this an embedded application or what?

  5. #5
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Change boolean to bool
    Change List to std::list<Bang> (and use push_back() instead of add()...)
    Get rid of final
    Change System.out.println(...) to cout << ...
    Remove all the superfluous public & private keywords and put the proper public: or private: tags in the appropriate spots
    Lookup Timer in the Java docs and try to find something appropriate in C++ to use.
    Put a semicolon at the end of the class declaration.

  6. #6
    Registered User
    Join Date
    May 2008
    Posts
    7
    in our school the prof. is explaining a bit of java. he told me that i should learn java more effective by translating it into c++ because c++ we are doing longer time than java. i have found on the net (oreilly page) different type of java codes and some of the code its possible to convert but i am not able to translate everything. thats why i asked for help here.

  7. #7
    Registered User
    Join Date
    May 2008
    Posts
    7
    for example i was able to translate this one:

    Code:
    public class Fernsteuerung {
    
      private Hundetuer t&#252;r;
    
      public Fernsteuerung(Hundetuer t&#252;r) {
        this.t&#252;r = t&#252;r;
      }
    
      public void dr&#252;ckeKnopf() {
        System.out.println("Dr&#252;cke Fernsteuerungsknopf...");
        if (t&#252;r.isOffen()) {
          t&#252;r.schlie&#223;en();
        } else {
          t&#252;r.&#246;ffnen();
        }
      }
    }
    in c++
    Code:
    #include <iostream> 
    class Fernsteuerung{
    private:
    	Hundetuer tuer;
    public: 
    	Fernsteuerung(Hundetuer tuer){
    		this->tuer=tuer;
    	void drueckeKnopf(){
    		cout << "Druecke Fernsteuerungsknopf...";
    		if(tuer.isOffen()){
    			tuer.schliessen();
    		}
    		else{
    			tuer.oeffnen();
    		}
    	}
    };
    i hope now you guys understand.

    @ cpjust
    thanks a lot!!
    Last edited by impossible; 05-31-2008 at 03:39 PM.

  8. #8
    Registered User Terran's Avatar
    Join Date
    May 2008
    Location
    Nashua, NH
    Posts
    100
    not that i want to do your HW for you but; (some of this may be wrong, i did it in like 3 minutes in Notepad)
    Code:
    class Door {
    
    
        public:
    
        void Girlsdoor() {
        this->opened = false;
        this->trueBent = new ArrayList();
      }
    
        void addTrueBent(Bang theBang) {
        trueBent.add(theBang);
      }
    
        List getTrueBent() const {
        return trueBent;
      }
    
        void opening() {
            std::cout << "The door is open now." << endl;
            this->opened = true;
            Timer theTIMER = new Timer();
            theTIMER.schedule(new TimerTask(), this->run(), 5000);
            theTIMER.cancel();
        }
    
        void run() const {
            closemebaby();
        }
    
        void closemebaby() {
        std::cout << "The door is closed now." << endl;
        this->opened = false;
      }
    
      bool isOpen() const {
        return opened;
      }
    
      protected;
            bool opened;
            List trueBent;
    };

  9. #9
    Registered User
    Join Date
    May 2008
    Posts
    7
    thank you very much!!
    i didn't know how the timer in c++ works because we havent worked in c++ with the timer function. learned once again something new. thnx!!

    greets

  10. #10
    Registered User Terran's Avatar
    Join Date
    May 2008
    Location
    Nashua, NH
    Posts
    100
    Oh well that's not how the timer works in C++ i just assumed there was a larger class called Timer that you were creating an instance of...

    I think you need to focus on learning more C++ and less on converting Java to C++.

    Java is Java, and C++ is C++, just because they're 98&#37; similar doesn't mean they're the same.

    Monkeys and Humans share 98% of their DNA.

  11. #11
    Registered User
    Join Date
    May 2008
    Posts
    7
    lol ... good example!!
    in the future i will concentrate me more on c++ instead of java.

    thanks and good night!

  12. #12
    Registered User
    Join Date
    May 2008
    Posts
    7
    btw., here is the link to the examples:

    http://examples.oreilly.de/english_examples

  13. #13
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    We probably should not respond to these types of post with answers since it only encourages laziness and ensures a new flood of similar posts.

  14. #14
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by Bubba View Post
    We probably should not respond to these types of post with answers since it only encourages laziness and ensures a new flood of similar posts.
    That's why I just gave hints instead of writing the actual code.

  15. #15
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    We've had a recent rash of these types of posts and I'm not sure why. Just trying to discourage those who think we will do everything for them.
    Last edited by VirtualAce; 05-31-2008 at 05:20 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. character set translation
    By password636 in forum C Programming
    Replies: 1
    Last Post: 06-08-2009, 11:45 AM
  2. How to find relative translation...
    By Shamino in forum Game Programming
    Replies: 5
    Last Post: 05-20-2007, 09:39 PM
  3. Website translation
    By Jumper in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 03-17-2004, 09:34 PM
  4. msvc translation unit
    By Stoned_Coder in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 05-14-2003, 05:31 AM
  5. Translation
    By GaPe in forum C Programming
    Replies: 10
    Last Post: 04-04-2002, 09:45 AM