Results 1 to 4 of 4
  1. #1
    dokumar is offline Member
    Join Date
    Nov 2013
    Posts
    2
    Rep Power
    0

    Default Dispaly dates in Java without using Date class

    I have problem to displaydates?....

    import java.lang.*; //all import statements must be first
    import java.util.Scanner; //program uses class Scanner
    import java.text.*;


    public class Adate {


    private int year;
    private int month;
    private int day;



    public Adate()
    {
    year= 1900;
    month=01;
    day= 01;
    //System.out.printf("Date object constructor for date %s\n", this );
    }

    public Adate(int myYear, int myMonth, int myDay)
    {
    year= myYear;
    month= myMonth;
    day=myDay;

    }

    //----------------------------------------------------------------------

    public int checkMyYear( )
    {
    Scanner input = new Scanner( System.in );
    System.out.print( "Enter year: " ); // prompt
    year = input.nextInt(); // read first number from user
    if ( year >= 2000 ) // validate year
    return year;

    else // Year is invalid
    throw new IllegalArgumentException( "Year is must be greater than or equal to 2000" );
    }

    //----------------------------------------------------------------------

    public int checkMyMonth( )
    {

    Scanner input = new Scanner( System.in );
    System.out.print( "Enter month: " ); // prompt
    month = input.nextInt(); // read first number from user
    if ( month > 0 && month <= 12 ) // validate month
    return month;

    else // month is invalid
    throw new IllegalArgumentException( "month must be 1-12" );
    //System.out.printf( "The date is : " month ); // prompt
    }

    //--------------------------------------------------------------------------

    public int checkMyDay( )
    {
    Scanner input = new Scanner( System.in );
    System.out.print( "day: " ); // prompt
    day = input.nextInt(); // read first number from user
    if ( day > 0 && day <= 31 ) // validate month
    return day;

    else // month is invalid
    throw new IllegalArgumentException( "Day must be 1-31" );
    }

    //-----------------------------------------------------------------------------


    public String StringtoString()
    {
    //return month + "/" + day + "/" + year;
    //return year;

    // return String.format( "Year %s ",
    // year );

    return String.format( "%d/%d/%d ",
    year, month, day );
    }


    }


    ------------------------------------------------------------------------------

    public class Bdate {




    private Adate invoiceDate;
    private Adate todayDate;
    int checkYear;




    public static void main (String args[]) {



    Adate out = new Adate();
    out.checkMyYear();
    out.checkMyMonth();
    out.checkMyDay();


    //System.out.printf( "%d/%d/%d ",
    // Adate.toString() ); // prompt
    //System.out.toString.format( );

    System.out.println(out);



    }
    }

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,029
    Rep Power
    6

    Default Re: Dispaly dates in Java without using Date class

    First, read the Forum Rules
    Second, please post your code between code tags [CODE][/CODE] .

    Third, do you have a question?

    Regards,
    Jim
    Last edited by jim829; 11-16-2013 at 02:24 AM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    dokumar is offline Member
    Join Date
    Nov 2013
    Posts
    2
    Rep Power
    0

    Default Re: Dispaly dates in Java without using Date class

    Dear James;
    I have problem in output..

    Adate@6025e7
    thanks for your time

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: Dispaly dates in Java without using Date class

    This is the output you get when you attempt to print an object. You need to write your own toString method for the class.

Similar Threads

  1. Integer Dates to String Dates Problem
    By HelpingIsCaring in forum New To Java
    Replies: 32
    Last Post: 08-23-2013, 01:29 AM
  2. Date() class to get current date
    By bigmac15 in forum New To Java
    Replies: 1
    Last Post: 06-28-2011, 10:17 PM
  3. Dispaly data from mysql database into JSP.
    By kritijain in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 06-16-2011, 09:17 AM
  4. dispaly data in a JTable from database using NET Beans
    By kishore rajkumar in forum AWT / Swing
    Replies: 1
    Last Post: 08-17-2009, 11:44 AM
  5. Dispaly of CGM Images and automatic Hotspotting
    By dkaja in forum Advanced Java
    Replies: 2
    Last Post: 04-08-2008, 09:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •