I am needing help with creating a simple Java program Here i

I am needing help with creating a simple Java program. Here is the exercise:

Write a program that reads from the console, a person’s first name, current age, and a year in the future and then displays the person’s name and future age based on the future year. Your main will gather the input and then call a method displayFutureAge(name, currentage, futuredate) that will calculate the future age, based off of the year 2016, and then display the information. Use simple arithmetic to calculate the future age.

For example,

Enter name: Tom

Enter current age: 33

Enter future year: 2050

Output will be:

Tom will be 67 years old in the year 2050.

Solution

FutureAge.java

import java.util.Calendar;
import java.util.Scanner;

public class FutureAge {

   public static void main(String[] args) {
       //Scanner class object is used to read the inputs entered by the user
       Scanner sc=new Scanner(System.in);
      
       //Getting the name entered by the user
       System.out.print(\"Enter Name :\");
       String name =sc.next();
      
       //Getting the age entered by the user
       System.out.print(\"Enter current age: \");
       int currentage=sc.nextInt();
      
       //Getting the future year entered by the user
       System.out.print(\"Enter future year: \");
       int futuredate=sc.nextInt();
      
       //Calling the method by passing the user entered inputs as arguments
       displayFutureAge(name, currentage, futuredate);
  
      

   }

   // This method will calculate the future age and display
      private static void displayFutureAge(String name, int currentage,
           int futuredate) {
         
          //Getting the Calendar class object
       Calendar present= Calendar.getInstance();
      
       //Getting the current year
       int presentYear=present.get(Calendar.YEAR);
      
  
       int yearDiff=futuredate-(presentYear-1);
      
       //Displaying the output
   System.out.println(\"Tom will be \"+(currentage+yearDiff)+\" years old in the year \"+futuredate+\".\");
      
      
   }

}

______________________

Output:

Enter Name :Tom
Enter current age: 33
Enter future year: 2050
Tom will be 67 years old in the year 2050.

___________Thank You

I am needing help with creating a simple Java program. Here is the exercise: Write a program that reads from the console, a person’s first name, current age, an
I am needing help with creating a simple Java program. Here is the exercise: Write a program that reads from the console, a person’s first name, current age, an

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site