Results 1 to 8 of 8

Thread: java output arrangement

  1. #1
    Senior Member
    Join Date
    Dec 2003
    Posts
    317

    java output arrangement

    i'm making a little skill calculator program for me and my friends to use and i'm having a problem with lining up the output. basically, depending on which class they choose at the beginning, the next section will have the attributes labeled accordingly. well, this throws off the alignment because if i alter it to look good for one class it will look bad for the others. im basically using tabs to line them up like this:
    swordsmanship: 2 cost for next point: 2
    swordsmanship: 2 cost for next point: 2
    swordsmanship: 2 cost for next point: 2
    anybody know a way that i can set this up so that it will always have the same amount of space between?

    here's the code if you want to see it, the first option(warrior/monk) is lined up allright, but the second option(necromancer/mesmer)

    Code:
    import java.io.*;
    class stats {
    	int totattrib;
    	int attribcost1, attribcost2, attribcost3, attribcost4, attribcost5, attribcost6, attribcost7, attribcost8;
    	int attrib1, attrib2, attrib3, attrib4, attrib5, attrib6, attrib7, attrib8;
    
    	stats(int a, int b, int c){
    	totattrib=a;
    	attribcost1=b;
    	attribcost2=b;
    	attribcost3=b;
    	attribcost4=b;
    	attribcost5=b;
    	attribcost6=b;
    	attribcost7=b;
    	attribcost8=b;
    	attrib1=c;
    	attrib2=c;
    	attrib3=c;
    	attrib4=c;
    	attrib5=c;
    	attrib6=c;
    	attrib7=c;
    	attrib8=c;
    	}
    }
    
    
    class calc {
    	private static BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
    	public static void main (String args[]) throws java.io.IOException {
    
    	String attribute1="a",attribute2="a",attribute3="a",attribute4="a",attribute5="a",attribute6="a",attribute7="a",attribute8="a";
    
    	stats character = new stats(100,1,0);
    
    System.out.println("Select your character class");
    System.out.println("1. Warrior/monk");
    System.out.println("2. Necromancer/Mesmer");
    
    
    String input1=stdin.readLine();
    int input2=Integer.parseInt(input1);
    
    switch(input2) {
    case 1:
    attribute1="Swordsmanship";
    attribute2="Axe Mastery";
    attribute3="Hammer Mastery";
    attribute4="Strength";
    attribute5="Tactics";
    attribute6="Healing prayers";
    attribute7="Protection prayers";
    attribute8="Smiting Prayers";
    break;
    case 2:
    attribute1="Soul Reaping";
    attribute2="Curses";
    attribute3="Death Magic";
    attribute4="Blook Magic";
    attribute5="Illusions";
    attribute6="Domination";
    attribute7="Fast Casting";
    attribute8="Inspiration";
    break;
    }
    
    while(character.totattrib>=0) {
    System.out.println();
    System.out.println("Allocate your points, enter 1 for attribute1, 2 for attrib2 and so on...");
    System.out.println();
    System.out.println("1. "+attribute1+":	"+character.attrib1+"	cost for next point:"+character.attribcost1);
    System.out.println("2. "+attribute2+":		"+character.attrib2+"	cost for next point:"+character.attribcost2);
    System.out.println("3. "+attribute3+":	"+character.attrib3+"	cost for next point:"+character.attribcost3);
    System.out.println("4. "+attribute4+":		"+character.attrib4+"	cost for next point:"+character.attribcost4);
    System.out.println("5. "+attribute5+":		"+character.attrib5+"	cost for next point:"+character.attribcost5);
    System.out.println("6. "+attribute6+":	"+character.attrib6+"	cost for next point:"+character.attribcost6);
    System.out.println("7. "+attribute7+":	"+character.attrib7+"	cost for next point:"+character.attribcost7);
    System.out.println("8. "+attribute8+":	"+character.attrib8+"	cost for next point:"+character.attribcost8);
    System.out.println();
    System.out.println("points left:"+character.totattrib);
    System.out.println();
    
    input1=stdin.readLine();
    input2=Integer.parseInt(input1);
    
    switch(input2) {
    case 1:
    character.attrib1++;
    character.totattrib=character.totattrib-character.attribcost1;
    character.attribcost1++;
    break;
    case 2:
    character.attrib2++;
    character.totattrib=character.totattrib-character.attribcost2;
    character.attribcost2++;
    break;
    case 3:
    character.attrib3++;
    character.totattrib=character.totattrib-character.attribcost3;
    character.attribcost3++;
    break;
    case 4:
    character.attrib4++;
    character.totattrib=character.totattrib-character.attribcost4;
    character.attribcost4++;
    break;
    case 5:
    character.attrib5++;
    character.totattrib=character.totattrib-character.attribcost5;
    character.attribcost5++;
    break;
    case 6:
    character.attrib6++;
    character.totattrib=character.totattrib-character.attribcost6;
    character.attribcost6++;
    break;
    case 7:
    character.attrib7++;
    character.totattrib=character.totattrib-character.attribcost7;
    character.attribcost7++;
    break;
    case 8:
    character.attrib8++;
    character.totattrib=character.totattrib-character.attribcost8;
    character.attribcost8++;
    break;
    default:
    System.out.println("what's the matter with you?");
    }
    
    	}
    
    }
    }

  2. #2
    Banned
    Join Date
    Sep 2004
    Posts
    305
    Why not just make a two or more methods so that each class has its own respective printout method? Seems like a simpler thing and would be following OOP rather than just clustering all your calculations and etc into one method.

  3. #3
    Senior Member
    Join Date
    Dec 2003
    Posts
    317
    well, the only thing that really changes from class to class is the name of the skills, and i dont really want to have to make 18 different methods, each with different spacing. i thought maybe there was an easier way

  4. #4
    Custom User
    Join Date
    Oct 2001
    Posts
    503
    One possible way would be to work out the number of characters that are going to be displayed (using String.length()) and then add in spaces using for loops as necessary rather than using tabs.

    Also, your code is long and cluttered; I'd suggest using a few arrays with loops where you are taking lists of numbers (especially when it's the same number every time).

    ac

  5. #5
    Senior Member
    Join Date
    Dec 2003
    Posts
    317
    that sounds like a good idea. im in a java class right now and we're just getting to arrays and stuff so i'll probably use them when i learn how to

  6. #6
    Senior Member
    Join Date
    Nov 2001
    Posts
    1,255
    If you're just in Java right now, hold off until you do some GUI stuff. It will be far simpler for you then IMO.
    Btw, nice to see a fellow GWer here on AO.
    Chris Shepherd
    The Nelson-Shepherd cutoff: The point at which you realise someone is an idiot while trying to help them.
    \"Well as far as the spelling, I speak fluently both your native languages. Do you even can try spell mine ?\" -- Failed Insult
    Is your whole family retarded, or did they just catch it from you?

  7. #7
    Senior Member
    Join Date
    Dec 2003
    Posts
    317
    im really excited about guild wars, i preordered it so i could play the beta events. the only reason i really created this program was cuz i was having a hard time planning my character's attribute points. you know how the price to add to a point increases for every point you have in it? i kept loosing track of that. then my friends wanted to use it so i was gonna try to modify it for all the different class types

  8. #8
    Senior Member
    Join Date
    Nov 2001
    Posts
    1,255
    I've seen a couple of web ones, and one that ran on .NET. Check out www.guild-hall.net, they have a thread in their strategy forum that details the apps like that that exist.

    I know it's not the same as writing it yourself, but if you need it working and aren't knowledgeable enough, there's nothing wrong with using someone else's app.

    I'd normally give you some detailed help, but it's coming up on end of semester crunch time (all next week), so I'm afraid I don't really have the time until later.
    Chris Shepherd
    The Nelson-Shepherd cutoff: The point at which you realise someone is an idiot while trying to help them.
    \"Well as far as the spelling, I speak fluently both your native languages. Do you even can try spell mine ?\" -- Failed Insult
    Is your whole family retarded, or did they just catch it from you?

Posting Permissions

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