LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General > LinuxQuestions.org Member Success Stories
User Name
Password
LinuxQuestions.org Member Success Stories Just spent four hours configuring your favorite program? Just figured out a Linux problem that has been stumping you for months?
Post your Linux Success Stories here.

Notices


Reply
  Search this Thread
Old 04-06-2004, 02:03 AM   #1
AMMullan
Member
 
Registered: Sep 2003
Location: United Kingdom
Distribution: Ubuntu, Arch
Posts: 438

Rep: Reputation: 30
Simple Java Joy


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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
java, simple program help needed.. marlor Programming 1 11-04-2004 02:40 PM
Simple Browser in Java LinuxTiro Programming 14 08-02-2004 03:16 PM
simple java question? Schizo265 Programming 2 07-15-2003 04:20 AM
Time To Sing The "Happy Happy Joy Joy" Song! KungFuHamster General 8 06-25-2003 01:59 PM
Simple Java question Citizen Bleys Programming 6 04-04-2002 02:16 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General > LinuxQuestions.org Member Success Stories

All times are GMT -5. The time now is 02:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration