What's new

Closed Java programmers pasok

Status
Not open for further replies.
oh eto, hinanap ko na lang. check mo sir.

This might help your problem and pamper you a little bit.

lahat ng main problem ay solved na. ang hindi lang ay yung mga related nya na problem. like for example, si number 1 at 2 ay related, si number 1 lang sinolved ko para sayo kasi papalitan mo lang naman konti yung logic mo, yun na solution for numer 2. same through to the other numbers following.

mag-aral kang mabuti sa mga ganyang logics kasi foundation yan for your programming career. mangangamote ka sa programming kung hindi malawak ang imahinasyon, logical at analytical skills mo.

DL mo lang using the link then open via MS Visual studio 2013 up. yung logic nung code is same lang yan kung translate mo sa javascript. language lang naiba pero anjan ang solution.


Download link:
You do not have permission to view the full content of this post. Log in or register now.

600674
 

Attachments

Last edited:
Now let me give you the rest of the solutions. Follow the same pattern:

Code:
class InvertedPyramidArt implements AsciiArt {

    private static final String ASTERISK = "*";
    private static final String WHITESPACE = " ";
    private static final String NEWLINE = "\n";
    private static final int ROWS = 5;
    private static final int COLS = 9;

    private InvertedPyramidArt() {}

    public static InvertedPyramidArt of() {
        return new InvertedPyramidArt();
    }

    private void process(String[] pattern) {
        for (int row = 0; row < ROWS; row++) {
            for (int col = 0; col < COLS; col++) {
                int stopper = row;

                if (col < stopper) {
                    System.out.print(WHITESPACE);
                } else if (col == stopper) {
                    for (int i = ROWS-row; i > 0; i--) {
                        System.out.print(pattern[row]);
                        System.out.print(WHITESPACE);
                    }
                } else if (col > stopper) {
                    System.out.print(WHITESPACE);
                }

            }
            System.out.print(NEWLINE);
        }
        System.out.print(NEWLINE);
    }

    @Override
    public void print() {
        process(new String[]{ASTERISK, ASTERISK, ASTERISK, ASTERISK, ASTERISK});
    }

    @Override
    public void print(String[] pattern) {
        process(pattern);
    }

}


class DiagonalArt implements AsciiArt {

    private static final String ASTERISK = "*";
    private static final String PLUS = "+";
    private static final String WHITESPACE = " ";
    private static final String NEWLINE = "\n";
    private static final int ROWS = 5;
    private static final int COLS = 5;

    private DiagonalArt() {}

    public static DiagonalArt of() {
        return new DiagonalArt();
    }

    private void process(String[] pattern) {
        for (int row = 0; row < ROWS; row++) {
            for (int col = 0; col < COLS; col++) {
                int stopper = row;

                if (col < stopper) {
                    System.out.print(pattern[0]);
                    System.out.print(WHITESPACE);
                } else {
                    System.out.print(pattern[1]);
                    System.out.print(WHITESPACE);
                }

            }
            System.out.print(NEWLINE);
        }
        System.out.print(NEWLINE);
    }

    @Override
    public void print() {
        process(new String[]{PLUS, ASTERISK});
    }

    @Override
    public void print(String[] pattern) {
        process(pattern);
    }

}



class InvertedDiagonalArt implements AsciiArt {

    private static final String ASTERISK = "*";
    private static final String PLUS = "+";
    private static final String WHITESPACE = " ";
    private static final String NEWLINE = "\n";
    private static final int ROWS = 5;
    private static final int COLS = 5;

    private InvertedDiagonalArt() {}

    public static InvertedDiagonalArt of() {
        return new InvertedDiagonalArt();
    }

    private void process(String[] pattern) {
        for (int row = 0; row < ROWS; row++) {
            for (int col = 0; col < COLS; col++) {
                int stopper = COLS - (row + 1);

                if (col < stopper) {
                    System.out.print(pattern[0]);
                    System.out.print(WHITESPACE);
                } else {
                    System.out.print(pattern[1]);
                    System.out.print(WHITESPACE);
                }

            }
            System.out.print(NEWLINE);
        }
        System.out.print(NEWLINE);
    }

    @Override
    public void print() {
        process(new String[]{PLUS, ASTERISK});
    }

    @Override
    public void print(String[] pattern) {
        process(pattern);
    }

}



class ComplexArt implements AsciiArt {

    private static final String ASTERISK = "*";
    private static final String PLUS = "+";
    private static final String WHITESPACE = " ";
    private static final String NEWLINE = "\n";
    private static final int ROWS = 5;
    private static final int COLS = 9;

    private ComplexArt() {}

    public static ComplexArt of() {
        return new ComplexArt();
    }

