Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

Task#1: Define the Date and DateTest classes by doing the followings. Run your code.

1.     In Date class,

a.     declare three instance variables: year, month, and day

b.     define a constructor to initialize the variables properly

c.      define toString method to return the date as a String like 26/3/2014

 2.     In DateTest class, define the main method. The main method should create a Date object and print it.

Task#2: Update the Date and DateTest classes by doing the followings. Run your code.

1.     In Date class,

a.     update the constructor to accept only valid values for year (> 0), month(1-12), and day(1-31). If any of the three values is not valid the value 1 should be assumed.

b.     define a default constructor that initializes each of the three instance variables with the value 1.

c.      the toString method should return the date with full month name, such as "March 26, 2014".
 
2.     In the main method of the DateTest class, add code to create a date object with the default constructor, and another one with invalid values, and see the results.

Task#3: Do the followings in the DateTest class.

1.     Add a static Date toDate(String str) method to the DateTest class. If the method is called with a string like "26/3/2014", it will create and return the corresponding date object. If the input string is not valid date, the method should return null.  Hint: use the String.split("/")  method to split the string in three parts and retrieve the day, month, and year. Or use the String.indexOf("/") and String.substring() methods to extract the three components of the date from the string.

2.     In the main method, call the toDate method with a string-date of your choice and print the result.

Task#4: Update the Date and DateTest classes by doing the followings.

1.     Implement the Comparable interface in the Date class. Provide implementation for the public int compareTo(Object obj) method. You may get help from Example#7.

2.     In the main method of the DateTest class, add code for the followings.

a.     Create an array of Date objects of size 4. Initialize the array by using a loop. In the loop, use the Scanner.nextLine() method to input a date as a string, convert it to a date by using the toDate() method, and assign the result to an element in the array. If the result of toDate() method is null, input the date again (Hint: consider using nested do-while loop for inputting a valid string-date).

b.     Print the array of dates using a loop.

c.      Use the Arrays.sort method to sort the array of dates.

d.     Print the array of dates using a loop. The dates will now be sorted.

 
Task#5: Zip the folder of your project and submit through Blackboard.

Java, Programming

  • Category:- Java
  • Reference No.:- M9455597

Have any Question?


Related Questions in Java

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Question slideshows or carousels are very popular in

Question : Slideshows (or carousels) are very popular in websites. They allow web developers to display news or images on the website in limited space. In this code challenge, you are required to complete the JavaScript ...

Solving 2nd degree equationsbull write the following java

Solving 2nd degree equations • Write the following Java methods • boolean real-sols(double a, double b, double c): it returns true if the 2nd degree equation ax2 + bx + c has real solutions • double solution1(double a, d ...

Can someone help me please with those question1what is the

Can someone help me please with those question 1:what is the best data type for student id datatime,currency,number,decimal 2:which relationshipis preferable? one to one,one to many,many to many 3:if you add table A's pr ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Object-oriented software development1 introduction 11

OBJECT-ORIENTED SOFTWARE DEVELOPMENT 1. Introduction 1.1 Assignment Requirement 1.2 Deliverables and Structure (what to submit) 1.3 Software Restrictions 1.4 How to score high... 1.5 Assumptions 2. System Requirements 2. ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

In ruby the hash class inherits from enumerable suggesting

In Ruby, the Hash class inherits from Enumerable, suggesting to a programmer that Hashes are collections. In Java, however, the Map classes are not part of the JCF (Java Collections Framework). For each language, provide ...

Project requirementsfor the problem described in the next

Project requirements For the problem described in the next section, you must do the following: 1. include your student ID at the end of all filenames for all java code files. Three classes have been identified in section ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As