• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Define a partial order interface help

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need some help understanding what a partial order interface with one method greaterThan(). I am working on an exercise to compare the volume of three boxes and this statement is the next step. Thank you,
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why not use Comparable? You can use compareTo for the same causes. For a.compareTo(b)
  • < 0 means that a is less than b
  • > 0 means that a is greater than b
  • == 0 means that a is equal to b

  • You can also use <= and >= of course.
     
    Bartender
    Posts: 6109
    6
    Android IntelliJ IDE Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Craig Warnick wrote:I need some help understanding what a partial order interface with one method greaterThan().



    Can you provide some context? Where did you come across this term? And what specific problems are you having?
     
    Marshal
    Posts: 28193
    95
    Eclipse IDE Firefox Browser MySQL Database
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Well, here's a link to the Wikipedia article about it: Partially ordered set. I must say, I don't really see how to implement a partial ordering over a domain in Java; perhaps you throw a runtime exception if you try to compare a pair of incomparable elements?

    But anyway if you're just going to compare the volume of boxes, then that's really a Total order. In that case it's much easier to implement a greaterThan method.
     
    Craig Warnick
    Greenhorn
    Posts: 8
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    class BoxVolSort implements Comparator<Box> {
    public int compare(Box b1, Box b2, Box b3) {
    if(b1.getVolume() == b2.getVolume()==b3.get volume)
    return 0;
    else if (b1.getVolume() < b2.getVolume() > b3.getVolume)
    return -1;
    else
    return 1;

    This is what I came up with off the top of my head, but the statement that caused my helmet fire is:

    box b > box c returns 1 whenever box c fits inside box box b. Note that c fits inside b if there is a way to arrange the dimensions of each box so
    the corresponding dimensions of b are each larger than c.

    No clue how to do that. Thanks for your earlier reply Saloon Keeper.

     
    Craig Warnick
    Greenhorn
    Posts: 8
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Its just a programming exercise I was given from a coworker. to help me learn Java. I am not in the programming business but trying to learn. Thanks
     
    Bartender
    Posts: 10780
    71
    Hibernate Eclipse IDE Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Craig Warnick wrote:box b > box c returns 1 whenever box c fits inside box box b. Note that c fits inside b if there is a way to arrange the dimensions of each box so
    the corresponding dimensions of b are each larger than c.

    No clue how to do that. Thanks for your earlier reply Saloon Keeper.


    Well, first off, java.util.Comparator works on two objects, not three, so I'd start off by amending your class accordingly.

    Second, as you said yourself:

    Note that c fits inside b if there is a way to arrange the dimensions of each box so the corresponding dimensions of b are each larger than c.

    So, in terms of a "fits inside" order, I would say that if Box a fits inside Box b, then
    compare(a, b)
    should return a negative number, and
    compare(b, a)
    should return a positive one; otherwise, your comparator should return 0 because the two objects have no 'order' with respect to each other in terms of "fitting in".

    Then it's just a matter of calling the method for combinations of pairs for larger numbers of boxes.

    [Edit] Note that while the above would work for providing a rudimentary "fits in" ordering, I suspect there's quite a bit more logic required to actually create a POS for these boxes. In terms of structure, I think I might look at an array of linked lists, but I suspect you're also going to need to come up with a heuristic to ensure that as many boxes are "fitted" as possible.

    HIH

    Winston
     
    Java Cowboy
    Posts: 16084
    88
    Android Scala IntelliJ IDE Spring Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Craig Warnick wrote:I need some help understanding what a partial order interface with one method greaterThan(). I am working on an exercise to compare the volume of three boxes and this statement is the next step. Thank you,


    It sounds like the exercise is to define an interface with one method, greaterThan(). You can do that in just 3 lines of code or so.

    See What Is an Interface? in Oracle's Java Tutorials.
     
    Craig Warnick
    Greenhorn
    Posts: 8
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks for all your responses and help. Got it figured out.
     
    Marshal
    Posts: 79177
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Well done, and welcome to the Ranch
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    reply
      Bookmark Topic Watch Topic
    • New Topic