CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Threaded View

  1. #1
    Join Date
    Jan 2003
    Location
    Malaysia
    Posts
    6

    Can Anyone help Me, PLS!

    The program requires to build several classes which will put several items with different weights into the MINIMUM number of boxes. Each item will have 2 data - an identifier and a weight, W (0<W<=1£©.

    You are required to implement TWO (2) related strategies, and to compare the number of boxes used by each strategy for given set of items.

    Strategy 1:
    Arrange items into boxes.
    E.g. weights 0.4, 0.4, 0.6, 0.6 --> 2 boxes

    Strategy 2:
    Sort the items into decreasing order by weight first, then use Strategy 1.

    CLASSES GIVEN:
    --------------
    BinaryHeap.java
    PriorityQueue.java
    UnderFlowException.java

    CLASSES NEED TO BUILD:
    --------------------------
    1. Item class
    - a constructor of Item containing an integer identifier and a double weight
    - this constructor only allows weight W (0<W<=1)
    - throw an exception if constructor passes a bad weight (e.g. W>1 or W<0)
    - methods to return items identifier and weight
    - a toString method to return a left bracket, identifier, a comma, a space, a weight and
    a right bracket (e.g. "(2, 0.359)")
    2. Box class
    - start counting at 1.0
    - list of item object in the box
    - a method to return the weight can be added, already added, number of items in the box,
    the i-th item in the box (throw exception if i is invalid), list of all items in the box
    - toString method contains weight available, weight of items in box, number of items in the
    box, list of items in the box
    - implement this class with Comparable interface - compare two boxes, compare the weight of
    items to pack into boxes, and should return the list of packed boxes
    3. Strategy class
    - contains Strategy 1 method and Strategy 2 method
    - first implement Strategy 1, then implement Strategy 2
    - each method accept only a parameter of list of items to pack into boxes and return the
    list of packed boxes
    4. Test class
    - contains the main method
    - opens a text file containing a single line with a list of items weights
    (i.e. 0.3, 0.249, 0.95, 0.34, 0.21, 0.13, 0.79, 0.2, 0.86)
    - creates a list of items
    - calls each methods for Strategy 1 and 2
    - prints out the resulting list of boxes of each call

    SOS~Can anyone help me to finish this program? Thanks a lot!
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured