Announcement

Collapse
No announcement yet.

Java problem - help please!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #31
    Originally posted by Kuciwalker View Post
    This doesn't work, as per the OP, because the submarine has to know what Sea it's in if it wants to know where it can move.

    You could give it a reference to a global object that contains a list of all the seas, but that is functionally pretty similar.
    Still don't like it, too tight a coupling.
    "The issue is there are still many people out there that use religion as a crutch for bigotry and hate. Like Ben."
    Ben Kenobi: "That means I'm doing something right. "

    Comment


    • #32
      If there are rules external to the sub governing where it can move, then the logic to determine if the sub can move should be external to the sub object.
      "The issue is there are still many people out there that use religion as a crutch for bigotry and hate. Like Ben."
      Ben Kenobi: "That means I'm doing something right. "

      Comment


      • #33
        If there are rules external to the sub governing where it can move, then the logic to determine if the sub can move should be external to the sub object.


        Sure, but since Cort Haus mentioned Submarine.moveTo in the OP I assumed it was part of the spec and therefore required.

        Comment


        • #34
          That's why I hated programming assignments. They're usually not well constructed, and don't lead to well-designed solutions.
          "The issue is there are still many people out there that use religion as a crutch for bigotry and hate. Like Ben."
          Ben Kenobi: "That means I'm doing something right. "

          Comment


          • #35
            Originally posted by Asher View Post
            That's why I hated programming assignments. They're usually not well constructed, and don't lead to well-designed solutions.
            Well, Cort Haus was actually quite sparse on what he wanted, so no wonder. I really can't figure out what will be the best - fleet or ocean base, though, I tend to favor fleet base despite the problems.
            With or without religion, you would have good people doing good things and evil people doing evil things. But for good people to do evil things, that takes religion.

            Steven Weinberg

            Comment


            • #36
              I agree with Asher and BlackCat on this one.
              Jon Miller: MikeH speaks the truth
              Jon Miller: MikeH is a shockingly revolting dolt and a masturbatory urine-reeking sideshow freak whose word is as valuable as an aging cow paddy.
              We've got both kinds

              Comment


              • #37
                Guys, I got the job done using the magic word 'this', to relate the object and its container. I'll post the details later. A slight confession - the seas and subs was a metaphor for the actual requirements. The OP was originally written for the course forum, where we shouldn't be discussing details of assignment work, so I substituted (har har) the allotment and various vegetable types for another example.

                The moveSub method was equivalent to (eg) plantCarrot and checkMove equated to plotValid in the allotment class. Veg types had to be placed in the field according to certain rules which were checked in plotValid. The difference was that there was only one allotment in the scenario, rather than the multiple seas, so all the fighting over that was probably not necessary, even though you doubtless enjoyed it. I certainly did. Sorry about that.

                The assignment was part 1 of a game (which to me looks like some sort of vegetarian version of Battleships) where a number of different veg types of different shapes are plotted in a field-grid according to certain rules, with the total number of occupied plots (tiles) summed for each row and column. Part 2 (not required in this assignment) is for the second player to guess the positions of all veg in the minimum number of turns, by enquiring into the status of individual plots. This assignment (which I've now done) is just about setting up the board.

                I'll post my implementation of the relationship between object and container in due course, and maybe you can explain the shortcomings of it. Thanks for all your contributions so far.

                Oh, I should add that in this or any subsequent questions where I seek your valued collective wisdom, I am looking for an understanding of principles, rather than for anyone to solve a logical problem for me, or to do my work for me, which would be unethical and illegal under university rules, and rightly so. I can solve problems logically and devise algorithms well, but I'm stuck with decades of procedural programming thinking, and having to adapt to OOP, which for me is the challenging part.

                Comment

                Working...
                X