Program opened below. You can scroll through the algorithm, Java code and output.

Project Submission Date with Sunday Extension

Download .java

Question

Accept a project-given date and the weekday name. The project is due after 90 days including the given day; if the resulting submission day is Sunday, allow one extra day. Display the final date and weekday.

Step 1: Start. Step 2: Declare the variables and data structures required for the task. Step 3: Input the date and the weekday name. Step 4: Parse the date using dd/MM/yyyy. Step 5: Initialize the counters, flags, accumulators or result structures needed by the solution. Step 6: Validate that the entered weekday matches the calendar weekday. Step 7: Set dueDate to givenDate plus 89 days because the given day counts as day 1. Step 8: If dueDate falls on Sunday, add one day. Step 9: Store the computed result and prepare it for display. Step 10: Display the final date and weekday. Step 11: Stop.
Java
import java.time.*;
import java.time.format.*;
import java.util.*;
class ProjectDueDate {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String raw = sc.nextLine().trim();
        String dayName = sc.nextLine().trim();
        try {
            LocalDate given = LocalDate.parse(raw, DateTimeFormatter.ofPattern("dd/MM/uuuu"));
            if (!given.getDayOfWeek().getDisplayName(java.time.format.TextStyle.FULL, Locale.ENGLISH).equalsIgnoreCase(dayName)) {
                System.out.println("INVALID DAY NAME");
                return;
            }
        LocalDate due = given.plusDays(89);
        if (due.getDayOfWeek() == DayOfWeek.SUNDAY) {
            due = due.plusDays(1);
        }
    System.out.println(due.format(DateTimeFormatter.ofPattern("dd/MM/uuuu")));
    System.out.println(due.getDayOfWeek().getDisplayName(java.time.format.TextStyle.FULL, Locale.ENGLISH));
}
catch (DateTimeParseException ex) {
    System.out.println("INVALID DATE");
}
}
}
Input: 01/01/2024 Monday Output: 30/03/2024 Saturday
← Previous Program 73 of 84 Next →

Share a comment or request a program

Use this form to send a comment, report an issue, or suggest a new practical. Your message will be saved for review by the school.