0

Hi, I'm just learning to program and I'm stuck on a basic problem, printing today's date in a form typified by (e.g.) 28 February 2011

Java Syntax (Toggle Plain Text)

import java.util.*; 

    class Date 
    {
        int day, month, year;
    }

    class PrintToday 
    {
        static Date thisDay() 
        {
            Date today = new Date();
            GregorianCalendar c = new GregorianCalendar();  
            today.day = c.get(Calendar.DATE);
            today.month  = c.get(Calendar.MONTH)+1;
            today.year  = c.get(Calendar.YEAR);
            return today;
        }


        static String monthName(int m) 
        {
            if (m==1) return "January";
            else if (m==2) return "February";
            else if (m==3) return "March";
            else if (m==4) return "April";
            else if (m==5) return "May";
            else if (m==6) return "June";
            else if (m==7) return "July";
            else if (m==8) return "August";
            else if (m==9) return "September";
            else if (m==10) return "October";
            else if (m==11) return "November";
            else return "December";
        }

            public static void main(String[] args) 
        {       
               .......
        }
    }

I'm not sure how to implement these classes/methods in the main method.

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Taywin
0

You already have everything there. You need to initiate the class you implement, and then print its data out in order day, month, and year. You need to read Java tutorial for how to implement a simple class before you can go any further because your post shows that you understand NOTHING about Java...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.