tried that before, got an error for the dob.getDay etc. And I NEED the dob. as in dateOfBirth = new Date(dob)
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.
tried that before, got an error for the dob.getDay etc. And I NEED the dob. as in dateOfBirth = new Date(dob)
Talking of BlueJ, does anyone else have trouble with this IDE and Windows 7 Starter Edition (32-bit)? It came pre-installed on my Netbook which I purchased for College. Oddly, I think I'm doing the same or a similar course to ibby50.
Thanks to everyone for the suggestions in this thread, by the way. It's been most helpful for me too :-P
Regards,
Shaun.
Well, I've finished the assignment and handed it in (the same one that ibby50 has just finished, I think), and it seems to show the wrong way to do certain things. If you did things the right way then you'd have got no marks for it even though it would have been more efficient.
Anyway, having a look-up table is a quick and easy way to convert a month integer (ie, value of 1 - 12) to a type String. Here's a quick and dirty example
Simples? Not according to my College lecturer (or at least the one who sets the assignments). You could use the same logic and simply do something like: return monthNames[month-1] if needed.// Right, let's import the Scanner import java.util.Scanner; // Our class name class MonthToString { // This is our main proggy public static void main(String args[]) { // Here is our matrix array, which we're using as a look-up table // note: the array starts at zero, so zero is January, one is February etc... // You'll see the significant of this later. String monthNames[]= {"January","February","March","April","May","June","July", "August","September","October","November","December"}; // I like buffers, though this it not entirely necessary. String buff=""; int month=0; // Here's our loop marker: for (int i=0; i<12; i=i+1) { System.out.println("Please enter month as MM (ie, 01 is January, 05 is May and 11 is November etc...)"); System.out.print("? "); // Let's read the keyboard entry: Scanner z=new Scanner(System.in); buff=z.nextLine(); // Now, let's take the literal value of the keyboard entry and convert it into a string. // Note the substring: you have to enter 01, 02, 03 etc... rather than 1, 2, 3 for this // example, though it's not entirely necessary. The one benefit is it can eleminate keyboard // typos in certain circumstances. month=Integer.parseInt(buff.substring(0,2)); // Now we'll check if you've entered a legal month value and... if(month>0 && month<13) { // ...because the array starts at zero, we need to take one away from month to output // the correct month: System.out.println(month+" is: "+monthNames[month-1]); } else { // Okay, you've entered a invalid number, dun dun dunnnnn!!!! System.out.println("Not a valid entry"); } } } }
Regards,
Shaun.