    private void process(String[] pattern) {
        int mid = COLS/2;

        for (int row = 0; row < ROWS; row++) {

            int k = 0;
            int j = ROWS-1;
            for (int col = 0; col < COLS; col++) {
                int stopper = mid - row;

                if (col < stopper) {
                    // Render initial 50% of outer
                    System.out.print(pattern[0]);
                    System.out.print(WHITESPACE);
                } else if (col == stopper) {
                    // Render initial 50% of inner
                    for (int i = 0; i < row + 1; i++) {
                        System.out.print(pattern[1]);
                        System.out.print(WHITESPACE);
                    }
                } else if (col > stopper) {
                    // Render remaining 50% of inner
                    for (; k < row; k++) {
                        System.out.print(pattern[1]);
                        System.out.print(WHITESPACE);
                    }
                    // Render remaining 50% of outer
                    for (; j > row; j--) {
                        System.out.print(pattern[0]);
                        System.out.print(WHITESPACE);
                    }
                }

            }
            System.out.print(NEWLINE);
        }
        System.out.print(NEWLINE);
    }

    @Override
    public void print() {
        process(new String[]{PLUS, ASTERISK});
    }

    @Override
    public void print(String[] pattern) {
        process(pattern);
    }
}


class InvertedComplexArt implements AsciiArt {

    private static final String ASTERISK = "*";
    private static final String PLUS = "+";
    private static final String WHITESPACE = " ";
    private static final String NEWLINE = "\n";
    private static final int ROWS = 5;
    private static final int COLS = 9;

    private InvertedComplexArt() {}

    public static InvertedComplexArt of() {
        return new InvertedComplexArt();
    }

    private void process(String[] pattern) {
        for (int row = 0; row < ROWS; row++) {

            int k = 0;
            int j = 0;
            for (int col = 0; col < COLS; col++) {
                int stopper = row;

                if (col < stopper) {
                    // Render initial 50% of outer
                    System.out.print(pattern[0]);
                    System.out.print(WHITESPACE);
                } else if (col == stopper) {
                    // Render initial 50% of inner
                    for (int i = ROWS-row; i > 0; i--) {
                        System.out.print(pattern[1]);
                        System.out.print(WHITESPACE);
                    }
                } else if (col > stopper) {
                    // Render remaining 50% of inner
                    for (; k < ROWS-row-1; k++) {
                        System.out.print(pattern[1]);
                        System.out.print(WHITESPACE);
                    }
                    // Render remaining 50% of outer
                    for (; j < row; j++) {
                        System.out.print(pattern[0]);
                        System.out.print(WHITESPACE);
                    }
                }

            }

            System.out.print(NEWLINE);
        }
        System.out.print(NEWLINE);
    }

    @Override
    public void print() {
        process(new String[]{PLUS, ASTERISK});
    }

    @Override
    public void print(String[] pattern) {
        process(pattern);
    }
}

When you run these, you should see these output:
Code:
* * * * *        
* * * *       
  * * *      
   * *     
    *    

5 5 5 5 5        
4 4 4 4       
  3 3 3      
   2 2     
    1    

8 8 8 8 8        
8 8 8 8       
  8 8 8      
   4 4     
    5    

* * * * *
+ * * * *
+ + * * *
+ + + * *
+ + + + *

y y y y y
x y y y y
x x y y y
x x x y y
x x x x y

4 4 4 4 4
5 4 4 4 4
5 5 4 4 4
5 5 5 4 4
5 5 5 5 4

+ + + + *
+ + + * *
+ + * * *
+ * * * *
* * * * *

x x x x y
x x x y y
x x y y y
x y y y y
y y y y y

5 5 5 5 4
5 5 5 4 4
5 5 4 4 4
5 4 4 4 4
4 4 4 4 4

+ + + + * + + + +
+ + + * * * + + +
+ + * * * * * + +
+ * * * * * * * +
* * * * * * * * *

x x x x y x x x x
x x x y y y x x x
x x y y y y y x x
x y y y y y y y x
y y y y y y y y y

5 5 5 5 4 5 5 5 5
5 5 5 4 4 4 5 5 5
5 5 4 4 4 4 4 5 5
5 4 4 4 4 4 4 4 5
4 4 4 4 4 4 4 4 4

* * * * * * * * *
+ * * * * * * * +
+ + * * * * * + +
+ + + * * * + + +
+ + + + * + + + +

y y y y y y y y y
x y y y y y y y x
x x y y y y y x x
x x x y y y x x x
x x x x y x x x x

4 4 4 4 4 4 4 4 4
5 4 4 4 4 4 4 4 5
5 5 4 4 4 4 4 5 5
5 5 5 4 4 4 5 5 5
5 5 5 5 4 5 5 5 5

Again you should see how complex problems can be tackled in a manageable manner if you approach it a systematic way.


This one is a neat code. You might want to just adapt this code since you dont have to translate it anymore. Just modify it to fit your needed output or as per your professor's preference. Just be sure you want how the code works just in case you need to defend it or your prof might want you to modify the output on the spot of your reporting or defense.
 
Status
Not open for further replies.

Similar threads

Back
Top