Please help me...how to implement a class DateAndTime.java

I have a class named DateAndTime.java How should I implement a method which allows me to check if the date entered by user is valid or not?. Also when the hour continues to a next day, how should I implement a method for a nextDay()? Thank you
class DateAndTime
     private int hour, minute, second, month, day, year;
     Constructor to initialize DateAndTime.
     Default DateAndTime 0:0:0 1/1/1
     public DateAndTime()
     {     month = 1;
          day =1;
          year =1;
     Constructor to set DateAndTime to specific values.
     Calls member function setDate and setTime to set variables.
     @param h hour of the DateAndTime
     @param m minute of the DateAndTime
     @param s second of the DateAndTime
     @param mo month of the DateAndTime
     @param d day of the DateAndTime
     @param y year of the DateAndTime
     public DateAndTime(int h, int m, int s, int mo, int d, int y)// CONSTRUCTOR
     {     if (isValidDate(mo, d, y))    //if date entered is valid, the date and time will be set
               setDate(mo, d, y);
               setTime(h, m, s);
          else
               System.out.println("Invalid Date :" + mo + "/" + d + "/" + y);
               setDate(1,1,1);
     Set the values of hour, minute, and second.
     @param h hour of the DateAndTime
     @param m minute of the DateAndTime
     @param s second of the DateAndTime
     public void setTime( int h, int m, int s ) //DEFINING SETTERS, SETTING time,hour,minute,and second,
     setHour( h );
     setMinute( m );
     setSecond( s );
     Set the hour if valid or to default 0.********************SET HOUR
     public void setHour( int h )
     {     hour = ( h >= 0 && h < 24 ) ? h : 0;     }
     Set the minute if valid or to default 0.******************SET MINUTE
     public void setMinute( int m )
     {     minute = ( m >= 0 && m < 60 ) ? m : 0;     }
     Set the hour if valid or to default 0. ******************SET SECOND
     public void setSecond( int s )
     {     second = ( s >= 0 && s < 60 ) ? s : 0;     }
     Set the values of month, day, and year.
     @param mo month of the DateAndTime
     @param d day of the DateAndTime
     @param y year of the DateAndTime
     public void setDate(int mo, int d, int y)//DEFINING SETTERS, SETTING DATE FOR month,day,and Year
          setMonth(mo);
          setDay(d,mo,y);
          setYear(y);
     Set the month if valid or to default 1. ****************SET MONTH
     public void setMonth(int mo)
     {     month = (mo >= 1 && mo <= 12)? mo : 1;  }
     Set the day if valid or to default 1. ****************SET DAY
     public void setDay(int d, int mo, int y) // ?????
     {     day = (isValidDate(mo,d,y))? d : 1;  }
     Set the year if valid or to default 1. ****************SET YEAR
     public void setYear(int y)
     {     year = (y >=1)? y : 1;     }
     Get the hour value.
     @return int
     public int getHour() {   return hour;  } //DEFINING GETTERS get hour, minute, second
     Get the minute value.
     @return int
     public int getMinute() {   return minute;  }
     Get the second value.
     @return int
     public int getSecond() {   return second;  }
     Get the month value.
     @return int
     public int getMonth() {   return month;  } //DEFINING GETTERS get month, day, and year
     Get the day value.
     @return int
     public int getDay() {   return day;  }
     Get the year value.
     @return int
     public int getYear() {   return year;  }
     Finds whether a given date is a valid date in A.D..
     @param mo month of the DateAndTime.
     @param d day of the DateAndTime.
     @param y year of the DateAndTime.
     @return boolean valid or not
     public static boolean isValidDate(int mo, int d, int y)
     //your code goes here
          return true;
     Print time DateAndTime in military format.
     public void printMilitary()
     System.out.println( month + "/" + day + "/" + year + "\t"
               + ( hour < 10 ? "0" : "" ) + hour + ":"
     + ( minute < 10 ? "0" : "" ) + minute);
     Formats DateAndTime for printing.
     @return String
     public String toString()
     return ( month + "/" + day + "/" + year + "\t"
               + (( hour == 0 || hour == 12 ) ? 12 : hour % 12)
     + ":" + ( minute < 10 ? "0" : "" ) + minute
     + ":" + ( second < 10 ? "0" : "" ) + second
     + ( hour < 12 ? " AM" : " PM" ));
     Increments DateAndTime by one second.
     Hint: calls nextDay() if tick() results in going in to next day.
     public void tick()
          //Your code goes here
second++;
if (second >59)
     second = 0;
     minute++;
if (minute > 59)
     minute = 0;
          hour++;
          if(hour >23)
     //      hour = 0;
     nextDay();
     Increments DateAndTime by one day.
     public void nextDay()
          day++;
          //your code goes here
}//end class

See java.util.Calendar
and java.util.GregorianCalendar
You can do all types of date validation with those classes.

Similar Messages

  • Please help me how concatenate all the error messages and send it as out parameter value.

    Hi Experts,
    Please help me how concatenate all the error messages and send it as out parameter value.
    Thanks.

    Agree with Billy, exception handling is not something that is done by passing parameters around.
    PL/SQL, like other languages, provides a suitable exception handling mechanism which, if used properly, works completely fine.  Avoid misuing PL/SQL by trying to implement some other way of handling them.

  • Hi team, please help me how to deploy creative cloud desktop application through SCCM for an enterprise

    Hi team, please help me how to deploy creative cloud desktop application through SCCM for an enterprise

    Moving this discussion to the Enterprise Deployment for Creative Cloud, Creative Suite forum.

  • I have updated to maverick from mountain lion.initially my mac book pro was snow leopard.the multitrack touch pad swapping the page is not happening in finder,it is only working in safari.please help me how to get that swiping gesture in  finder

    i have updated to maverick from mountain lion.initially my mac book pro was snow leopard.the multitrack touch pad swapping the page to get back to previous page is not happening in finder,it is only working in safari.please help me how to get that swiping gesture in  finder

    Hi..
    I repled to you here >  https://discussions.apple.com/message/25598596#25598596
    Please do not start duplicate topics. It makes it that much harder to assist you.

  • Can you please help me how resolved this issue.

    Hi Experts
    I am trying to connect LDAP by R/3 system. R/3 system connected to LDAP but when I am trying to find and pull the fileds in the "Find in the Directolry" option I am getting below error.
    LDAPRC 010 another server is referenced.
    Can you please help me how resolved this issue.
    With Regards,
    Trinadh Bokka

    You may be able to solve by using
    Note 1151329 - Depth of LDAP search is only one level below the base entry
    Markus

  • Please help me how to check a material does existed group code in system (w

    Hi all,
    Please help me...
    I have inputted quantity for  tx MC 94  but when I input them into  tx MC94, I met  a message " Structure  not yet maintained for  this conbination characterstics". Step by step to show a error message as below:
    Step 1: Launch MC 94
    step 2: Enter Planning
    Step 3: Enter  Prod.Code. Material (ex: enter material code :0101010260008, this code is existed  Prod.Code )
    Step 4: Click on "Inactive Version " button
    ==> A error message is showed.
    Please help me how to check a material does existed group code in system (which table to  check  it)?
    How to record the message" Structure  not yet maintained for  this conbination characterstics" to catch up it in my program?
    Thank in advance.

    Karenloria,
    1. Check in MC8C, which Infostructure is used for Planning type "Planning" or the one you are entering in the intial screen of MC94.
    2. Using transaction MC63 for the infostructure identified in step 1, check the planning hierarchy maintained. If this product is not maintined maintain using MC62.
    You can also check using SE16 transction the current infostructe records(Plan) for the table name = infostructure identified in step 1.
    Regards,
    Prasobh

  • I have a huge file which is in GB and I want to split the video into clip and export each clip individually. Can you please help me how to split and export the videos to computer? It will be of great help!!

    I have a huge file which is in GB and I want to split the video into clip and export each clip individually. Can you please help me how to split and export the videos to computer? It will be of great help!!

    video
    What version of Premiere Elements do you have and on what computer operating system is it running?
    Please review the following workflow.
    ATR Premiere Elements Troubleshooting: PE11: Project Assets Organization for Scene and Highlight Grabs from Collection o…
    But please also determine if your project goal is supported by
    a. format of your source
    and
    b. computer resources
    More later based on details that you will post.
    ATR

  • Please help me , how to know if my ipod is unloked or not to , I live in Brazil and I can't sync  it with  itunes, please help me , how to know if my ipod is unloked or not to , I live in Brazil and I can't sync  it with  itunes

    please, help me , how to know if my ipod is unloked or not , I live in Brazil and I can't sync my ipod with  the itunes thanks.

    What do you mean, "is it unlocked"? If your iPod has a screen lock set, it will be obvious from the iPod's screen. For issues with the iPod not appearing in iTunes, start which these troubleshooting steps:
    http://support.apple.com/kb/TS1538
    Regards.

  • I am a OS10.7.4 user. yesterday i bought a Lacie external hard disk but error message appear said " You cant open the applicant LaCie setup assistant because PowerPC applicants are no longer support". please help me how to connect my mac with Lacie??

    i am a OS10.7.4 user. yesterday i bought a Lacie external hard disk but error message appear said " You cant open the applicant LaCie setup assistant because PowerPC applicants are no longer support". please help me how to connect my mac with Lacie??

    You do not need the Setup Assistant; in fact, you do not need any software on an external hard drive. I have two LaCie's; I erased the drive as soon as I plugged it in. You will need to format it anyway because most hard drives come Windows formatted. So, if you only want to use it with the Mac, highlight it in Disk Utility and choose Mac OS Extended (Journaled) as the format and the GUID Partition scheme under Options. While doing that, it will erase the drive (and get rid of the LaCie software) - once finished, your drive is ready to use for Time Machine or any other backup plans you have for it.

  • Please  Help me How write the BDC program for the MIGO inbound Delivery

    Please help me how to write bdc program for the MIGO Inbound Delivery in 4.7EE Version. Please help me.
    Not in LSMW.  Required call transaction or Session Method. Please help me.
    Mohan

    Run transaction BAPI . Select Logistics Execution/Shipping/InboundDelivery/SaveReplica.. You can use function module BAPI_INB_DELIVERY_SAVEREPLICA in your ABAP program.

  • I've installed windows 7 with the help of bootcamp on my macbook pro 2011. Please help me how to install mac drivers for windows7 64 bit???

    I've installed windows 7 with the help of bootcamp on my macbook pro 2011.
    Please help me how to install mac drivers for windows7 64 bit???

    You either download drivers from within Boot Camp Assistant and save to USB FAT disk, or you insert and use 10.6.x OS X DVD when in Windows and install and run the SETUP from there.
    General Help:
    Boot Camp 4.0, OS X Lion: Frequently asked question
    http://support.apple.com/kb/HT4818
    http://manuals.info.apple.com/en_US/boot_camp_install-setup_10.7.pdf
    create a Windows support software (drivers) CD or USB storage media
    http://support.apple.com/kb/HT4407
    Installation Guide   Instructions for all features and settings.
    Boot Camp 4.0 FAQ   Get answers to commonly asked Boot Camp questions.
    Windows 7 FAQ   Answers to commonly asked Windows 7 questions.
    - support articles and tips, how to.
    http://www.apple.com/support/bootcamp/
    Macs that work with 64-bit editions of Microsoft Windows Vista and Windows 7
    http://support.apple.com/kb/HT1846
    Step 4: Install the Boot Camp Drivers for Windows
    After installing Windows, install Mac-specific drivers and other software for Windows using your Mac OS X installation disc.  The Mac OS X disc installs drivers to support Mac components, including AirPort,built-in iSight camera, the Apple Remote, the trackpad on a portable Mac, and thefunction keys on an Apple keyboard. 
    The Mac OS X disc also installs the Boot Camp control panel for Windows and theApple Boot Camp system tray item.
    To install the Boot Camp drivers:
    1 Eject the Windows installation disc.
    2 Insert the Mac OS X disc.  If the installer doesn’t start automatically, browse the disc using Windows Explorerand double-click the setup.exe file in the Boot Camp directory.
    3 Follow the onscreen instructions.
    If a message appears that says the software you’re installing has not passed Windows  Logo testing, click Continue Anyway.
    Windows that appear only briefly during the installation don’t require your input.
    If nothing appears to be happening, there may be a hidden window that you mustrespond to. Check the taskbar and look behind open windows.
    Important: Do not click the Cancel button in any of the installer dialogs.
    4 After your computer restarts, follow the instructions in the Found New Hardware  Wizard to update your software drivers (Windows XP only).
    5 Follow the instructions for any other wizards that appear.
    6 Check for updated Boot Camp drivers by using Apple Software Update or going to www.apple.com/support/bootcamp.
      If You Have Problems Installing the Device Drivers 
    If it appears that the Boot Camp drivers weren’t successfully installed, try repairing them.
    To repair Boot Camp drivers:
    1 Start up your computer in Windows.
    2 Insert your Mac OS X installation disc.
    3 If the installer doesn’t start automatically, browse the disc using Windows Explorerand double-click the setup.exe file in the Boot Camp directory.
    4 Click Repair and follow the onscreen instructions.
    If a message appears that says the software you’re installing has not passed Windows  Logo testing, click Continue Anyway. 
    If you need to reinstall specific drivers, you can install one driver at a time. For example,if your built-in iSight camera isn’t working, you can reinstall just the iSight driver.
    Individual drivers are in the Drivers folder on the Mac OS X installation disc.

  • I lost my ipad and i need the serial number and IMEI , please help me how?

    i lost my ipad and i need the serial number and IMEI , please help me how?

    If you have registered your device, you can go to https://supportprofile.apple.com/ and log into your apple id.  Your devices appear there with serial numbers.
    Additionally, your serial number is included on the original receipt when purchased at any Apple Online or Apple Retail store, or any Authorized Apple Reseller.

  • HEY, i have some issue i am using macbook air i5...the problem is that without doing anything 1.5gb of ram out of 2gb always in use ..please help me how to make it normal.

    HEY, i have some issue i am using macbook air i5...the problem is that without doing anything 1.5gb of ram out of 2gb always in use ..please help me how to make it normal....
    and my battery back up is max 3 to 3.5 hours in normal use with web ....is this normal or need some betterment!!!!

    ADEEL UR REHMAN wrote:
    ...the problem is that without doing anything 1.5gb of ram out of 2gb always in use
    No computer can do a thing without using memory. 1.5 GB is very little. It's normal.
    3 or so hours from a full charge may also be normal, for what you are doing. As batteries age, they don't last as long on a full charge as they did when they were new. All batteries eventually wear out, and are easily replaceable.

  • Hi please help me how can I use my iPhone 4 I am at vocation my is not working please help

    Hi I am at vocation at Italy I am not able to use my phone please help me how can I use my phone overseas thank u

    You need to make your own ringtones in iTunes then sync them to your phone. Follow the directions here:
    http://osxdaily.com/2010/09/04/make-free-iphone-ringtones-in-itunes-10/

  • I bought CS6 creative suite. As of now i need to work each application in separate separate system. Can any one please help me how to solve this problem.

    I bought CS6 creative suite. As of now i need to work each application in separate separate system. Can any one please help me how to solve this problem.
    I saw the below quote on Adobe forum
    "You may install software on up to two computers. These two computers can be Windows, Mac OS, or one each."
    If i install each application in single single system the system count is more than two. In this case, are we have any license issue? Please advice how the problem will solve?
    If possible please send the advise to my mail id: <Removed by Moderator>
    Thanks
    Uvaraj S

    I already answered that.  If you purchased a Suite then you can only install and activate it on two machines.  Even if you only insdtall one of the applications of that suite, it counts as one activation of the suite.  You cannot take the six or seven different applications that might be in a suite and install and activate them in six or seven different machines... only two machines.
    If your scenario will allow for it, one thing you can do is install the programs on all the different machines and only activate two of the machines at any given time.  If you need to activate a program on a third machine then you need to deactivate on one of the currently activate machines first so that you have an open activation to use again.  I do not remember if there is a limit to the total number of activations you can process for the life of the software.

Maybe you are looking for