Thread: Help with java

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    12
    Rep Power
    0

    Help with java


    I wrote main class for edgematch in java.
    I need to check the solution for edgematch to see if it is valid. I compiled the code but it shows grid already filled.

    here is my code:

    Code:
    Code:
    /**
     *
     * @author usmanm2
     */
    public class Main {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            
            int rows = 6;
            int columns = 6;
            int colours = 7;
    
            EdgeMatch em = new EdgeMatch(rows, columns, colours);
            em.randomYesInstance();
            
            EdgeMatchSolution ems = new EdgeMatchSolution(em);
            ems.randomSolution();
                          
            EdgeMatchDisplay emd = new EdgeMatchDisplay(ems, 500, 500);
            emd.setVisible(true);
            boolean answer = CheckSolution(ems, rows, columns);
        }
        
        public static boolean CheckSolution(EdgeMatchSolution ems, int rows, int columns)
        {
            
            for (int i = 0; i <rows; i++)
                for (int j = 0; j <columns; j++)
                {
                    if (ems.occupied(i,j))
                        return false;
                }
                return true;
        }
    }
    regarding the second part for checksolution method is to check the solution but my program shows something else.

    regarding the second part of the task i have created my program but i need to fill all the boxes from top left hand corner, row by row to down ward.

    Code:
    import java.util.Scanner;
    
    /**
     *
     * @author usmanm2
     */
    public class Main {
        static Scanner input;
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            input = new Scanner(System.in);
            int i, j;
            // TODO code application logic here
            EdgeMatch em = new EdgeMatch(5, 5, 10);
            //em.randomYesInstance();
            EdgeMatchSolution ems = new EdgeMatchSolution(em);
            
            EdgeMatchDisplay emd = new EdgeMatchDisplay(ems, 400, 400);
            emd.setVisible(true);
            
            input.next();
            ems.add(3, 3, 0);
            emd.repaint();
        }
        public static void addTiles(EdgeMatchSolution ems, int i, int j)
        {
            for(i = 0; i < 36; i++)
            {
                for (j = 0; j < 36; j++)
                    System.out.println(ems);
            }
        }
    }
    this program shows empty grid.


    in this program a user has to selec the piece.

    here is my code:
    Code:
    import java.util.Scanner;
    
    /**
     *
     * @author usmanm2
     */
    public class Main {
        static Scanner input;
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            input = new Scanner(System.in);
            // TODO code application logic here
            EdgeMatch em = new EdgeMatch(5, 5, 10);
            input.nextInt();
            EdgeMatchSolution ems = new EdgeMatchSolution(em);
            
            EdgeMatchDisplay emd = new EdgeMatchDisplay(ems, 400, 400);
            emd.setVisible(true);
        }
        public static void swap(EdgeMatchPiece ems)
        {
                    ems.swap(piece);
                    ems.repaint();
            }
        }
    but the user can't select any piece.
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    Where is the definition for the EdgeMatch class?

    Why have you posted 3 versions of the same class?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    12
    Rep Power
    0
    Originally Posted by NormR
    Where is the definition for the EdgeMatch class?

    Why have you posted 3 versions of the same class?
    edgematch class in the .jar file.

    each version includes different outputs.
  6. #4
  7. Daniel Schildsky
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Mar 2004
    Location
    KL, Malaysia.
    Posts
    1,540
    Rep Power
    1621

    Settle one by one


    Can't you at least settle the first one before you proceed with the rest?

    Also, we are not clear on what you are trying to achieve. For part one, you have told us what the program is written for and what is the output produced so far; But you have yet to tell us the expected output and sample input.

    The more details you provide, the better we understand the issue and the more helpful our advice woud be.
    When the programming world turns decent, the real world will turn upside down.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    12
    Rep Power
    0
    Originally Posted by tvc3mye
    Can't you at least settle the first one before you proceed with the rest?

    Also, we are not clear on what you are trying to achieve. For part one, you have told us what the program is written for and what is the output produced so far; But you have yet to tell us the expected output and sample input.

    The more details you provide, the better we understand the issue and the more helpful our advice woud be.
    OK for the first program.

    first program is initialsed. this program create 6 x6 tiles to be produced for the output. it used colours up to 10 only. colours numbers must be range from 1 - 10. regarding the tiles can be any numer large. for my program it will 6 x 6 square tiles.

    the program actually checks the algorithm to see if the output is valid or not.
  10. #6
  11. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    How can anyone compile and execute the posted code for testing?
    There are missing class definitions.
  12. #7
  13. Daniel Schildsky
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Mar 2004
    Location
    KL, Malaysia.
    Posts
    1,540
    Rep Power
    1621

    Checking solution


    java Code:
     
     
    public static boolean CheckSolution(EdgeMatchSolution ems, int rows, int columns)
        {
     
            for (int i = 0; i <rows; i++)
                for (int j = 0; j <columns; j++)
                {
                    if (ems.occupied(i,j))
                        return false;
                }
                return true;
        }


    What is the condition to confirm that the EdgeMatch algorithm is correct? From your codes, it seems that this CheckSolution() method only returns true if all grids are empty.
    When the programming world turns decent, the real world will turn upside down.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    12
    Rep Power
    0
    Originally Posted by tvc3mye
    java Code:
     
     
    public static boolean CheckSolution(EdgeMatchSolution ems, int rows, int columns)
        {
     
            for (int i = 0; i <rows; i++)
                for (int j = 0; j <columns; j++)
                {
                    if (ems.occupied(i,j))
                        return false;
                }
                return true;
        }


    What is the condition to confirm that the EdgeMatch algorithm is correct? From your codes, it seems that this CheckSolution() method only returns true if all grids are empty.
    the condition is to check checksolution() method to check the condition is valid or not valid.
  16. #9
  17. Daniel Schildsky
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Mar 2004
    Location
    KL, Malaysia.
    Posts
    1,540
    Rep Power
    1621

    How do you define validity?


    the condition is to check checksolution() method to check the condition is valid or not valid.
    And how do you define validity of the condition?
    When the programming world turns decent, the real world will turn upside down.
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    12
    Rep Power
    0
    Originally Posted by tvc3mye
    And how do you define validity of the condition?
    OK, i couldn't see any validity of the condition.

    could you proceed to next thread.
  20. #11
  21. Daniel Schildsky
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Mar 2004
    Location
    KL, Malaysia.
    Posts
    1,540
    Rep Power
    1621
    If you can't see the validity of the way this method uses to test the correctness of the EdgeMatch algorithm, then this test is flawed in design and should be removed from your codes.

    To test for the correctness of the algorithm, you should first define a few things:
    a) What are the attributes of the EdgeMatch algorithm that can be used as validation criteria?
    b) What are the available ways to test these attributes?
    c) What are the defining conditions for the tests with these attributes which constitutes the passing/failure of the test?
    d) How to control the other variables so as to make them constant and to prevent them from interfering the test results?

    If you are implementing your own EdgeMatch algorithm then you should have performed the following before you start validating/verifying the correctness of your algorithm:
    a) Ensure that your program is error-free.
    b) Ensure that your codes are implementing your drafted algorithm correctly for each step.
    c) Ensure that the input to your program is not flawed.

    regarding the second part for checksolution method is to check the solution but my program shows something else.

    regarding the second part of the task i have created my program but i need to fill all the boxes from top left hand corner, row by row to down ward.

    What actually are you trying to accomplish with the second version of your codes?

    OK, i couldn't see any validity of the condition.

    could you proceed to next thread.
    If we proceed to the next thread, does that mean your problem is solved after removing the CheckSolution() method in your class?
    When the programming world turns decent, the real world will turn upside down.

IMN logo majestic logo threadwatch logo seochat tools logo