Results 1 to 2 of 2
- 11-30-2010, 06:55 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 1
- Rep Power
- 0
Desperate for some help if possible :(
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","1Q5 0",
"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.
Thanx in advance :)
- 11-30-2010, 10:44 PM #2
Member
- Join Date
- Nov 2010
- Posts
- 33
- Rep Power
- 0
The statement "Time test = new Time();" is instantiating an object called "test" of class "Time", where Time() is the constructor for the class.
The "x++" is nothing but the iterator for the "for" loop. The loop starts with x equal to zero on the first iteration. Each subsequent iteration increments x by 1 (this is what x++ does), until the value of x is no longer less than times.length.
You might want to review basic things like classes, objects, and loops before your exam. Good luck with that!
Similar Threads
-
In Desperate need for a good swing website
By Loop in forum New To JavaReplies: 4Last Post: 09-30-2008, 02:23 PM -
Multithreading + Networking (desperate)
By bluebarca in forum New To JavaReplies: 1Last Post: 11-07-2007, 02:14 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks