Create an array of date objects

Assignment Help JAVA Programming
Reference no: EM13165479

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.

Reference no: EM13165479

Questions Cloud

Effectiveness of an hrd program : Explain the role that trainability plays in the effectiveness of an HRD program or intervention. Briefly describe the options available to assess the trainability of employees
Class sorter which contains methods for selection sort : Write a class Sorter which contains methods for selection sort, insertion sort and bubble sort (start with the code below). Then create a client class which asks user to enter ten numbers using arrays. Then the program asks user which sorting algo..
Write a script that creates a craps game : Write a script that creates a craps game and meets the following requirements. Name the script craps.sh The script will get 2 random numbers between 1-6.
Estimate state income tax payments : Estimated state income tax payments of $1,000 each quarter and estimated city income tax payments of $300 each quarter. The Dunphys made all fourth-quarter payments on December 31, 2013. They would like to receive a refund for any overpayments.
Create an array of date objects : 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 ..
Write a linked-list-based push-down stack implementation : Write a linked-list-based push-down stack implementation that keeps items on the list in order from least recently inserted to most recently inserted. You will need to use a doubly linked list.
Create 3 files date.h, date.cpp, date_main.cpp : create 3 files date.h, date.cpp, date_main.cpp that will create a birth date and a graduation date in the form MM/DD/YYYY
Prepare a statement of cash flows for 2012 : Prepare a statement of cash flows for 2012 using the indirect method in the Operating Activities section and problem Statement of Cash Flows Indirect Method
Identify five different it systems : Identify five different IT systems that have affected business in the past few years. For each system, briefly note the following: · A name for the system

Reviews

Write a Review

 

JAVA Programming Questions & Answers

  The drink machine should have a supply

When the applet starts, the drink machine should have a supply of 20 of each of the drinks. The applet should have a text field where the user can enter the amount of money he or she is giving the machine. The user can then click on a button to selec..

  Write java program to find calories-conditional operator

Write down the answer for this program? Write down Java program (use Conditional (? Operator) which suggests number of calories a person must eat each day.

  Java program ask user to enter 10-character telephone number

Write a Java program that asks the user to enter a 10-character telephone number in the format XXX-XXX-XXXX. The program should display the telephone number with any alphabetic characters

  Create web application uses visual web java server

Create the Web application which uses Visual Web Java Server Faces framework and either Apache Tomcat or Glassfish as the server.

  Java program that prompts the user to input an integer

Write a Java program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits.

  Java program use breadth-first search closest broadcast

Write the java program which will use breadth-first search (which you implement as part of your program) to determine the closest broadcast vertex for each vertex in graph.

  Generates a random number between 1 and 100

Write a program that generates a random number between 1 and 100 (inclusive) and then prompts the user to guess the number. The user should be given up to 10 chances to guess the number.

  Java program to find a value at in index

Construct a main class named Array Program that generates an array of 50-integers, all ranging from one to one hundred.

  Accepts a binary number from the user

Write a Java test program that accepts a binary number from the user. You should store the binary number in a String. Your program should then use afor loop to sequence through every character in the String, counting the number of ones, zeros, and..

  Create application uses two-dimensional arrays

Create an application which uses 2-dimensional arrays to keep track of 5 students' grades, with each student having 3 different classes.

  Construct java program named collegelist

Construct a set of classes for a college to use in many student service and personnel applications. Classes you require to design include following:

  Write a program that asks a user for a file name and prints

Write a program that asks a user for a file name and prints the number of characters, words, and lines in that file.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd