Chat with us, powered by LiveChat Creating Two different Classes for Time and Date in Java | Writedemy

Creating Two different Classes for Time and Date in Java

Creating Two different Classes for Time and Date in Java

Question

Assignment 1:

	1. Create the java TimeType class (discussed in class & Chapter 8), 
 with three private integer data fields named hours, minutes, 
 and seconds, and implement the following public methods:

 TimeType() 
 no argument contructor. Sets all private data to 0.
 TimeType(int, int, int)
 contructor function. Set the private data according to the 
 three parameters. The first paramter represents hours, the 
 second minutes, and the third seconds. If any of the 
 parameters are invalid, set all private data to 0.
 TimeType(TimeType)
 contructor function. Initializes the private data to the 
 values stored in the TimeType parameter
 String toString()
 Returns the time stored in the object in the format 
 HH:MM:SS AM/PM
 boolean Set(int,int,int)
 Sets the time in the object according to the three 
 parameters. The first paramter represents hours, the 
 second minutes, and the third seconds. If any of the 
 parameters are invalid, does nothing and 
 returns false. Otherwise, set the private 
 data according to the three parameters and returns true.
 void Increase()
 Increases the time in the object by 1 SECOND
 void Decrease()
 Decreases the time in the object by 1 SECOND

	2. After you have created and compiled the TimeType class, create a 
 client Java application to test the TimeType class. This application, 
 named TestTime, should do the following and display its results 
 using a Scanner object:

 - Create a TimeType object called time1 using the default 
 contructor.
 - Create a TimeType object called time2 initialized to 23 hours, 
 59 minutes, and 58 seconds
 - Create a TimeType object called time3 initialized with the 
 values from the time2 object.
 - Write the values of time1, time2, and time3 on separate lines.
 - Attempt to set the time in time1 to 25 hours, 0 minutes, and 0 
 seconds. If successful, display the time in time1 otherwise 
 display the message "Invalid Time".
 - Create a loop that will increase and write the time in time2 10 
 times.
 - Create a loop that will decrease and write the time in time2 10 
 times.

As usual, include general comments, comment each variable and method, and format 
your code neatly.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Start Assignment 2 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Assignment:
	Create a new DateAndTime class that inherits from your TimeType class 
and adds the following three private integer instance variables: month, day, 
and year (and two arrays - see Notes below). Your class should implement the 
following methods:

1.	DateAndTime()	a no-argument constructor that sets the date to 01/01/1980 and 
			the hours, minutes and seconds to 0.

2.	boolean setDate(int m, int d, int y)
			If the year and month are valid, and the day is valid for the 
			given month, set the month, day, and year according to the 
			parameters supplied and return true. If any of the parameters 
			are invalid, this method should do nothing and return false. 

3.	void increaseDay()	
			increases the day by 1. Adjusts the month and year if necessary.

4.	void decreaseDay()	
			decreases the day by 1. Adjusts the month and year if necessary.

5. String toString()
	 	prints the date in the format Monthname day, year HH:MM:SS AM/PM

6.	boolean isEqual(Date d)
			return true if the Date object calling the method has the same 
			values as the Date object passed as a paramater, otherwise return 
			false.
 
7.	boolean leapYear(int yr)
			returns true if the parameter yr is a leap year, otherwise returns 
 false. A leap year occurs in years whose last two digits are 
 evenly divisible by four, except for centenary years not divisible by 400

8. void increaseSecond()
 increases the time by one second. Adjusts the date if necessary 
 
9. void decreaseSecond()
 decreases the time by one second. Adjusts the date if necessary

Notes:

Assume the original TimeType class from assignment #4 contains 3 additional methods: 
getSeconds(), getMinutes(), and getHours(). Each of these methods return the respective private instance variable. 
These methods are necessary to implement increaseSecond() and decreaseSecond(). A complete working copy 
of the TimeType class is available in the class folder/home2/classes/csi205/TimeType.class 

In addition to the month, day, and year private instance variables, you should 
create two one dimensional private instance variable arrays for the purpose of 
printing the month names, and for validating the number of days in each month. 
The first static final array of 12 String elements should hold the names of 
each month and should be referenced by the toString() method to return the full 
month name. The second array of 12 int elements should be referenced to 
determine if the given day is valid for the current month. The days in each 
month are: Jan 31, Feb 28, Mar 31, Apr 30, May 31 Jun 30, Jul 31, Aug 31, 
Sep 30, Oct 31, Nov 30, Dec 31. You should use the leapYear() method to 
determine if Feb. contains 28 or 29 days.


You should create your own test client to test the implementation of your 
DateAndTime class. 

As usual, format your code neatly. You should comment each of your variables 
and place comments before EACH method explaining its purpose.

Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteDemy. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.

Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.

Do you need an answer to this or any other questions?

About Writedemy

We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.

How It Works

To make an Order you only need to click on “Order Now” and we will direct you to our Order Page. Fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.

Are there Discounts?

All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.

Hire a tutor today CLICK HERE to make your first order