/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
import java.time.* ;
import java.time.format.* ;
import java.time.temporal.* ;
import java.time.chrono.* ;
import java.time.zone.* ;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
{
LocalDate firstDayOfPayPeriod = LocalDate.of( 2020 , Month.OCTOBER , 23 );
LocalDate firstDayOfSuccessivePayPeriod = LocalDate.of( 2020 , 11 , 7 );
LocalDate dateInQuestion = null;
try
{
dateInQuestion = LocalDate.parse( input );
}
catch ( DateTimeParseException e )
{
// Handle faulty input.
e.printStackTrace();
}
// Validate dates.
Objects.requireNonNull( firstDayOfPayPeriod );
Objects.requireNonNull( firstDayOfSuccessivePayPeriod );
Objects.requireNonNull( dateInQuestion );
if ( ! firstDayOfPayPeriod.isBefore( firstDayOfSuccessivePayPeriod ) )
{
}
if ( dateInQuestion.isBefore( firstDayOfPayPeriod ) )
{
}
if ( ! dateInQuestion.isBefore( firstDayOfSuccessivePayPeriod ) )
{
}
long payPerDay = 100;
long partialPay = 0;
LocalDate localDate = firstDayOfPayPeriod;
while ( localDate.isBefore( firstDayOfSuccessivePayPeriod ) )
{
if ( localDate.isBefore( dateInQuestion ) )
{
partialPay = ( partialPay + payPerDay );
}
// Set up the next loop.
// Notice that java.time uses immutable objects. So we generate a new object based on another’s values rather than alter (mutate) the original.
localDate = localDate.plusDays( 1 ); // Increment to next date.
}
System.
out.
println( "Partial pay earned from firstDayOfPayPeriod " + firstDayOfPayPeriod
+ " to dateInQuestion " + dateInQuestion
+ " is " + partialPay
);
}
}