The document describes a Java program that implements a class hierarchy with a base class 'Person' and two child classes 'Account' and 'Admin'. It also includes an 'Employee' class that inherits from 'Account' and displays employee details along with current date and time information. The program outputs various date-related details such as the current year, month, week number, and day of the week.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
3 views
Program 2
The document describes a Java program that implements a class hierarchy with a base class 'Person' and two child classes 'Account' and 'Admin'. It also includes an 'Employee' class that inherits from 'Account' and displays employee details along with current date and time information. The program outputs various date-related details such as the current year, month, week number, and day of the week.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3
2. Write a program to implement following.
Create a base class called person consisting of
name and code. Create 2 child classes a. Account with member pay and b. Admin with experience and inherit the base class. Create a class Employee with name, code, experience and pay by inheriting the above class. a. Write Python script to display b. Current date and time c. Current year d. Month of year e. Week number of the year f. Weekend of the week g. Day of year h. Day of the month and Day of week.
public static void main(String[] args) { // Create Employee object Employee employee = new Employee("John Doe", "E123", 5000.00, 5);
// Display employee details
employee.displayDetails();
// Display date and time information
displayDateInfo(); }
public static void displayDateInfo() {
LocalDateTime now = LocalDateTime.now();
// Format the current date and time
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); System.out.println("\nDate and Time Information:"); System.out.println("Current Date and Time: " + now.format(formatter));
System.out.println("Month of Year: " + now.getMonth());
// Get the week number of the year
WeekFields weekFields = WeekFields.of(Locale.getDefault()); int weekNumber = now.get(weekFields.weekOfWeekBasedYear()); System.out.println("Week Number of the Year: " + weekNumber); // Display the day of the week (Weekend of the week) System.out.println("Weekend of the Week: " + now.getDayOfWeek());
// Display day of the year
System.out.println("Day of the Year: " + now.getDayOfYear());
// Display day of the month
System.out.println("Day of the Month: " + now.getDayOfMonth());
// Display the day of the week
System.out.println("Day of the Week: " + now.getDayOfWeek()); } } Output: Name: John Doe Code: E123 Pay: 5000.0 Experience: 5 years
Date and Time Information:
Current Date and Time: 2025-01-27 04:43:59 Current Year: 2025 Month of Year: JANUARY Week Number of the Year: 5 Weekend of the Week: MONDAY Day of the Year: 27 Day of the Month: 27 Day of the Week: MONDAY