Write a java class called date that includes three fields

Assignment Help Computer Engineering
Reference no: EM132200511

Write a Java class called Date that includes three fields year, month and day.

This class stores information about a single date (year, month and day). Your class should have constructor(s), accessors and mutators and it should implement the Comparable interface.

Years take precedence over months, which take precedence over days.

For example, Feb 19, 2016 comes after Nov 20, 2015.

The following class DateTest can be used to test the Date class that you wrote.

It creates a list of the birthdays of the first 5 U.S. presidents in random order and puts them into sorted order.

(Note: you can use Collections.sort() to sort your ArrayList after you implement the compareTo() method).

import java.util.*;

public class DateTest {
public static void main(String[] args) {

ArrayList<Date> dates = new ArrayList<Date>();

dates.add(newDate(4,13,1743)); //Jefferson

dates.add(newDate(2,22,1732)); //Washington

dates.add(newDate(3,16,1751)); //Madison

dates.add(new Date(10, 30, 1735)); // Adams

dates.add(newDate(4,28,1758)); //Monroe

System.out.println("birthdays = " + dates);

Collections.sort(dates);

System.out.println("birthdays = " + dates);

}

}

When you execute the following code it should print:
birthdays = [4/13/1743, 2/22/1732, 3/16/1751, 10/30/1735, 4/28/1758]

birthdays = [2/22/1732, 10/30/1735, 4/13/1743, 3/16/1751, 4/28/1758]

Reference no: EM132200511

Questions Cloud

Explain the common ion effect : Explain the common ion effect. Explain the relationship between Ka for an acid and Kb for its conjugate base.
Write a java program to accept positive integers from user : Write a Java program to accept positive integers from the user at the command line. The user can enter as many integers as they like. Use -1 as a sentinel.
Equilibrium concentrations in a chemical reaction : List the steps and explain how to solve for equilibrium concentrations in a chemical reaction by creating a table of initial and final
Suggestions for learning basic chemistry : When studying for the HESI exam, the nursing school entry exam, I'm having an issue with the chemistry section as it's the only class
Write a java class called date that includes three fields : Write a Java class called Date that includes three fields year, month and day.
Internal standards used in chemical analysis : Why is the method of standard addition or internal standards used in chemical analysis? What is the difference between the two?
General type of chemical concentration using chemical : How do you calculate/what formula do you use when trying to determine any general type of chemical concentration using chemical stoichiometry?
Write a java code to initialize a 2-d array of integers : Write a Java code snippet to declare and initialize a 2-dimensional array of integers, 10 rows and 10 columns.
Convert molarity to mass percentage : How do you calculate/what formula(s) do you use when calculating the mass of solute/solvent in a given solution, determine final molarity after several dilution

Reviews

Write a Review

Computer Engineering Questions & Answers

  Dscribe your experiences related to your setup of mysql

research the capabilities of mysql.write a one to two page paper in which youdescribe your experiences related to your

  Questionyour company has a benchmark that is considered

questionyour company has a benchmark that is considered representative of your typical applications. an embedded

  Design a program that let the user enter the total

SDEV 140 : Design a program that let the user enter the total rainfall for each of 12 months into an array.

  Calculate the slope and length of sides

Write a program that calculates the slope and length of sides and the perimeter of a rectangle given four of its vertices as ordered pairs (x,y).

  How would the given customer be classified

Specify the success class as 1 (loan acceptance), and use the default cutoff value of 0.5. How would this customer be classified?

  Analyze the difference between a use case and a scenario

Analyze the difference between a use case and a scenario. Give a specific example of a use case with at least two (2) possible scenarios.

  Similarities and differences to issue of regulation

Describe the relevance of each of these similarities and differences in order to issue of regulation of the Internet.

  How many more comparisons of keys does quicksort make

How many more comparisons of keys does quicksort make than the optimum? About how many comparisons does it make in the worst case?

  How is the memory address to be interpreted

Consider a system of 8Kbytes of byte-addressable main memory partitioned into blocks of 32bytes each.

  Perform the test for the non-additive join property

Perform the test for the non-additive join property (lossless join) for the relation R.

  Use the internet to locate one incident of disaster recovery

Use the Internet to locate one incident of disaster recovery that was successful and one incident that was not successful. Compare and contrast

  Apple inc is known for its state-of-the-art designs for

apple inc. is known for its state-of-the-art designs for products such as the iphone but most are unaware that apple

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