Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Help Desperately needed...

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Help Desperately needed...

    Hey all I was wondering if someone could help me understand this code as It will unlock my ability to pass this exam tomorrow... I was good at java and now i'm totally out of date as i've barely touched it in years since I completed my HND. Anyways, I was wondering if someone could help explain this code to me? It would be so much appreciated

    public class TimeTest extends TestCase {
    public void testValidConvert24to12hour() {
    String[] times = {"0000","1200","0300","0650","1059","2159","2359"};
    String[] timeStrings = {"12:00am","12:00pm","3:00am","6:50am",
    "10:59am","9:59pm","11:59pm"};
    Time test = new Time();
    for (int x=0;x<times.length;x++){
    String result = test.convert24to12hour(times[x]);
    assertEquals("Test time "+x,timeStrings[x],result);
    }
    }
    public void testInvalidConvert24to12hour() {
    String[] times = {"12309","650","2450","1360","0675","x650","1Q50",
    "16Z0","165K"};
    Time test = new Time();
    for (int x=0;x<times.length;x++){
    String result = test.convert24to12hour(times[x]);
    assertNull("Test time "+x,result);
    }
    }
    }

    I don't actually understand where the Time test = New time Comes from.. also where the x++ is coming from. IT's very stressful as I am very unsure of this code. Is there anyway to locate it in the IDE Netbeans interface so i know what i'm linking too? This is the solution, but I am not understanding the location of this. Everything else is pretty basic to me apart form this.
    Last edited by JavaPF; November 30th, 2010 at 01:56 PM. Reason: Please use [highlight=Java] code [/highlight] tags


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Help Desperately needed...

    Hello SBOSlayer, welcome to the Java Programming Forums

    String[] times = {"0000","1200","0300","0650","1059","2159","2359"};
    String[] timeStrings = {"12:00am","12:00pm","3:00am","6:50am","10:59am","9:59pm","11:59pm"};

    times and timeStrings are both String arrays.

    for (int x=0;x<times.length;x++){
    String result = test.convert24to12hour(times[x]);
    assertEquals("Test time "+x,timeStrings[x],result);
    }

    This is a for loop which loops through the times array. It loops by the amount of values in the array. This is what times.length is.

    x is the integer variable defined in the for loop. x++ means increment itself by 1.

    I hope this helps.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  3. The Following User Says Thank You to JavaPF For This Useful Post:

    SBOSlayer (November 30th, 2010)

  4. #3
    Junior Member
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Help Desperately needed...

    Thank you so much for your help Was informative and helpful

    I am however, still trying to work out where: Time test = new Time(); comes from exactly? It's a problem I am experiencing in most codes. Is it possibly located somewhere in the testing of this code? I have two .jars to work from... I can't seem to see the source code for them, I guess i'm doing something wrong, but I figured that the Time test = new time would be referenced from that?

    I would be so much in ur debt if you could help me with this aspect also. I am very grateful for the info so far

  5. #4
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Help Desperately needed...

    No problem, glad I could help.

    Maybe you are meant to create the Time class yourself? Create a class in the same package called Time..

    Either that or it's an import.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. help needed ,,, please
    By dpes in forum What's Wrong With My Code?
    Replies: 7
    Last Post: October 7th, 2010, 09:03 AM
  2. help needed
    By The Lost Plot in forum Loops & Control Statements
    Replies: 4
    Last Post: March 16th, 2010, 03:55 AM
  3. [SOLVED] Help needed!
    By subhvi in forum Web Frameworks
    Replies: 4
    Last Post: February 18th, 2010, 09:26 AM
  4. [SOLVED] A little help needed..
    By JavaStudent87 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 22nd, 2010, 06:54 PM
  5. Desperately in need of help
    By Idy in forum Web Frameworks
    Replies: 0
    Last Post: January 17th, 2010, 02:00 PM