Granno Posted 17 November 2008 Share Posted 17 November 2008 Basically I have written this code: /** * Describe class Xmas here. * * * Created: Thu Oct 13 18:04:31 2005 * * @author <a href="mailto:">N. D. Measor</a> * @version 1.0 */ public final class Xmas { /** * Specifies the number of days of Xmas */ public static final int NUMDAYS = 12; public static void main (String [] args) { //loop through and get the days of Xmas verses, // and print them to the console for (int i=1;i<=NUMDAYS;i++){ getVerse(i); } } /** * Create and return a String of a whole i'th verse * of the song * (NOTE: A verse ends with a blank line.) * */ public static String getVerse (int i){ for (int j=i; j>=1; j--) { getLine(j); }//for if (i==1) { System.out.println("A partridge in a pear tree."); }//if } //getVerse /** * Create and return a String of the i'th line of Xmas of the verse * * (NOTE: the repeating version of the first day of Xmas line is returned - * "And a partridge in a pear tree.") * * e.g. sixth day of Xmas, "Six geese a-laying," */ public static String getLine (int i) { switch (i){ case 1: return ("And a partridge in a pear tree."); case 2: return ("Two turtle doves,"); case 3: return ("Three French hens,"); case 4: return ("Four calling birds,"); case 5: return ("Five golden rings,"); case 6: return ("Six geese a-laying,"); case 7: return ("Seven swans a-swimming,"); case 8: return ("Eight maids a-milking,"); case 9: return ("Nine ladies dancing,"); case 10: return ("Ten lords a-leaping,"); case 11: return ("Eleven pipers piping"); case 12: return ("Twelve drummers drumming"); } } // end of method getLine /** * Converts an int value into its related ordinal (as a String) * * e.g. convert 1 to "first" */ public static String toOrdinal (int i) { switch (i) { case 1: return ("first "); case 2: return ("second "); case 3: return ("third "); case 4: return ("fourth "); case 5: return ("fifth "); case 6: return ("sixth "); case 7: return ("seventh "); case 8: return ("eighth "); case 9: return ("ninth "); case 10: return ("tenth "); case 11: return ("eleventh "); case 12: return ("twelfth "); } } // end of method toOrdinal } And the output i require is: On the first day of ChristmasMy true love gave to me, A partridge in a pear tree. On the second day of Christmas My true love gave to me, Two turtle doves, And a partridge in a pear tree. On the third day of Christmas My true love gave to me, Three French hens, Two turtle doves, And a partridge in a pear tree. On the fourth day of Christmas My true love gave to me, Four calling birds, Three French hens, Two turtle doves, And a partridge in a pear tree. On the fifth day of Christmas My true love gave to me, Five golden rings, Four calling birds, Three French hens, Two turtle doves, And a partridge in a pear tree. On the sixth day of Christmas My true love gave to me, Six geese a-laying, Five golden rings, Four calling birds, Three French hens, Two turtle doves, And a partridge in a pear tree. On the seventh day of Christmas My true love gave to me, Seven swans a-swimming, Six geese a-laying, Five golden rings, Four calling birds, Three French hens, Two turtle doves, And a partridge in a pear tree. On the eighth day of Christmas My true love gave to me, Eight maids a-milking, Seven swans a-swimming, Six geese a-laying, Five golden rings, Four calling birds, Three French hens, Two turtle doves, And a partridge in a pear tree. On the ninth day of Christmas My true love gave to me, Nine ladies dancing, Eight maids a-milking, Seven swans a-swimming, Six geese a-laying, Five golden rings, Four calling birds, Three French hens, Two turtle doves, And a partridge in a pear tree. On the tenth day of Christmas My true love gave to me, Ten lords a-leaping, Nine ladies dancing, Eight maids a-milking, Seven swans a-swimming, Six geese a-laying, Five golden rings, Four calling birds, Three French hens, Two turtle doves, And a partridge in a pear tree. On the eleventh day of Christmas My true love gave to me, Eleven pipers piping, Ten lords a-leaping, Nine ladies dancing, Eight maids a-milking, Seven swans a-swimming, Six geese a-laying, Five golden rings, Four calling birds, Three French hens, Two turtle doves, And a partridge in a pear tree. On the twelfth day of Christmas My true love gave to me, Twelve drummers drumming, Eleven pipers piping, Ten lords a-leaping, Nine ladies dancing, Eight maids a-milking, Seven swans a-swimming, Six geese a-laying, Five golden rings, Four calling birds, Three French hens, Two turtle doves, And a partridge in a pear tree. I get the following 3 compilation errors, and I can't see how to put a return statement in. --------------------Configuration: <Default>--------------------G:\CO1003 Program Design\cmc\cm_area\tg75\CO1003worksheet5exercise3\Xmas.java:41: missing return statement } //getVerse ^ G:\CO1003 Program Design\cmc\cm_area\tg75\CO1003worksheet5exercise3\Xmas.java:69: missing return statement } // end of method getLine ^ G:\CO1003 Program Design\cmc\cm_area\tg75\CO1003worksheet5exercise3\Xmas.java:94: missing return statement } // end of method toOrdinal ^ 3 errors Process completed. If anyone can help it would be fantastic. Apologies for the long post. Link to comment Share on other sites More sharing options...
Nick Posted 17 November 2008 Share Posted 17 November 2008 I can't help. Link to comment Share on other sites More sharing options...
act smiley Posted 17 November 2008 Share Posted 17 November 2008 Do you have to break from them, or is that C++? Been a while since I really had a stab at anything much, need to get going on it again. Link to comment Share on other sites More sharing options...
Granno Posted 17 November 2008 Author Share Posted 17 November 2008 Do you have to break from them, or is that C++? Been a while since I really had a stab at anything much, need to get going on it again. You can break from them, but return does the same job. It's sorted now anyway, so if a mod wants to close it Link to comment Share on other sites More sharing options...
Daggers Posted 18 November 2008 Share Posted 18 November 2008 Next time just PM SMuts directly - I taught him everything he doesn't know. Link to comment Share on other sites More sharing options...
Foxhateram Posted 10 November 2009 Share Posted 10 November 2009 Anyone got any good advice on how to J-unit testing in JAVA i have absolutely no clue where to start with it. any help would be much appreciated. Link to comment Share on other sites More sharing options...
Hitesh Posted 10 November 2009 Share Posted 10 November 2009 Anyone got any good advice on how to J-unit testing in JAVA i have absolutely no clue where to start with it. any help would be much appreciated. I've got a good guide somewhere...i'll try and dig it out. I'm working late most of this week so might be a few days before I can get it to you though (i need to find it!)...just PM me to remind me! Also, whilst on the Java theme, I'm currently working on a small application which helps you manage your personal finances - its very much WIP but its useful if you have a few accounts and want to keep track of your outgoings - the aim also is to help with budgeting and track other expenses, like company expenses. I have it in Excel atm, but its difficult to maintain. If anyone's interested in testing it then give me PM and once its at a decent stage then ill send it across! PS: Granno - what did you do to sort the issue out? Link to comment Share on other sites More sharing options...
Daggers Posted 10 November 2009 Share Posted 10 November 2009 Excel? James LOVES Excel. Link to comment Share on other sites More sharing options...
Foxhateram Posted 10 November 2009 Share Posted 10 November 2009 I've got a good guide somewhere...i'll try and dig it out. I'm working late most of this week so might be a few days before I can get it to you though (i need to find it!)...just PM me to remind me!Also, whilst on the Java theme, I'm currently working on a small application which helps you manage your personal finances - its very much WIP but its useful if you have a few accounts and want to keep track of your outgoings - the aim also is to help with budgeting and track other expenses, like company expenses. I have it in Excel atm, but its difficult to maintain. If anyone's interested in testing it then give me PM and once its at a decent stage then ill send it across! PS: Granno - what did you do to sort the issue out? Cheers very much Hitesh. Will PM you over the weekend. Much appreciated buddy. Link to comment Share on other sites More sharing options...
Stuliasz Posted 11 November 2009 Share Posted 11 November 2009 Granno, you're not at Sheff Uni are you? I remember do that exact task in one of my Java modules. Been out of the loop for a while now so probably wouldn't be as much use to you as others on here. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.