Write a java program to create experience calculator.

Write a program to read Date of Joining and current date as Strings and Experience as integer and validate whether the given experience and calculated experience are the same. Print “true” if same, else “false”.

Input and Output Format:

Input consists of 2 strings and an integer, where the 2 strings correspond to the date of joining and the current date, and the integer is the experience.

The output is either “true” or “false”.

Refer sample output for formatting specifications.

Sample Input 1:

11/01/2010

01/09/2014

4

Sample Output 1:

true

Sample Input 2:

11/06/2009

01/09/2014

4

Sample Output 2:

False

Experience calculator in Java.

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class Main {

  /**
   * @param args
   * @throws ParseException 
   */
  public static void main(String[] args) throws ParseException {
    // TODO Auto-generated method stub
    Date d=new Date();
    Date d1=new Date();
    
    Scanner sc=new Scanner(System.in);
    String a=sc.next();
    String b=sc.next();
    int c=sc.nextInt();
    SimpleDateFormat s=new SimpleDateFormat("dd/MM/yyyy");
    d=s.parse(a);
    d1=s.parse(b);
  long t=d.getTime();
  long t1=d1.getTime();

  long t3=t1-t;
  long l1=(24 * 60 * 60 * 1000);
  long l=l1*365;
  long res=t3/l;
  
  if(res==c)
   {
     System.out.println("true");
   }
  else
     System.out.println("false");
  }

}

Add a Comment

Your email address will not be published. Required fields are marked *

4 × 3 =