Write a program NamePrinter that displays your name inside a box on th

Duplicate topics --- Topics merged

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 10125 Views - Last Post: 30 June 2011 - 09:16 PM Rate Topic: -----

#1 tiger200687  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 14-January 09

Write a program NamePrinter that displays your name inside a box on th

Posted 14 January 2009 - 08:48 AM

Just like the title says I need help creating and Writing a program NamePrinter that displays your name inside a box on the console screen
Is This A Good Question/Topic? 0
  • +

Replies To: Write a program NamePrinter that displays your name inside a box on th

#2 ayman_mastermind  Icon User is offline

  • human.setType("geek");
  • member icon

Reputation: 126
  • View blog
  • Posts: 1,860
  • Joined: 12-December 08

Re: Write a program NamePrinter that displays your name inside a box on th

Posted 14 January 2009 - 08:59 AM

Can you please show us your code(where you are exactly stuck)? and please be more specific, and what do you mean by box on the console screen? oh and make sure to add code tags to the code that you show....
thanks and good luck :)
Was This Post Helpful? 0
  • +
  • -

#3 tiger200687  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 14-January 09

Re: Write a program NamePrinter that displays your name inside a box on th

Posted 14 January 2009 - 09:01 AM

I need help making a namebox with my name in it the attached document will explain

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#4 tiger200687  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 14-January 09

Re: Write a program NamePrinter that displays your name inside a box on th

Posted 14 January 2009 - 09:06 AM

hey i can add the attachment im stuck on the first thing i dont even know how to begin I did the last part of the assignment the code was there we just had to change it around but as far as the first thing goes the name in the box im just stuck

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#5 tiger200687  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 14-January 09

Re: Write a program NamePrinter that displays your name inside a box on th

Post icon  Posted 14 January 2009 - 09:33 AM

public class NamePrinter
{
public static void main(String[] args)
{
System.out.println();
}
}


Its explained in the attachment but I keep getting stuck

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#6 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 521
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

Re: Write a program NamePrinter that displays your name inside a box on th

Posted 14 January 2009 - 09:33 AM

If it's in the console...all you have to do is use println() statements...It's not that hard. You don't have to use variables or anything.

This post has been edited by Locke37: 14 January 2009 - 09:34 AM

Was This Post Helpful? 1
  • +
  • -

#7 ayman_mastermind  Icon User is offline

  • human.setType("geek");
  • member icon

Reputation: 126
  • View blog
  • Posts: 1,860
  • Joined: 12-December 08

Re: Write a program NamePrinter that displays your name inside a box on th

Posted 14 January 2009 - 09:33 AM

okay i wrote you a sample program that does exactly what you want:
public class NamePrinter {
	public static void main(String[] args){
		System.out.println("+----+");
		System.out.println("|DAVE|");
		System.out.println("+----+");
	}
}


I wrote it to show you how to do it, now you will have to learn how!
anyways, hope this helps try it, and good luck in your programming ;)
Was This Post Helpful? 1
  • +
  • -

#8 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 521
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

Re: Write a program NamePrinter that displays your name inside a box on th

Posted 14 January 2009 - 09:37 AM

Please don't make duplicate topics, refer to your other one.
Was This Post Helpful? 0
  • +
  • -

#9 Christopher Elison  Icon User is offline

  • D.I.C Head

Reputation: 39
  • View blog
  • Posts: 230
  • Joined: 29-December 08

Re: Write a program NamePrinter that displays your name inside a box on th

Posted 14 January 2009 - 09:38 AM

It's really very simple, what you basically need to do is:
  • Prompt for the name to be input
  • Get the name input from the console and put it into a name string
  • Find the length of the name string
  • Then draw the top line of the box and loop through n amount of times to draw "-"
  • Write out the name on the next line
  • Repeat the top line for the bottom line

Was This Post Helpful? 0
  • +
  • -

#10 BigAnt  Icon User is offline

  • May Your Swords Stay Sharp
  • member icon

Reputation: 101
  • View blog
  • Posts: 2,392
  • Joined: 16-August 08

Re: Write a program NamePrinter that displays your name inside a box on th

Posted 14 January 2009 - 09:41 AM

Post the problem in the post not as an attachment.

