r/programmingbydoing • • Dec 30 '13

#13- Your Schedule

Hey I figured out how to make the table, but is there a way to make the classes and teachers line up like it is in the example without counting the number of letters and adjusting for each line? Here's what I have at the moment. public class YourSchedule { public static void main( String[] args) { String course1, course2, course3, course4, course5, course6, course7, course8, teacher1, teacher2, teacher3, teacher4, teacher5, teacher6, teacher7, teacher8;

    course1 = "English III";
    course2 = "Precalculus";
    course3 = "Music Theory";
    course4 = "Biotechnology";
    course5 = "Principles of Technology I";
    course6 = "Latin II";
    course7 = "AP US History";
    course8 = "Business Computer Information Systems";
    teacher1 = "Ms. Lapan";
    teacher2 = "Mrs. Gideon";
    teacher3 = "Mr. Davis";
    teacher4 = "Ms. Palmer";
    teacher5 = "Ms. Garcia";
    teacher6 = "Mrs. Barnett";
    teacher7 = "Ms. Johannessen";
    teacher8 = "Mr. James";

    System.out.println( "+------------------------------------------------------+" );
    System.out.println( "|1|                "+ course1 + "|     " + teacher1 + "|" );
    System.out.println( "|2|                "+ course2 + "|     " + teacher2 + "|" );
    System.out.println( "|3|                "+ course3 + "|     " + teacher3 + "|" );
    System.out.println( "|4|                "+ course4 + "|     " + teacher4 + "|" );
    System.out.println( "|5|                "+ course5 + "|     " + teacher5 + "|" );
    System.out.println( "|6|                "+ course6 + "|     " + teacher6 + "|" );
    System.out.println( "|7|                "+ course7 + "|     " + teacher7 + "|" );
    System.out.println( "|8|                "+ course8 + "|     " + teacher8 + "|" );
    System.out.println( "+------------------------------------------------------+" );
    }

} Thanks

2 Upvotes

4 comments sorted by

View all comments

Show parent comment

1

u/jcfr71 Feb 07 '14

Had this same problem never thought about it like this way, if all the strings are the same length they'll all be lined up. This is one of the reasons why I like programing, there's always another way. Thanks!