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

  Write a program that reads the french name of a country

Write a program that reads the French name of a country and adds the article: le for masculine or la for feminine, such as le Canada or la Belgiqe.

  What is the result of the receivers crc calculation

What is the result of the receiver's CRC calculation? Show your work. Does the receiver know that an error has occurred?

  Create a schema that supports the company business

Create a schema that supports the company's business and processes. Explain and support the database schema with relevant arguments that support the rationale.

  Why do some distributed systems use two-level naming

Why do some distributed systems use two-level naming? Why do stateless servers have to include a file offset in each request?

  How many botnet machines are needed to send data

How many botnet machines are needed to send data to the web server in order to fill the web server's link capacity?

  Illustrate the methods for data validation

Illustrate the methods for Data Validation and Illustrate the methods of Hardware Testing - What is the weakest-precondition of a program

  Reduce natural convection heat transfer through the window

Consider a double-pane window consisting of two glass sheets separated by a 1-cm-wide air space. Someone suggests inserting a thin vinyl sheet in the middle.

  Define a brief discussion of the technical aspects

Plagiarism is "cheating." It will not be tolerated and will be dealt with in accordance with University policy. Automated tools will be used to detect plagiarism and I will make deductions for minor cases, and grade the paper as a zero for major..

  Program meeting the least program requirements

Incorporate ADO.NET access to at least three Microsoft Access data tables. These tables must include Customers, Products (the kinds of products offered, cost, sales price, and quantity on hand), and Sales information (a combination of customer and..

  Write program to calculate pay of different types of employe

Write program to calculate pay of different types of employe

  What is the purpose of the hidden control view state

What is the purpose of the hidden control View State? How can an ASP.NET checkbox control be forced to cause a post back when it is checked?

  Write a program that plays the game of mad lib

Write a program that plays the game of mad lib. Your program should prompt the user to enter the following strings: The first or last name of your instructor.

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