Create class Date with the following capabilities:
a) Output the date in multiple formats, such as
MM/DD/YYYY
June 14, 1992
DDD YYYY
b) Use overloaded constructors to create Date objects initialized
with dates of the formats
in part (a). In the first case the constructor should receive three
integer values. In the
second case it should receive a String and two integer values. In
the third case it should
receive two integer values, the first of which represents the day
number in the year.
[Hint: To convert the String representation of the month to a
numeric value, compare
Strings using the equals method. For example, if s1 and s2 are
Strings, the method
call s1.equals(s2)
//Java program
class Date{
private int day,month,year;
public Date(int m,int d, int y) {
day = d;
month = m;
year =y;
}
public Date(String m ,int d, int y) {
day = d;
year = y;
if(m.equals("January"))month=1;
else
if(m.equals("February"))month=2;
else
if(m.equals("March"))month=3;
else
if(m.equals("April"))month=4;
else
if(m.equals("May"))month=5;
else
if(m.equals("June"))month=6;
else
if(m.equals("July"))month=7;
else
if(m.equals("August"))month=8;
else
if(m.equals("September"))month=9;
else
if(m.equals("October"))month=10;
else
if(m.equals("November"))month=11;
else
if(m.equals("December"))month=12;
}
public Date(int days , int y) {
int months[] =
{31,28,31,30,31,30,31,31,30,31,30,31};
if (y % 400 == 0 || (y % 4 == 0
&& y % 100 != 0))months[1]+=1;
int m=1;
while(days>months[m-1]) {
days-=months[m-1];
m++;
}
day=days;
month = m;
year = y;
}
public void printDate() {
System.out.printf("%2d/%2d/%4d\n",day,month,year);
}
}
public class MainDate {
public static void main(String args[]) {
Date d1 = new
Date(10,2,2018);
Date d2 = new Date("April" ,4,2018
);
Date d3 = new Date(89 ,
2018);
d1.printDate();
d2.printDate();
d3.printDate();
}
}
//sample output

Create class Date with the following capabilities: a) Output the date in multiple formats, such as...
CODING IN JAVA Dates are printed in several common formats. Two of the more common formats are: 07/21/55 and July 21, 1955 Write a program that reads a date in the first format and prints that date in the second format. Prompt the user and accept user input for the date in MM/DD/YYYY format. Retrieve the month portion of the date entered and convert it to an integer. Do the same thing for day and year Create a string named...
Create a class called Date212 to represent a date. It will store the year, month and day as integers (not as a String in the form yyyymmdd (such as 20161001 for October 1, 2016), so you will need three private instance variables. Two constructors should be provided, one that takes three integer parameters, and one that takes a String. The constructor with the String parameter and should validate the parameter. As you are reading the dates you should check that...
JAVA programing Question 1 (Date Class): 5 Points Create a class Date with the day, month and year fields (attributes). Provide constructors that: A constructor that takes three input arguments to initialize the day, month and year fields. Note 1: Make sure that the initialization values for the day, month and year fields are valid where the day must be between 1 and 31 inclusive, the month between 1 and 12 inclusive and the year a positive number. Note 2:...
Need help writing beginner C# program, I will make sure to
provide feedback to whoever can help me figure it out!
No public or global variables should be used. You need to
consider passing arguments between the methods according to the
ways described in the lecture. i.e. all variables should be
declared inside the methods and passed to other methods by
value/ref/out as needed
Description: We want to design a Date class to represent a date using three integer numbers...
public class Date { private int month; private int day; private int year; /** default constructor * sets month to 1, day to 1 and year to 2000 */ public Date( ) { setDate( 1, 1, 2000 ); } /** overloaded constructor * @param mm initial value for month * @param dd initial value for day * @param yyyy initial value for year * * passes parameters to setDate method */ public Date( int mm, int dd, int yyyy )...
Create a UML diagram to help design the class described in exercise 3 below. Do this exercise before you attempt to code the solution. Think about what instance variables will be required to describe a Baby class object; should they be private or public? Determine what class methods are required; should they be private or public? Write Java code for a Baby class. A Baby has a name of type String and an age of type integer. Supply two constructors:...
Program Description: Design a class named Date. The class should store a date in three integers: month, day, and year. Create the necessary set and get methods. Design member functions to return the date as a string in the following formats: 3/29/1988 29 MARCH 1988 MARCH 29, 1988 Input Validation: Do not accept values for day greater than 31 or less than 1. Do not accept values for month greater than 12 or less than 1. Do...
Create a new Java Application that test MyStack by having the following methods in main class: 1. A method to generate a number of element between two given values and save them in a stack 2. A method to print a stack (10 elements per line). The original stack should remain as is after the print 3. A method to exchange the first element and the last element in a stack 4. A Boolean method to search for a value...
// Client application class and service class Create a NetBeans project named StudentClient following the instructions provided in the Starting a NetBeans Project instructions in the Programming Exercises/Projects Menu on Blackboard. Add a class named Student to the StudentClient project following the instructions provided in the Starting a NetBeans Project instructions in the Programming Exercises/Projects Menu on Blackboard. After you have created your NetBeans Project your application class StudentC lient should contain the following executable code: package studentclient; public class...
Java, can you help me out thanks.
CSCI 2120 Introduction For this assignment you will implement two recursive methods and write JUnit tests for each one. You may write all three methods in the same class file. You are required to write Javadoc-style documentation for all of your methods, including the test methods. Procedure 1) Write method!! a recursive method to compare two Strings using alphabetical order as the natural order (case insensitive, DO NOT use the String class built-in...