Answered step by step
Verified Expert Solution
Question
1 Approved Answer
public class CalenderDay private int month; private int day; private int year; public CalenderDay(String date) { String[] parts = date.split(/); this month = Integer.parseInt(parts[0]);
public class CalenderDay private int month; private int day; private int year; public CalenderDay(String date) { String[] parts = date.split("/"); this month = Integer.parseInt(parts[0]); this.day= Integer.parseInt(parts[1]); this.year=Integer.parseInt(parts [2]); } public CalenderDay (int month, int day, int year){ this.month = month; } public CalenderDay (CalenderDay other){ this month = other.month; other. day; } this.day day; this.year = year; public int getMonth() { return month; this.day this.year = other.year; } public void setMonth(int month) { this.month = month; } public int getDay () { return day; } public void setDay (int day) { this.day day; } public int getYear() { return year; } } public void setYear(int year) { this.year = year; } @Override public boolean equals(Object o){ if(o instanceof CalenderDay) { CalenderDay other = (CalenderDay) o; return this.month == other.month && this.day == other.day && this.year == other.year; } else{ } return false; } @Override public String toString(){ } return month + "/" + day + "/" + year; File Edit Format View Help import java.util.Arrays; public class Main{ public static void main(String[] args) { // Christmas CalenderDay d1 = new CalenderDay ("12/25/2000"); // Thanksgiving CalenderDay d2 = new CalenderDay("11/24/2016"); // A copy of Thanksgiving CalenderDay d3 = new CalenderDay (d2); // 12/25/2000 Christmas System.out.println("d1: "+d1); "+ d2); // 11/24/2016 What day is it? System.out.println("d2: // 11/24/2016 copy System.out.println("d3: "+ d3); // false - different dates System.out.println("d1 // true - same dates System.out.println("d2 equals d3: equals d2: } + "d1.equals(d2)" + "False"); + "d2.equals(d3)" + "True"); CalenderDay [] days= new CalenderDay [3]; days [0] =new CalenderDay ("10/31/2015"); // Halloween days [1] =new CalenderDay("12/25/2000"); // Christmas days [2] =new CalenderDay("11/24/2016"); // Thanksgiving Arrays.sort (days); for (CalenderDay d: days) { System.out.println(d);
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started