**Also only post one new topic not 3 :(

This post has been edited by BigAnt: 14 January 2009 - 09:42 AM

Was This Post Helpful? 0
  • +
  • -

#11 Christopher Elison  Icon User is offline

  • D.I.C Head

Reputation: 39
  • View blog
  • Posts: 230
  • Joined: 29-December 08

Re: Write a program NamePrinter that displays your name inside a box on th

Posted 14 January 2009 - 11:03 AM

Because I'm such a nice person and also because I'm procrastinating from doing other stuff, here's an example I whipped up which will take an arbitrary name and then print it out in a neat little box like in your example:

/* 
	NamePrinter - Command line program to print out someone's name in a 'pretty' box
	Author:	Christopher Elison
	Date:	  14 January 2009
*/

import java.io.*;

public class NamePrinter {
	public static void drawbox(String name) {
		int length = name.length();	// Integer to hold name length
		
		// Print out top line of box
		System.out.print("+");
		for (int i = 0; i < length; i++) {
			System.out.print("-");
		}
		System.out.print("+\n");
   		
   		// Print out name
		System.out.println("|" + name + "|");
		
		// Print bottom line of box
		System.out.print("+");
		for (int i = 0; i < length; i++) {
			System.out.print("-");
		}
		System.out.print("+\n");
	}
	
	public static void main(String[] args) throws IOException { 	
		String name = "";  // String to hold person's name
		
		InputStreamReader input = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(input);
		
		// Prompt user to enter their name
		System.out.print("Enter your name: ");
		
		try {
			name = reader.readLine();	
		} catch(Exception e){}
		
		// Call the drawbox function, passing the name to it
		drawbox(name);
	}
}



The result:

Enter your name: Chris
+-----+
|Chris|
+-----+

Enter your name: Dream In Code
+-------------+
|Dream In Code|
+-------------+

This post has been edited by Christopher Elison: 14 January 2009 - 11:22 AM

Was This Post Helpful? 0
  • +
  • -

#12 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8334
  • View blog
  • Posts: 31,858
  • Joined: 06-March 08

Re: Write a program NamePrinter that displays your name inside a box on th

Posted 14 January 2009 - 06:14 PM

STOP those multiple postings !!! And quick :angry: :angry: :angry: :angry:
Was This Post Helpful? 0
  • +
  • -

#13 hotoma  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 05-June 09

Re: Write a program NamePrinter that displays your name inside a box on th

Posted 05 June 2009 - 07:26 AM

I understand how to make the box, but how do i make it tight around the characters ?

my code is :
public class NamePrinter {
public static void main (String []args) {

System.out.println (" +----+");
System.out.println (" |Luke|");
System.out.println (" +----+");
}

}

but i compile it and the lines dont connect? where am i going wrong sorry im new to this :)
Was This Post Helpful? 0
  • +
  • -

#14 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 521
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

Re: Write a program NamePrinter that displays your name inside a box on th

Posted 05 June 2009 - 11:36 AM

First of all...:code:

Second, don't hijack other people's topics. And since this one is almost 5 months old...that's also a no no. Just create your own new topic, but only create ONE topic per question/problem.

Third, about your problem, you just have fiddle around with the spaces and see what lines up and what doesn't.

This post has been edited by Locke: 05 June 2009 - 11:37 AM

Was This Post Helpful? 0
  • +
  • -

#15 alexC1984  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 30-June 11

Re: Write a program NamePrinter that displays your name inside a box on th

Posted 30 June 2011 - 02:24 PM

View Posthotoma, on 05 June 2009 - 07:26 AM, said:

I understand how to make the box, but how do i make it tight around the characters ?

my code is :
public class NamePrinter {
public static void main (String []args) {

System.out.println (" +----+");
System.out.println (" |Luke|");
System.out.println (" +----+");
}

}

but i compile it and the lines dont connect? where am i going wrong sorry im new to this :)



+----+
|Dave|
+----+
+-------------+
|Ion Alexandru|
+-------------+



This is how I have done it. Hope it helps.
public class NameP {
            public static void main(String[] args) {
                  NamePrinter("Dave");
                  NamePrinter("Ion Alexandru");
            }

public static void NamePrinter(String name) {
        /* top line */
	 System.out.print("+");
         //you start from the first position with the "+" sign 
         // after the "+" sign you continue to print "-" sign 
         // "-" sign is equal with the length of the name that you are putting as parameter ( our case: "Dave")
	 for(int i=0;i<name.length();i++) {
		 System.out.print("-");
	 }
	 System.out.println("+");
	 
         //prints the name  followed by "|" sign 
	 System.out.println("|" + name + "|");


         /* bottom line  same thing as top line*/	 
	 System.out.print("+");
	 for(int i=0;i<name.length();i++) {
		 	System.out.print("-");
	 }
	 System.out.println("+");
	 }
	
}

}


Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2