Results 1 to 2 of 2
  1. #1
    manibby93 is offline Member
    Join Date
    Sep 2013
    Posts
    77
    Rep Power
    0

    Default Again, how add user input to scalable method using constant, SIZE value, for figures?

    The user input is supposed to change the overall size of the figure...the scale of it I guess.

    Java Code:
    public class ScalableMethod{ 
    public static final int SIZE = 4; 
    
    public static void main(String[] args) { 
    
    topHalf(); 
    bottomHalf(); 
    } 
    // Prints the expanding pattern of <> for the top half of the figure. 
    public static void topHalf() { 
    for (int line = 1; line <= SIZE; line++) { 
    System.out.print("|"); 
    
    for (int space = 1; space <= (line * -2 + (2*SIZE)); space++) { 
    System.out.print(" "); 
    } 
    System.out.print("<>"); 
    for (int dot = 1; dot <= (line * 4 - 4); dot++) { 
    System.out.print("."); 
    } 
    System.out.print("<>"); 
    for (int space = 1; space <= (line * -2 + (2*SIZE)); space++) { 
    System.out.print(" "); 
    } 
    System.out.println("|"); 
    } 
    } 
    // Prints the expanding pattern of <> for the bottom half of the figure. 
    public static void bottomHalf() { 
    for (int line = SIZE; line >= 1; line--) { 
    System.out.print("|"); 
    
    for (int space = 1; space <= (line * -2 + (2*SIZE)); space++) { 
    System.out.print(" "); 
    } 
    System.out.print("<>"); 
    for (int dot = 1; dot <= (line * 4 - 4); dot++) { 
    System.out.print("."); 
    } 
    System.out.print("<>"); 
    for (int space = 1; space <= (line * -2 + (2*SIZE)); space++) { 
    System.out.print(" "); 
    } 
    System.out.println("|"); 
    } 
    } 
    }

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,789
    Rep Power
    7

    Default Re: Again, how add user input to scalable method using constant, SIZE value, for figu

    Your current code has lots of hard coded (magic) numbers. Replace these with variables that you can assign values obtained from the user.

Similar Threads

  1. Replies: 5
    Last Post: 01-05-2014, 09:12 PM
  2. Replies: 4
    Last Post: 10-11-2013, 05:52 AM
  3. Replies: 6
    Last Post: 12-18-2012, 05:49 PM
  4. Replies: 3
    Last Post: 01-03-2011, 03:48 PM
  5. Constant size for JTextArea
    By itaipee in forum AWT / Swing
    Replies: 1
    Last Post: 12-30-2008, 04:12 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
  •