Results 1 to 5 of 5
  1. #1
    AcousticBruce is offline Senior Member
    Join Date
    Dec 2010
    Location
    Indiana
    Posts
    202
    Rep Power
    4

    Default I want to use more objects in my thining.

    I want to have a user input a string such as "Welcome Home" and the it out put the string in a ascii type fashion.

    I created an array for each letter in the alphabet.

    Here is an example without user input.

    Java Code:
    	for (int i = 0; i < mArray.length; i++) {
    
        		System.out.println(mArray[i] + "   " + bArray[i] + "   " + aArray[i] + "   ");
        	}
    Java Code:
    **       **   *******       **      
    ***     ***   **     *     *  *     
    ** *   * **   **     *    *    *    
    **  * *  **   **     *   **    **   
    **   *   **   *******    ********   
    **       **   **     *   **    **   
    **       **   **     *   **    **   
    **       **   **     *   **    **   
    **       **   *******    **    **   
    
    Process completed.
    I tend to think linear and program everything in the main method. I want to start thinking as in Objects and methods even if it takes me longer to write simple programs. So with this program

    1) What kind of methods would you make ( I just need some ideas not code). Sure you can say "well whatever you want" but I already know I can use whatever I chose. I am asking YOU how YOU might go about this.

    2) I want to use a char within a string to call my String[] variables. So maybe the first letter of the actual var name would be called by a char. SO if the char tempLetter is 'b' then it would call (tempLetter)Array or (b)Array. This maybe a bit advanced for me, but I am very curious.

  2. #2
    demonick is offline Member
    Join Date
    Dec 2010
    Posts
    27
    Rep Power
    0

    Default

    I would start with taking the main writing process out of main method into a separate method, so it can be reused elsewhere.

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,304
    Blog Entries
    7
    Rep Power
    20

    Default

    I'd create a BufferedImage and get its Graphics object; set the font, draw the String and iterate over all coordinates of the image and draw a '*' (or whatever) when the pixel is set to black, otherwise a ' ' is drawn.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    AcousticBruce is offline Senior Member
    Join Date
    Dec 2010
    Location
    Indiana
    Posts
    202
    Rep Power
    4

    Default

    Quote Originally Posted by demonick View Post
    I would start with taking the main writing process out of main method into a separate method, so it can be reused elsewhere.
    I am simply looking for how to structure some methods and what methods too create.

    Quote Originally Posted by JosAH View Post
    I'd create a BufferedImage and get its Graphics object; set the font, draw the String and iterate over all coordinates of the image and draw a '*' (or whatever) when the pixel is set to black, otherwise a ' ' is drawn.

    kind regards,

    Jos
    Sweet. This is really advanced and I have no idea how to do this. But I can figure it out with the net :)

    But I was wondering what methods and classes to create. How many classes and methods would you make?

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,304
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by AcousticBruce View Post
    I am simply looking for how to structure some methods and what methods too create.

    Sweet. This is really advanced and I have no idea how to do this. But I can figure it out with the net :)

    But I was wondering what methods and classes to create. How many classes and methods would you make?
    I'd create a simple class that 'owns' a BufferedImage of size width*height (that'd be a constructor's job). It can have a method that'd set the font and scribble a String of text on the BufferedImage. Maybe for convenience I'd implement a small method 'getPixel(int x, int y)' that'd return the value of the pixel (maybe only black and white are supported here, it would be enough). So basically the layout of the class would look like this:

    Java Code:
    public class Scribbler {
       public Scribbler(int width, int height) { ... }
       public void setFont(Font font) { ... }
       public void scribble(String text) { ... }
       public boolean getPixel(int x, int y) { ... }
    }
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. How to map 2 different objects together?
    By einnhann in forum New To Java
    Replies: 5
    Last Post: 12-22-2009, 09:42 AM
  2. Objects
    By Silverlining in forum New To Java
    Replies: 3
    Last Post: 11-11-2009, 02:36 PM
  3. Replies: 1
    Last Post: 01-22-2009, 04:25 PM
  4. Two Objects
    By losintikfos in forum New To Java
    Replies: 3
    Last Post: 11-14-2008, 07:04 PM
  5. how many objects ?
    By kevinsong in forum Advanced Java
    Replies: 16
    Last Post: 07-16-2008, 05:59 PM

Posting Permissions

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