How come when i put //private String namespace = “###Name:”+name+” ###”; and system.out.println(namespace) it comes out null?
I am suppose to create a tagmaker program, but I am stuck at how to line up the # on the right side.
/*################################################
### ANNUAL CONFERENCE ###
############################################### #
###Name:Simon ###
### ###
############################################### #
###Organization:NBA ###
### ###
################################################*/
How do I line them up for any given name that I set it to?
I am suppose to Set the Name, Set the organization, Print tag with the name and organization, Clear the name and organization, and Print a blank tag.
—————-UPDATE 4:09AM—————————-
I am just going to model my code after this:
public class Divers {
public static void main(String args[]){
String format = "|%1$-10s|%2$-10s|%3$-20s|\n";
System.out.format(format, "FirstName", "Init.", "LastName");
System.out.format(format, "Real", "", "Gagnon");
System.out.format(format, "John", "D", "Doe");
String ex[] = { "John", "F.", "Kennedy" };
System.out.format(String.format(format, (Object[])ex));
}
}
but can someone show me how i can do it the other way? just for learning purposes
public class AddressBookTester {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
TagMaker test = new TagMaker("Simon", "NBA");
test.printlL();
}
}
public class TagMaker {
private String name;
private String organization;
private String l = "################################################";
private String annual= "### ANNUAL CONFERENCE ###";
//private String namespace = "###Name:"+name+" ###";
private String l2= "### ###";
//private String organizationspace= "###Organization:"+organization+"###";
TagMaker (){
}
TagMaker (String tempName, String tempOrg){
name = tempName;
organization = tempOrg;
}
void setname(String tempName){
name = tempName;
}
String getname(){
return name;
}
void setorganization(String tempOrg)
{
organization = tempOrg;
}
String getorganization(){
return organization;
}
void printlL(){
System.out.println(l);
System.out.println(annual);
System.out.println(l);
System.out.println("###Name:"+name+" ###");
System.out.println(l2);
System.out.println(l);
System.out.println("###Organization:"+organization+" ###");
System.out.println(l2);
System.out.println(l);
}
}
You need to set a constant for the Maximum width (in characters) of your output. Then you can do some simple arithmetic to work out how many spaces/characters etc. you need to properly format your output.
Say if max_width = 60.
Here’s a header:
############################################################(the full 60)The you work out the indents and things based on the length in chars of the strings you’re outputting.
e.g. If you want to print
Name: Simonget the length of this and subtract from max_length, etc. etc.HTH.