Question

In: Computer Science

Java program Create class DateClass with the following capabilities: Output the date in multiple formats, such...

Java program

Create class DateClass with the following capabilities:

Output the date in multiple formats, such as

MM/DD/YYYY
June 14, 1992
DDD YYYY

Use overloaded constructors to create DateClass 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.

If someone enters the day as the 14 and the month is june, the program should be able to convert that to the day out of 365 for the third format. No null values. The program should convert whatever the user enters and print out all three date formats correctly.

Solutions

Expert Solution

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Below java classes are created.

DateClass.java :

//Java class
public class DateClass {

   //constructor
   public DateClass(int mm,int dd,int yyyy)
   {
       //print date in the format MM/DD/YYYY
       System.out.println(mm+"/"+dd+"/"+yyyy);
   }
   //overloaded constructor
   public DateClass(String mm,int dd,int yyyy)
   {
       //print date in the format June 14, 1992
       System.out.println(mm+" "+dd+","+yyyy);
      
   }
   public DateClass(int dd,int yyyy)
   {
       //print date in the format DDD YYYY
       System.out.println(dd+" "+yyyy);
   }
  
}
**********************************

DateClassTest.java :

import java.util.*;//import package
import java.time.LocalDate;
//Java class
public class DateClassTest {
   // entry point of program , main() method
   public static void main(String[] args) {
       // creating object of scanner class
       Scanner sc = new Scanner(System.in);
       // asking user to enter day
       System.out.print("Enter Day : ");
       int day = sc.nextInt();// reading day
       // asking user to enter month
       System.out.print("Enter Month : ");
       String month = sc.next();// reading month
       // asking user to enter year
       System.out.print("Enter Year : ");
       int year = sc.nextInt();// reading year
       // declaring variable to store month number
       int monthNumber = 0;
       // array to store month number
       String[] months = { "january", "february", "march", "april", "may", "june", "july", "august", "september",
               "october", "november", "december" };
       // finding month number using for loop
       for (int i = 0; i < months.length; i++) {
           if (month.toLowerCase().equals(months[i])) {
               // if month is found in the month array
               monthNumber = i;// set i as month number
               break;// break the loop
           }
       }
       // creating object of DateClass
       DateClass date2 = new DateClass(monthNumber + 1, day, year);// object 1
       DateClass date1 = new DateClass(month, day, year);// object 2
       // getting day number from the date
       int dayNumber = LocalDate.of(year, monthNumber + 1, day).getDayOfYear();
       DateClass date3 = new DateClass(dayNumber, year);
   }

}

======================================================

Output : Compile and Run DateClassTest,java to get the screen as shown below

Screen 1 :DateClassTest.java

Screen 2 :

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.


Related Solutions

Java Program using Netbeans IDE Create class Date with the following capabilities: a. Output the date...
Java Program using Netbeans IDE 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...
C++ * Program 2:      Create a date class and Person Class.   Compose the date class...
C++ * Program 2:      Create a date class and Person Class.   Compose the date class in the person class.    First, Create a date class.    Which has integer month, day and year    Each with getters and setters. Be sure that you validate the getter function inputs:     2 digit months - validate 1-12 for month     2 digit day - 1-3? max for day - be sure the min-max number of days is validate for specific month...
Create the following java program with class list that outputs: //output List Empty List Empty List...
Create the following java program with class list that outputs: //output List Empty List Empty List Empty Item not found Item not found Item not found Original list Do or do not. There is no try. Sorted Original List Do There do is no not. or try. Front is Do Rear is try. Count is 8 Is There present? true Is Dog present? false List with junk junk Do or moremorejunk do not. There is no try. morejunk Count is...
(Using Date Class) The following UML Class Diagram describes the java Date class: java.util.Date +Date() +Date(elapseTime:...
(Using Date Class) The following UML Class Diagram describes the java Date class: java.util.Date +Date() +Date(elapseTime: long) +toString(): String +getTime(): long +setTime(elapseTime: long): void Constructs a Date object for the current time. Constructs a Date object for a given time in milliseconds elapsed since January 1, 1970, GMT. Returns a string representing the date and time. Returns the number of milliseconds since January 1, 1970, GMT. Sets a new elapse time in the object. The + sign indicates public modifer...
Write a program in java that does the following: Create a StudentRecord class that keeps the...
Write a program in java that does the following: Create a StudentRecord class that keeps the following information for a student: first name (String), last name (String), and balance (integer). Provide proper constructor, setter and getter methods. Read the student information (one student per line) from the input file “csc272input.txt”. The information in the file is listed below. You can use it to generate the input file yourself, or use the original input file that is available alone with this...
Create a simple Java class for a Month object with the following requirements:  This program...
Create a simple Java class for a Month object with the following requirements:  This program will have a header block comment with your name, the course and section, as well as a brief description of what the class does.  All methods will have comments concerning their purpose, their inputs, and their outputs  One integer property: monthNumber (protected to only allow values 1-12). This is a numeric representation of the month (e.g. 1 represents January, 2 represents February,...
Create a Java program. The class name for the program should be 'EncryptText'. In the main...
Create a Java program. The class name for the program should be 'EncryptText'. In the main method you should perform the following: You should read a string from the keyboard using the Scanner class object. You should then encrypt the text by reading each character from the string and adding 1 to the character resulting in a shift of the letter entered. You should output the string entered and the resulting encrypted string. Pseudo flowchart for additional code to be...
Program in Java Create a class and name it MyArray and implement following method. * NOTE:...
Program in Java Create a class and name it MyArray and implement following method. * NOTE: if you need more methods, including insert(), display(), etc. you can also implement those. Method name: getKthMin(int k) This method receives an integer k and returns k-th minimum value stored in the array. * NOTE: Items in the array are not sorted. If you need to sort them, you can implement any desired sorting algorithm (Do not use Java's default sorting methods). Example: Items...
Program in Java Create a class and name it MyArray and implement following method. * NOTE:...
Program in Java Create a class and name it MyArray and implement following method. * NOTE: if you need more methods, including insert(), display(), etc. you can also implement those. Method name: getKthMin(int k) This method receives an integer k and returns k-th minimum value stored in the array. * NOTE: Items in the array are not sorted. If you need to sort them, you can implement any desired sorting algorithm (Do not use Java's default sorting methods). Example: Items...
The following program will be written in JAVA. Create a class called complex performing arithmetic with...
The following program will be written in JAVA. Create a class called complex performing arithmetic with complex numbers. Write a program to test your class.                         Complex numbers have the form:                         realPart + imaginaryPart * i                                               ___                         Where i is sqrt(-1)                                                 Use double variables to represent data of the class. Provide a constructor that enables an object of this class to be initialized when it is declared. The constructor should contain default values in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT