Results 1 to 8 of 8

Thread: First try at Java

  1. #1
    Join Date
    Jun 2007
    Posts
    532
    Mentioned
    1 Post(s)
    Quoted
    68 Post(s)

    Default First try at Java

    Hello guys! I am taking a Java class online at the University I attend and this is my first assignment!

    Exercise
    Write a Java program to print the following information on
    separate lines.
    1. Your name.
    2. The Department Name, Course Number, and Time for each course that you are taking this semester. Put the information for each course on a separate line.
    3. Skip two lines (see notes for explanation).
    4. The email address that you regularly use.

    Notes and Comments

    The file MUST be named as LastnamePass1.java (for example, my last name is Li, it will be named as LiPass1.java). Be sure to compile your program, correct any syntax errors, recompile until no errors, then test the program with different values. Upload only the .java file to D2L dropbox folder named Programming Assignment 1.

    Note 1:
    Use System.out.println( ) without any arguments to generate a new line character (i.e.,skip a line).
    Note 2:
    In Java, the class name and the file name must match exactly(case-sensitive).
    If the file name is LastnamePass1.java, the Java class must also be LastnamePass1. Otherwise it will fail the compiling and you will lose 20 points for this.
    Note 3:
    Please pay close attention to the indentation and spacing. Read the code in the textbook to see how you can well format the source code.





    This is my first try at it....ehhh? Better way to do it?


    Simba Code:
    public class Assignment1 {

        public static void main(String[] args){
            System.out.println("Andrew Varnick");
            System.out.println("Physics, 1930 5:10-7:20");
            System.out.println("Chemistry, 2394 2:20-5:20");
            System.out.println("Computer Science, 1015-W1");
            System.out.println("Communications, 1200-WA2");
            System.out.println();
            System.out.println();
           
        }

       
    }
    Finished B.S. Program in Radiology!!

    Projects: A big one! Total secret! hehe

  2. #2
    Join Date
    Jun 2008
    Location
    United States
    Posts
    818
    Mentioned
    60 Post(s)
    Quoted
    90 Post(s)

    Default

    You could use new line characters and have a single System.out.println() call instead of multiple.
    [10/14/13:19:03] <BenLand100> this is special relatively, just cleverly disguised with yachts

  3. #3
    Join Date
    Dec 2011
    Location
    Toronto, Ontario
    Posts
    6,424
    Mentioned
    84 Post(s)
    Quoted
    863 Post(s)

    Default

    Missing your email. (Or you left it out on purpose)

    Also, you can do:
    java Code:
    code
    for us to see better.

    Why not make an array of strings and have the program loop through it while printing? It'll give your teacher a good impression.

  4. #4
    Join Date
    Mar 2012
    Location
    127.0.0.1
    Posts
    3,383
    Mentioned
    95 Post(s)
    Quoted
    717 Post(s)

    Default

    Quote Originally Posted by Sin View Post
    Missing your email. (Or you left it out on purpose)

    Also, you can do:
    java Code:
    code
    for us to see better.

    Why not make an array of strings and have the program loop through it while printing? It'll give your teacher a good impression.
    Because I'm assuming he's never done Java and he doesn't want to get in over his head just yet. :s

  5. #5
    Join Date
    Nov 2006
    Posts
    449
    Mentioned
    84 Post(s)
    Quoted
    145 Post(s)

    Default

    Quote Originally Posted by Element17 View Post
    java Code:
    public class Assignment1 {

        public static void main(String[] args){

            System.out.println("Andrew Varnick");
            System.out.println("Physics, 1930 5:10-7:20");
            System.out.println("Chemistry, 2394 2:20-5:20");
            System.out.println("Computer Science, 1015-W1");
            System.out.println("Communications, 1200-WA2");
            System.out.println();
            System.out.println();
           
        }
       
    }
    Looks fine to me.

    Quote Originally Posted by NKN View Post
    Because I'm assuming he's never done Java and he doesn't want to get in over his head just yet. :s
    I agree with NKN. What Element17 has meets the requirements well enough (barring name and missing email), and seems to do exactly what the notes imply.

    There's no reason to complicate anything. Having multiply System.out.println statements makes the presentation of the output clear and straight forward, no need to mess about with new line characters or arrays.

    In fact, this might result in point deduction. If you want to deviate at all from what you already have, you should consult your instructor prior to implementing those changes.

    If this were anything more advanced, I'd probably suggest using a String formatter and aligning all of the class information to consistent columns. You might be able to do this manually in this case as well to get a better looking output.
    Last edited by core; 08-28-2013 at 01:19 PM.

    First they ignore you, then they laugh at you, then they fight you, then you win.
    Stance on Leechers

  6. #6
    Join Date
    Dec 2011
    Location
    The Netherlands
    Posts
    1,631
    Mentioned
    47 Post(s)
    Quoted
    254 Post(s)

    Default

    Quote Originally Posted by euphemism View Post
    You could use new line characters and have a single System.out.println() call instead of multiple.
    Would only put new line characters on the last line to keep the readability.

    Code:
    public class Assignment1 {
    
        public static void main(String[] args){
            System.out.println("Andrew Varnick");
            System.out.println("Physics, 1930 5:10-7:20");
            System.out.println("Chemistry, 2394 2:20-5:20");
            System.out.println("Computer Science, 1015-W1");
            System.out.println("Communications, 1200-WA2\n\n");
            
        }
       
    }
    Also for note 3 you can use System.out.printf http://docs.oracle.com/javase/1.5.0/...Formatter.html But it might be too advanced for this assignment already. I think manually formatting would be fine aswell (using \t for tab or just spaces)
    Last edited by J J; 08-28-2013 at 01:59 PM.

    Script source code available here: Github

  7. #7
    Join Date
    Feb 2012
    Location
    UK
    Posts
    909
    Mentioned
    10 Post(s)
    Quoted
    191 Post(s)

    Default

    Can you not just use a different print command line for printing on a new line to avoid needing at least one of the println()'s?
    Solar from RiD.

  8. #8
    Join Date
    Jun 2007
    Posts
    532
    Mentioned
    1 Post(s)
    Quoted
    68 Post(s)

    Default

    I would first like to thank everyone that added to this discussion! I did leave my e-mail out on purpose and I would also like to point out that class has only been going for 3 days lol. I wouldn't want to go to over the top on the first assignment ha, but I will probably continue to post my assignments along with MY work. I wont really be asking for help unless I don't understand something and have talked to my professor. I will just post just giving my code and ask for better ways or if I have done something wrong! It is always nice to know before you turn something in! Again thanks guys!
    Finished B.S. Program in Radiology!!

    Projects: A big one! Total secret! hehe

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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