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...
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...
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:...
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 )...
// 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...
Create a Java application named Problem14 using the two files Dr. Hanna provided to you—Date.java andProblem14.java—then change his code to add two non-trivial public, non-static methods to the Date class.1. Increment a Date to the next day (for example, 1-31-2011 increments to 2-1-2011; 12-31-2010 increments to 1-1-2011).2. Decrement a Date to the previous day (for example, 2-1-1953 decrements to 1-31-1953; 1-1-1954 decrements to 12-31-1953).. Extra Credit (up to 5 points) Re-write the Date member functions Input() and Output() to usedialog boxes to...
Given the follawing tent,TALKSOW DAT um? ?,iLon ㆀ01 09/15/1974 nd te elowing Hot iava class anower she questions that follaw: buffer.append(" BIRTHDAY:"birthday) return buffer.toString ) 1. Write a Java class HmWk14. Create the method readTalkshow(list) in the HmWk14 class that that reads the file TALKSHOW.DAT. Each line in the data file will be stored into a Host Java class object and added to a list of Host objects. Make a note that the date in the file needs to be...
Create a Java application, that support the following: Create an Employee class, which holds following information: Employee First Name Employee Last Name Employee Phone Number Employee Address Employee id Employee Title Employee salary Create an application that uses the Employee class Constructors –Getters and setters A minimum of 3 constructors including default constructor equals() method Helper methods toString() method Create an array of 5 Employee objects Use a Scanner to read in 5 employee information Change 2 employees information (3-items...