Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Need help finishing class methods

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    7
    My Mood
    Confused
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Need help finishing class methods

    Hey guys,

    I am new to Java and am having trouble finishing the class methods in Hole.java. I was provided reconstructor and glass. I was also told that the methods in glass are similar to those in hole. I was able to figure out some but I think I completely messed up others. Any help or tips would be welcomed.

    Thank you

    Reconstructor.java
    package StainedGlass;
    import java.io.BufferedReader;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.Arrays;
    import java.util.Comparator;
     
     
    public class Reconstructor {
     
     
        private Glass[] pieces;
        private Hole window;
        private boolean solved;
     
     
     
     
     
        public  Reconstructor(BufferedReader input) throws IOException
        {
            solved = false;
     
            readSilhouettes(input);
        }
     
     
        private void readSilhouettes(BufferedReader input) {
            final int MAXPIECES = 8;  // At most 8 pieces
            final int MAXLINES = 8*(MAXPIECES+1);  // At most 8 pieces plus a hole, each at most 8 lines long
     
            String[] lines = new String[MAXLINES];
            int[] startingLine = new int[MAXPIECES+1];
            Arrays.fill(startingLine, -1);
     
            int numLines = 0;
            try {
                while (numLines < MAXLINES) {
                    lines[numLines] = input.readLine();
                    if (lines[numLines] == null) // after EOF
                        break;
                    ++numLines;
                }
            } catch (IOException e)
            {
                // do nothing
            }
            char lastDescriptor = 'A';
            int holeStart = 0;
            for (int i = 0; i < numLines; ++i) {
                char c = findNonBlank(lines[i]);
                if (c == '%') {
                    holeStart = i;
                    break;
                } else {
                    lastDescriptor = c;
                    if (startingLine[c-'A'] < 0)
                        startingLine[c-'A'] = i;
                }
            }
            int numPieces = lastDescriptor - 'A' + 1;
            startingLine[numPieces] = holeStart;
            pieces = new Glass[numPieces];
            for (char piece = 'A'; piece <= lastDescriptor; ++piece) {
                int pieceNum = piece - 'A';
                String[] pieceLines = Arrays.copyOfRange(lines, startingLine[pieceNum], startingLine[pieceNum+1]);
                pieces[pieceNum] = new Glass(pieceLines);
            }
            String[] holeLines = Arrays.copyOfRange(lines, holeStart, numLines);
            window = new Hole(holeLines);
        }
     
        /**
         * Find the first non-blank character in a string
         * @param string
         * @return the first non-blank character or ' ' if all are blank
         */
        private char findNonBlank(String string) {
            for (int i = 0; i < string.length(); ++i)
                if (string.charAt(i) != ' ')
                    return string.charAt(i);
            return ' ';
        }
     
     
        private void printSolution() {
            if (solved)
                System.out.print (window.toString());
            else
                System.out.println ("The window cannot be repaired.");
        }
     
        /**
         * Attempt to place a piece in the window, then recursively solve the remaining part of the puzzle.
         * Continue until solved or determined to be unsolvable.
         * 
         * @param pieceNum piece to place in the window
         */
        private void solve(int pieceNum) {
            if (pieceNum >= pieces.length) {
                solved = window.filled();
            } else {
                Glass p = pieces[pieceNum];
                // System.err.println ("Attempting to insert\n" + p);
                tryToInsert (p, pieceNum);
                if (!solved) {
                    Glass p2 = p.flip();
                    // System.err.println ("Attempting to insert flipped\n" + p2);
                    tryToInsert (p2, pieceNum);
                }
            }
        }
     
        public void tryToInsert (Glass p, int pieceNum)
        {
            for (int xoffset = 0; xoffset <= window.getWidth() - p.getWidth() && !solved; ++xoffset)
                for (int yoffset = 0; yoffset <= window.getHeight() - p.getHeight() && !solved; ++yoffset)
                    if (window.fits(p, xoffset, yoffset))
                    {
                        window.insert(p, xoffset, yoffset);
                        // System.err.println ("Inserted into window\n" + window);
                        solve (pieceNum+1);
                        if (solved)
                            return;
                        window.remove(p);
                        // System.err.println ("Removed piece from window\n" + window);
                    }
        }
     
     
        private class GlassCompare implements Comparator<Glass> {
     
            @Override
            public int compare(Glass g1, Glass g2) {
                return g2.area() - g1.area();
            }
     
        }
     
     
        /**
         * Attempt to solve the puzzle.
         * 
         * @param pieceNum piece to place in the window
         */
        private void solve() {
            int total = 0;
            for (int i = 0; i < pieces.length; ++i)
                total += pieces[i].area();
            if (total == window.area()) {
                // The areas match, so there's at least a possibility that the 
                // glass pieces can fill up the window. 
     
                // Sort the pieces so that we try the largest ones first - this speeds things
                // up on average because smaller pieces are more likely to "fit" temporarily into
                // incorrect positions, which can lead us to explore a lot of dead ends.
                Arrays.sort(pieces, new GlassCompare());
     
                // Start solving beginning with piece 0
                solve(0);
            }
        }
     
     
     
        public static void main (String[] argv) throws FileNotFoundException
        {
            BufferedReader inScan = null;
            if (argv.length > 0) {
                FileReader infile = new FileReader(argv[0]);
                inScan = new BufferedReader(infile);
            } else {
                inScan = new BufferedReader(new InputStreamReader(System.in));
            }
     
            try {
                Reconstructor cw = new Reconstructor(inScan);
                cw.solve();
                cw.printSolution();
            } catch (IOException e) {
                System.err.println ("Input format error: " + e);
            }
        }
     
     
    }

    Glass.java
    /**
     * 
     */
    package StainedGlass;
     
     
    /**
     * A single piece of stained glass.
     * 
     * @author zeil
     *
     */
    public class Glass {
        private int width;
        private int height;
        private char descriptor;
        private char[][] chars;
     
        /**
         * Initializes a piece of glass given a representation in lines of text.
         * 
         * For example; given lines == {"  W", " WW", "  W"}, we would get a Glass piece
         * with width 2, height 3, and a descriptor of 'W', such that charAt(0,0) == ' '
         * and charAt(0,1) == 'W' 
         * 
         * @param text  array of strings. Each represents a single line across the glass piece. Blanks indicate
         *     horizontal positions where no glass is present. A letter indicates a position where class of a "color"
         *     denoted by that letter can be found.
         */
        public Glass (String[] text)
        {
            width = 0;
            height = text.length;
            int leftOffset = Integer.MAX_VALUE;
     
            for (int i = 0; i < height; ++i) {
                for (int w = 0; w < text[i].length(); ++w) {
                    if (text[i].charAt(w) != ' ') {
                        descriptor = text[i].charAt(w);
                        width = Math.max(width, w+1);
                        leftOffset = Math.min(leftOffset, w);
                    }
                }
            }
            width -= leftOffset;
     
            chars = new char[height][width];
            for (int h = 0; h < height; ++h) {
                for (int w = leftOffset; w < text[h].length(); ++w)
                    chars[h][w-leftOffset] = text[h].charAt(w);
                for (int w = text[h].length() - leftOffset; w < width; ++w)
                    chars[h][w] = ' ';
            }
     
        } 
     
     
     
    	/**
         * Returns the character indicating the presence or absence of glass at position
         * (w,h) in this piece. 
         * 
         * If w or h are out of bounds, returns ' ' (no glass).
         *  
         * @param x x position (starts at 0, increases moving to the right)
         * @param y y position (starts at 0, increases moving down the glass)
         * @return descriptor if glass is present at that location, ' ' otherwise
         */
        public char charAt(int x, int y) {
            if (y < 0 || y >= height)
                return ' ';
            if (x < 0 || x >= width)
                return ' ';
            return chars[y][x];
        }
     
     
        /**
         * @return the width
         */
        public int getWidth() {
            return width;
        }
     
        /**
         * @return the height
         */
        public int getHeight() {
            return height;
        }
     
        /**
         * @return the descriptor character indicating the presence of glass
         */
        public char getDescriptor() {
            return descriptor;
        }
     
     
     
     
     
        /**
         * Produces a new piece of glass by flipping this one around its vertical axis;
         * E.g.,  AAA           AAA
         *          A   becomes A
         *         A              A
         */
        public Glass flip()
        {
            String[] flippedLines = new String[height];
            for (int y = 0; y < height; ++y) {
                StringBuffer buf = new StringBuffer();
                for (int x = width-1; x >= 0; --x)
                    buf.append(chars[y][x]);
                flippedLines[y] = buf.toString();
            }
            return new Glass(flippedLines);
        }
     
     
        /**
         * The area is the total number of positions occupied by colored glass
         * 
         * @return area of this piece
         */
         public int area()
        {
             int total = 0;
             for (int h = 0; h < height; ++h)
                 for (int w = 0; w < width; ++w)
                     if (chars[h][w] != ' ')
                         ++total;
             return total;
        }
     
     
        public String toString()
        {
            StringBuffer buf = new StringBuffer();
            for (int h = 0; h < height; ++h) {
                int w = width-1;
                while (w >= 0 && chars[h][w] == ' ')
                    --w;
                for (int x = 0; x <= w; ++x)
                    buf.append(chars[h][x]); 
                buf.append('\n');
            }
            return buf.toString();
        }
     
        public boolean equals (Object o)
        {
            try {
                Glass g = (Glass)o;
                if (width != g.width || height != g.height || descriptor != g.descriptor) {
                    return false;
                }
                for (int h = 0; h < height; ++h)
                    for (int w = 0; w < width; ++w)
                        if (charAt(w,h) != g.charAt(w,h))
                            return false;
                return true;        
            } catch (Exception e) {
                return false;
            }
        }
     
     
     
     
    }

    Hole.java
    /**
     * 
     */
    package StainedGlass;
     
    public class Hole {
    	private int width;
    	private int height;
    	private char descriptor;
    	private char[][] chars;
     
    	/**
    	 * Initializes a hole given a representation in lines of text.
    	 * 
    	 * For example; given lines == {"  %", " %%", "  %"}, we would get a Hole
    	 * with width 2, height 3, such that charAt(0,0) == ' ' and charAt(0,1) ==
    	 * '%'
    	 * 
    	 * @param text
    	 *            array of strings. Each represents a single line across the
    	 *            glass piece. Blanks indicate horizontal positions where no
    	 *            glass is present. A '%' indicates a position where glass could
    	 *            be placed. A letter indicates a position where glass has been
    	 *            placed.
    	 */
    	public Hole(String[] text) // I probably don't need the descriptor...review
    								// this hunch before submission
    	{
    		width = 0;
    		height = text.length;
    		int leftOffset = Integer.MAX_VALUE;
     
    		for (int i = 0; i < height; ++i) {
    			for (int w = 0; w < text[i].length(); ++w) {
    				if (text[i].charAt(w) != ' ') {
    					descriptor = text[i].charAt(w);
    					width = Math.max(width, w + 1);
    					leftOffset = Math.min(leftOffset, w);
    				}
    			}
    		}
    		width -= leftOffset;
     
    		chars = new char[height][width];
    		for (int h = 0; h < height; ++h) {
    			for (int w = leftOffset; w < text[h].length(); ++w)
    				chars[h][w - leftOffset] = text[h].charAt(w);
    			for (int w = text[h].length() - leftOffset; w < width; ++w)
    				chars[h][w] = ' ';
    		}
    	}
     
    	/**
    	 * Returns the character indicating the presence or absence of glass at
    	 * position (w,h) in this piece.
    	 * 
    	 * If w or h are out of bounds, returns ' ' (no glass).
    	 * 
    	 * @param x
    	 *            x position (starts at 0, increases moving to the right)
    	 * @param y
    	 *            y position (starts at 0, increases moving down the glass)
    	 * @return descriptor if glass is present at that location, ' ' otherwise
    	 */
    	public char charAt(int x, int y) {
    		// your code here
    		if (y < 0 || y >= height)
    			return ' ';
    		if (x < 0 || x >= width)
    			return ' ';
    		return chars[y][x];
    	}
     
    	/**
    	 * @return the width
    	 */
    	public int getWidth() {
    		// your code here
    		return width;
    	}
     
    	/**
    	 * @return the height
    	 */
    	public int getHeight() {
    		// your code here
    		return height;
    	}
     
    	/**
    	 * Determines whether a given piece of glass would fit into the empty spaces
    	 * of this hole if the piece were shifted over by (xoffset,yoffset) from the
    	 * upper left corner of the hole.
    	 * 
    	 * @param g
    	 *            a piece of glass
    	 * @param xoffset
    	 *            horizontal offset
    	 * @param yoffset
    	 *            vertical offset
    	 * @return true if the glass could be placed in empty spaces in this hole
    	 * 
    	 */
    	public boolean fits(Glass g, int xoffset, int yoffset) {
    		// your code here
    		try {
    			for (xoffset = 0; xoffset <= width; ++xoffset)
    				for (yoffset = 0; yoffset <= height; ++yoffset)
    					if (g.area() == xoffset)
    						return true;
    			return false;
    		} catch (Exception e) {
    			return false;
    		}
    	}
     
    	/**
    	 * Inserts a piece of glass into the empty spaces of this hole, shifting the
    	 * piece over by (xoffset,yoffset) from the upper left corner of the hole.
    	 * '%' empty spots in this hole are filled with the descriptor for the
    	 * glass.
    	 * 
    	 * Pre-requisite: fits(g, xoffset, yoffset)
    	 * 
    	 * @param g
    	 *            a piece of glass
    	 * @param xoffset
    	 *            horizontal offset
    	 * @param yoffset
    	 *            vertical offset
    	 * 
    	 */
    	@SuppressWarnings("null")
    	public void insert(Glass g, int xoffset, int yoffset) {
    		// your code here
    		int[] OS = null;
    		int key;
     
    			for(xoffset = 1; xoffset <= width; ++xoffset)
    			{
    				key = OS[xoffset];
    				for (yoffset = 1; yoffset <= height; --yoffset)
    				{
    					OS[yoffset+1] = OS[yoffset];
    				}
    				OS[yoffset+1] = key;
    			}
     
     
    	}
     
    	/**
    	 * Removes a piece of glass previously fitted into this hole, All spaces in
    	 * this hole currently occupied by descriptors for g are made empty
    	 * (replaced by '%')
    	 * 
    	 * @param g
    	 *            a piece of glass
    	 * @return true if the glass could be placed in empty spaces in this hole
    	 * 
    	 */
    	public void remove(Glass p) {
    		// your code here
    		p = null;
    	}
     
    	/**
    	 * Is the hole completely filled?
    	 * 
    	 * @return true if all empty spaces have been filled with glass
    	 */
    	public boolean filled() {
    		// your code here
    		try {
    			for (int h = 0; h < height; ++h)
    				for (int w = 0; w < width; ++w)
    					if (charAt(w, h) == ' ') // If position is empty return
    												// false
    						return false;
    			return true; // Otherwise true
    		} catch (Exception e) {
    			return false; // Exception thrown return false
    		}
    	}
     
    	/**
    	 * The area is the total number of positions that are occupied by colored
    	 * glass and that are empty and could be so filled.
    	 * 
    	 * @return area of this piece
    	 */
    	public int area() // Mostly the same as Glass.java (just need to account for
    						// empty as well
    	{
    		// your code here
    		int total = 0;
    		for (int h = 0; h < height; ++h)
    			for (int w = 0; w < width; ++w)
    				if (chars[h][w] != ' ' || chars[h][w] == ' ')
    					++total;
    		return total;
    	}
     
    	public String toString() // Should be the same as in Glass.java
    	{
    		// your code here
    		StringBuffer buf = new StringBuffer();
    		for (int h = 0; h < height; ++h) {
    			int w = width - 1;
    			while (w >= 0 && chars[h][w] == ' ')
    				--w;
    			for (int x = 0; x <= w; ++x)
    				buf.append(chars[h][x]);
    			buf.append('\n');
    		}
    		return buf.toString();
    	}
     
    	public boolean equals(Object o) // Should be the same as in Glass.java, just
    									// needed to change Glass
    									// to Hole
    	{
    		// your code here
    		try {
    			Hole g = (Hole) o;
    			if (width != g.width || height != g.height
    					|| descriptor != g.descriptor) {
    				return false;
    			}
    			for (int h = 0; h < height; ++h)
    				for (int w = 0; w < width; ++w)
    					if (charAt(w, h) != g.charAt(w, h))
    						return false;
    			return true;
    		} catch (Exception e) {
    			return false;
    		}
    	}
    }
    Last edited by R2B Boondocks; September 23rd, 2013 at 01:45 PM. Reason: Complete code tags


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,387
    My Mood
    Hungover
    Thanks
    144
    Thanked 628 Times in 538 Posts

    Default Re: Need help finishing class methods

    You forgot to ask a question!
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Sep 2013
    Posts
    7
    My Mood
    Confused
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Need help finishing class methods

    Sorry! The question would be what is wrong with my methods in Hole.java? I wrote everything below the //your code here lines in each method.

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,306
    My Mood
    Mellow
    Thanks
    194
    Thanked 669 Times in 656 Posts

    Default Re: Need help finishing class methods

    Forgive us dragging you down this painful path, but what do you mean, "what is wrong?" Are you getting errors? If so, post them. Are the results not as anticipated? If so, describe what is expected and what is being received. Posting runs that demonstrate your point can be helpful. Have you received comments from an instructor or one of those nasty on-line code checkers? If so, tell us what you were told.

    We have to know what you need help with in fairly specific terms, or we could waste hours guessing.

  5. #5
    Junior Member
    Join Date
    Sep 2013
    Posts
    7
    My Mood
    Confused
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Need help finishing class methods

    Apologies guys. Here is example output and directions. (Note: The "errors" I get is that every input.txt I give it, the program tells me it can't be done when I know it should be able to)

    Problem Description: Stained Glass

    Dale was working on the restoration of an elaborate stained glass window composed of numerous irregular pieces of colored glass. He had carefully disassembled the window, treated the more faded pieces of glass to restore their bright coloring, and had made substantial progress towards reassembling the work when night fell and the poor lighting forced him to stop work.

    Upon returning the next morning, he discovered that some well-meaning janitor had disposed of his drawings and pictures of the original window. Now he has to figure out how to arrange the pieces to fit the hole remaining in the window. Dale knows that, because of the techniques used to prepare ancient stained glass, the glass was not of uniform thickness but was always cut and arranged so that the thickest edge would be at the bottom. He therefore knows the vertical orientation of each piece (they need not be rotated) but not the facing (it may be necessary to flip some pieces horizontally).

    Input

    Input to this program may be supplied via standard input or via a text file named on the command line.

    Input consists of silhouettes of one or more pieces and a silhouette of the hole in the window. A silhouette is presented as an ASCII graphic composed of blanks and a specific non-blank character (as described further below). A blank character indicates locations where no glass exists. The non-blank characters indicate the presence of glass (or, in the case of the hole's silhouette, a location where we wish to place some glass).

    Each silhouette consists of 1 to 8 lines, each line containing 1 to 8 characters. Each line of a silhouette will have at least one non-blank character. Each silhouette is presented in a separate sequence of lines.

    The first piece is rendered using the character `A', then the next piece with a `B', and so on. There will be at most 8 pieces. After the final piece, the silhouette of the hole is rendered using the character `%'. The transition from one silhouette to the next is signaled by the change of character. The end of the hole's silhouette is signaled by the end of input.

    Output

    If an arrangement of the pieces that exactly and completely fills the holeā€™s silhouette is possible, print that silhouette filled in with the alphabetic characters indicating the positioning of the pieces. (If more than one arrangement is possible, you may show any one of them.) The filled-in silhouette should be printed as far to the left as possible without distorting the shape of the silhouette. There should be no blanks spaces at the ends of the output lines.

    If no such arrangement is possible, print a line consisting of the phrase "The window cannot be repaired." (including the closing period).

    Examples

    Given the input

    A
    AAA
    A
    A
    AAA
    B
    BBB
    B
    B
    BB
    B
    CC
    C
    %
    %%%%
    %%%%
    %%%%
    %%%%
    %%%%

    the output would be

    B
    ABBB
    AAAB
    ACCB
    ACBB
    AAAB

    Given the input

    A
    B
    C
    %%
    %%

    the output would be

    The window cannot be repaired.

    Notes

    The main() function for this program is found in the class StainedGlass.Reconstructor.
    The main algorithm used by the Reconstructor class' solve(...) function is an example of backtracking. You don't need to know that, as CS361 is not a pre-requisite for this course, but just in case you were curious...
    Backtracking is a solution technique of "last resort". It tends to run in time that grows exponentially with the size ofthe input set, which is why this problem is limited to no more than 8 fairly small pieces of glass. Even at that, the solution needs some heuristics ("tricks") to improve the performance by not wasting time on partial solutions that are likely to pay off in the long run.

    The Hole and Glass classes are actually similar in some respects. You may be able to get some insight into how to implement the Hole functions by studying the Glass class.
    I have suggested a reasonable data structure for the Hole, and provided the input code for it. You may change that data structure if you like.

  6. #6
    Junior Member
    Join Date
    Sep 2013
    Posts
    7
    My Mood
    Confused
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Need help finishing class methods

    Anyone?

  7. #7
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,387
    My Mood
    Hungover
    Thanks
    144
    Thanked 628 Times in 538 Posts

    Default Re: Need help finishing class methods

    All you've done is dump your homework here. I'm not sure what your question is. See the link in my signature on asking questions the smart way, and we'll be happy to help if you ask a specific technical question and post an SSCCE.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  8. #8
    Junior Member
    Join Date
    Sep 2013
    Posts
    7
    My Mood
    Confused
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Need help finishing class methods

    Alright. A good place to start would be: Are there any algorithms out there that would help me complete the following two methods?:
    /**
    	 * Determines whether a given piece of glass would fit into the empty spaces
    	 * of this hole if the piece were shifted over by (xoffset,yoffset) from the
    	 * upper left corner of the hole.
    	 * 
    	 * @param g
    	 *            a piece of glass
    	 * @param xoffset
    	 *            horizontal offset
    	 * @param yoffset
    	 *            vertical offset
    	 * @return true if the glass could be placed in empty spaces in this hole
    	 * 
    	 */
    	public boolean fits(Glass g, int xoffset, int yoffset) {
    		// your code here
    		try {
    			for (xoffset = 0; xoffset <= width; ++xoffset)
    				for (yoffset = 0; yoffset <= height; ++yoffset)
    					if (g.area() == xoffset)
    						return true;
    			return false;
    		} catch (Exception e) {
    			return false;
    		}
    	}
     
    	/**
    	 * Inserts a piece of glass into the empty spaces of this hole, shifting the
    	 * piece over by (xoffset,yoffset) from the upper left corner of the hole.
    	 * '%' empty spots in this hole are filled with the descriptor for the
    	 * glass.
    	 * 
    	 * Pre-requisite: fits(g, xoffset, yoffset)
    	 * 
    	 * @param g
    	 *            a piece of glass
    	 * @param xoffset
    	 *            horizontal offset
    	 * @param yoffset
    	 *            vertical offset
    	 * 
    	 */
    	@SuppressWarnings("null")
    	public void insert(Glass g, int xoffset, int yoffset) {
    		// your code here
    		int[] OS = null;
    		int key;
     
    			for(xoffset = 1; xoffset <= width; ++xoffset)
    			{
    				key = OS[xoffset];
    				for (yoffset = 1; yoffset <= height; --yoffset)
    				{
    					OS[yoffset+1] = OS[yoffset];
    				}
    				OS[yoffset+1] = key;
    			}
     
     
    	}

    Note that for the insert method I attempted to follow an insertion sort algorithm. Second question would be: Are there any places to review up on the concept of xoffet and yoffset shifts (I think that is hindering my progress for the fits / insert methods)? Google has failed me with this one.

Similar Threads

  1. Multiple methods in the same inner class?
    By tommyf in forum What's Wrong With My Code?
    Replies: 12
    Last Post: January 24th, 2012, 12:10 PM
  2. Use of Exceptions and Methods of The String Class
    By cagataylina in forum Exceptions
    Replies: 1
    Last Post: April 26th, 2011, 01:56 AM
  3. Running methods of a class that created you...
    By joestr in forum Java Theory & Questions
    Replies: 2
    Last Post: April 3rd, 2011, 01:59 PM
  4. Help requested - testing a class with a tester class, no methods allowed.
    By miketeezie in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 21st, 2011, 09:40 PM
  5. [SOLVED] Help with Class Methods(Probably simple)
    By ShakeyJakey in forum Object Oriented Programming
    Replies: 9
    Last Post: May 27th, 2010, 09:53 AM