Hey all
Well this may seem miniscule to some of the Java programmers out there but I feel this is something to be proud of... I've been using C since I got into Linux and Programming and lately decided to make the move to a more powerful GUI language - thus I chose Java
This is what I wrote:
Code:
import java.util.*;
public class ClockTalk {
public static String getPrefix(String prefix, int day) {
switch(day) {
case(1)|(21)|(31):
return("st");
case(2)|(22):
return("nd");
case(3)|(23):
return("rd");
default:
return("th");
}
}
public static void main(String[] arguments) {
Calendar now = Calendar.getInstance();
int hour = now.get(Calendar.HOUR_OF_DAY);
int minute = now.get(Calendar.MINUTE);
int month = now.get(Calendar.MONTH) + 1;
int day = now.get(Calendar.DAY_OF_MONTH);
int year = now.get(Calendar.YEAR);
String prefix = "";
// Display greeting
if(hour < 12)
System.out.println("Good morning.\n");
else if(hour < 17)
System.out.println("Good afternoon.\n");
else
System.out.println("Good evening.\n");
// Begin time message by showing the minutes
System.out.print("It's");
System.out.print(" " + hour + ":" + minute + " on ");
// DSisplay the name of the month
switch(month) {
case(1):
System.out.print("January");
break;
case(2):
System.out.print("February");
break;
case(3):
System.out.print("March");
break;
case(4):
System.out.print("April");
break;
case(5):
System.out.print("May");
break;
case(6):
System.out.print("June");
break;
case(7):
System.out.print("July");
break;
case(8):
System.out.print("August");
break;
case(9):
System.out.print("September");
break;
case(10):
System.out.print("October");
break;
case(11):
System.out.print("November");
break;
case(12):
System.out.print("December");
break;
}
// Display the date and the year
System.out.println(" the " + day + getPrefix(prefix, day) + " " + year + ".");
}
}
In it i pass arguments between classes and also use comparisons in print()'s - in C this would've been a small achievement but getting used to another language can be quite a pain in the.... Anywho, just thought that i'd say that as much as people say that Java sux and its slow I totally disagree - well now to get into GUI stuff
Thanks LQ for all the help and all the people i've gotten to know - everyone that helps out deserves a pat on the back, this forum really helps people... I don't think theres a better feeling than being able to help someone out with their problems