Results 1 to 15 of 15
  1. #1
    SgtGump is offline Member
    Join Date
    Nov 2013
    Posts
    9
    Rep Power
    0

    Default Looking for help with my code

    The main method is what I need help with.
    Iv'e attached a picture of the out come.

    Basically i need the middleLine() to print 1 less then the amount of times rowHeight() because the last row should be replace with lastLine().

    ive been messing around with it for awhile and its just not working the way i want.
    Let me know
    Thanks

    Heres my code...
    ************************************************** ************************************************** *************
    private static int numColumn,columnWidth,numRows,rowHeight;
    static char firstLine[] = {'\u2501', '\u250F', '\u2533', '\u2513'};

    static char middleLine[]={'\u2501', '\u2523', '\u254B', '\u252B'};

    static char lastLine[] = {'\u2501', '\u2517', '\u253B', '\u251B'};


    public static void firstLine(){
    System.out.print(firstLine[1]+"");

    for (int first=1;first<=numColumn;first++){ //if counter is less then or equal to the number of columns it will loop
    for (int i=1;i<=columnWidth;i++){
    System.out.print(firstLine[0]); //if counter is less then or equal to the width it will print unicode \u2501
    }
    if (first<numColumn){ //if the counter is less then column num print unicode \u2533
    System.out.print(firstLine[2]);
    }else{
    System.out.print(firstLine[3]+"\n"); //else print unicode \u2513
    }
    }
    }
    public static void middleLine(){


    System.out.print(middleLine[1]+"");

    for (int first=1;first<=numColumn;first++){ //if counter is less then or equal to the number of columns it will loop
    for (int i=1;i<=columnWidth;i++){
    System.out.print(middleLine[0]); //if counter is less then or equal to the width it will print unicode \u2501
    }
    if (first<numColumn){ //if the counter is less then column num print unicode \u254B
    System.out.print(middleLine[2]);
    }else{
    System.out.print(middleLine[3]+"\n"); //else print unicode \u252B
    }
    }
    }

    public static void lastLine(){
    System.out.print(lastLine[1]+""); // print unicode \u2517

    for (int last=1;last<=numColumn;last++){
    for(int y=1;y<=columnWidth;y++){
    System.out.print(lastLine[0]); //print unicode \u2501
    }
    if (last<numColumn){
    System.out.print(lastLine[2]); //print unicode \u253B
    }else{
    System.out.print(lastLine[3]+"\n"); //print unicode \u251B
    }
    }
    }


    public static void rowHeight(){
    for (int loop=1;loop<=rowHeight;loop++){
    for (int mid=0;mid<=numColumn;mid++){
    System.out.print("\u2503");
    for (int x=1;x<=columnWidth;x++){
    System.out.print("\u2002"+"\u2002"+"\u200a"); //if counter is less then or equal to width print out a space
    }


    }
    System.out.print("\n"); // Skip a line
    }
    }

    public static void main(String[] args) {
    Scanner input= new Scanner (System.in);

    //asking for user input of the box layout

    System.out.println("Enter number of rows: ");
    numRows=input.nextInt();
    System.out.println("Enter number of columns: ");
    numColumn=input.nextInt();
    System.out.println("Enter row height in characters: ");
    rowHeight=input.nextInt();
    System.out.println("Enter column width in characters: ");
    columnWidth=input.nextInt();

    if (numRows==0){

    }else if(numRows==1){
    firstLine();
    rowHeight();
    lastLine();
    }else{
    firstLine();
    for(int loop=0;loop<numRows;loop++){
    rowHeight();
    middleLine();


    }
    lastLine();
    }
    }
    }
    Attached Thumbnails Attached Thumbnails Looking for help with my code-untitled.png  

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default Re: Looking for help with my code

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.

    Copy the current output and paste it here. Add some comments showing what is wrong.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    SgtGump is offline Member
    Join Date
    Nov 2013
    Posts
    9
    Rep Power
    0

    Default Re: Looking for help with my code

    i know what your asking and tried but can't figure out how to do it sorry..


  4. #4
    SgtGump is offline Member
    Join Date
    Nov 2013
    Posts
    9
    Rep Power
    0

    Default Re: Looking for help with my code

    This is what I dont want..
    Attached Thumbnails Attached Thumbnails Looking for help with my code-untitled.png  

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default Re: Looking for help with my code

    That's strange, 90% of the other posters have no problem. What did you do differently?

    There are 5 horizontal lines printed. Change the code so that only 4 are printed.
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    SgtGump is offline Member
    Join Date
    Nov 2013
    Posts
    9
    Rep Power
    0

    Default Re: Looking for help with my code

    obviously I just didn't do it right..lol

    I literally just pasted my code where u said "YOUR CODE HERE"
    thats it.

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default Re: Looking for help with my code

    Try typing the [code] tags instead of copying them from my post. There are 'magic' host tags to keep the [code] tags from being recognized as MU tags
    If you don't understand my response, don't ignore it, ask a question.

  8. #8
    SgtGump is offline Member
    Join Date
    Nov 2013
    Posts
    9
    Rep Power
    0

    Default Re: Looking for help with my code

    Java Code:
    public class Assign3 {
    
    
    	private static int numColumn,columnWidth,numRows,rowHeight;
    	static char firstLine[] = {'\u2501', '\u250F', '\u2533', '\u2513'};
    			
    	static char middleLine[]={'\u2501', '\u2523', '\u254B', '\u252B'};
    
    	static char lastLine[] = {'\u2501', '\u2517', '\u253B', '\u251B'};
    
    	
    	 public static void firstLine(){
    		System.out.print(firstLine[1]+"");
    		
    		for (int first=1;first<=numColumn;first++){		//if counter is less then or equal to the number of columns it will loop
    			for (int i=1;i<=columnWidth;i++){
    				System.out.print(firstLine[0]);			//if counter is less then or equal to the width it will print unicode \u2501
    			}
    			if (first<numColumn){						//if the counter is less then column num print unicode \u2533
    				System.out.print(firstLine[2]);
    			}else{
    				System.out.print(firstLine[3]+"\n");		//else print unicode \u2513
    			}
    		}
    	}
    	public static void middleLine(){
    		
    		
    		System.out.print(middleLine[1]+"");
    		
    		for (int first=1;first<=numColumn;first++){		//if counter is less then or equal to the number of columns it will loop
    			for (int i=1;i<=columnWidth;i++){
    				System.out.print(middleLine[0]);			//if counter is less then or equal to the width it will print unicode \u2501
    			}
    			if (first<numColumn){						//if the counter is less then column num print unicode \u254B
    				System.out.print(middleLine[2]);
    			}else{
    				System.out.print(middleLine[3]+"\n");		//else print unicode \u252B
    			}
    		}
    	}	
    	
    	public static void lastLine(){
    		System.out.print(lastLine[1]+"");				// print unicode \u2517
    		
    		for (int last=1;last<=numColumn;last++){
    			for(int y=1;y<=columnWidth;y++){
    				System.out.print(lastLine[0]);			//print unicode \u2501
    			}
    			if (last<numColumn){
    				System.out.print(lastLine[2]);			//print unicode \u253B
    			}else{
    				System.out.print(lastLine[3]+"\n");			//print unicode \u251B
    			}
    		}
    	}
    	
    		
    	public static void rowHeight(){
    		for (int loop=1;loop<=rowHeight;loop++){
    		for (int mid=0;mid<=numColumn;mid++){				
    			System.out.print("\u2503");				
    			for (int x=1;x<=columnWidth;x++){
    				System.out.print("\u2002"+"\u2002"+"\u200a");			//if counter is less then or equal to width print out a space
    			}
    			
    			
    		}
    			System.out.print("\n");					// Skip a line
    		}
    	}
    	
    	public static void main(String[] args) {
    	Scanner input= new Scanner (System.in);
    		
    		//asking for user input of the box layout
    	
    	System.out.println("Enter number of rows: ");
    	numRows=input.nextInt();
    	System.out.println("Enter number of columns: ");
    	numColumn=input.nextInt();
    	System.out.println("Enter row height in characters: ");
    	rowHeight=input.nextInt();
    	System.out.println("Enter column width in characters: ");
    	columnWidth=input.nextInt();
    		
    		if (numRows==0){
    			
    		}else if(numRows==1){
    			firstLine();
    			rowHeight();	
    			lastLine();
    		}else{
    				firstLine();                                               //this is where the problem is
    			for(int y=0;y<numRows;y++){
    				rowHeight();
    				middleLine();
    		
    	}
    			lastLine();
    	}
    }
    }
    Last edited by SgtGump; 11-19-2013 at 05:19 AM.

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default Re: Looking for help with my code

    The code has lost all its formatting. All the statements start in the first column. Logically nested statements should be indented.
    If you don't understand my response, don't ignore it, ask a question.

  10. #10
    SgtGump is offline Member
    Join Date
    Nov 2013
    Posts
    9
    Rep Power
    0

    Default Re: Looking for help with my code

    got it now ,that better?

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default Re: Looking for help with my code

    Yes, except for the main() method.

    Have you found where the extra line is being printed?

    There are 5 horizontal lines printed. Can you change the code so that only 4 are printed.
    If you don't understand my response, don't ignore it, ask a question.

  12. #12
    SgtGump is offline Member
    Join Date
    Nov 2013
    Posts
    9
    Rep Power
    0

    Default Re: Looking for help with my code

    well the very first and last dont count because they are diffferent.
    So i only need 2 instead of 3 middleLine().

  13. #13
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default Re: Looking for help with my code

    When I use this to provide input to the program, I get lots of ????s
    Java Code:
       Scanner input= new Scanner ("12 12 12 12"); //System.in);  // get input from String vs keyboard
    If you don't understand my response, don't ignore it, ask a question.

  14. #14
    SgtGump is offline Member
    Join Date
    Nov 2013
    Posts
    9
    Rep Power
    0

    Default Re: Looking for help with my code

    in eclipse: 1. you need to go to windows
    2. preferences
    3.In the menu at the left, select General, then Appearance, and finally Colors and Fonts. In the Colors and Fonts window at right, select the first item, which should be ‘Console font (overrides default Text Font)’

    4. Select Courier New from the list of fonts. Select OK, and then from the Preferences dialog select OK again
    5.Back in the main menu, Select Run and then select the menu item Run Configurations…
    6.In the Run Configurations Dialog, select the name of your Java Application from the menu at left, and then click on the Common tab on the right side of the dialog box. In the resulting dialog window, under Encoding, change the selection from the Default button to ‘Other’ and select UTF-8. Then click on the Close button at the bottom.

  15. #15
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default Re: Looking for help with my code

    What does eclipse have to do with my suggestion for giving the user's input via a String in the Scanner's constructor?

    I use the command prompt for executing programs. I don't use eclipse.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 1
    Last Post: 03-25-2012, 02:40 AM
  2. Replies: 16
    Last Post: 01-31-2012, 08:36 PM
  3. Replies: 0
    Last Post: 08-07-2011, 08:32 PM
  4. Replies: 0
    Last Post: 02-21-2011, 11:50 AM
  5. Replies: 1
    Last Post: 04-26-2007, 03:52 PM

Tags for this Thread

Posting Permissions

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