title: Using Scanner class to take user input for constructor Variables
body: <p>I am trying to use a Scanner object to take in user input that will then be attributed to the following values for an object called TargetHeartRateCalculator.</p>
  
  <p>TargetHeartRateCalculator takes constructor parameters of..</p>
  
  <p>String fName, String lName, int month, int day, int year.</p>
  
  <p>Normally without using the Scanner I would just instantiate the object with the parameters manually like...</p>
  
  <pre><code>TargetHeartRateCalculator patient1 = new TargetHeartRateCalculator("Tom", "Willickers", 01, 25, 1966);
  </code></pre>
  
  <p>I need to use the Scanner to take user input and then from the user recived input assign values to fName, lName, month, day, year.</p>
  
  <p>I have tried making the object instantiation part of the assignment of the user input through the Scanner object by the syntax is not correct and I'm not even really sure if that's how your supposed to do something like this.</p>
  
  <p>I feel like this is probably a simple solution but the answer is quite evasive to me.</p>
  
  <p>Here is my Driver Class...</p>
  
  <pre><code>
  import java.util.Scanner;
  
  public class DriverClass {
  
  
  
          //--------------------------------------------------------------------------------------
          //  TARGET HEART RATE CALCULATOR CLASS FUNCTIONALITY TEST
          //--------------------------------------------------------------------------------------
  
          TargetHeartRateCalculator patient1 = new TargetHeartRateCalculator("Tom", "Willickers", 01, 25, 1966);
          TargetHeartRateCalculator patient2 = new TargetHeartRateCalculator("Bill", "Skarsgard", 8,9, 1990);
  
  
  
          //Write a java app that prompts for the persons information
          //instantiates an object  and prints the information from that object
          //first name, last name, date of birth,
          // calculates maximum heart rate, and target heart rate.
          //and then displays them to the them.
  
          Scanner input = new Scanner(System.in);
  
          System.out.print("Please enter your first name: ");
          String fnInput = input.nextDouble();
          System.out.printf("%nThank you %s %s. Your date of birth is %n" +
                          "%d and you are %d years old!%n" +
                          "Your maximum heart rate is %.2f and your %n" +
                          "Target Heart Rate range is %.2f%n%n" get,
  
  
  
          patientInfo(patient1);
          patientInfo(patient2);
  
          displayAgeYears(patient1);
          displayAgeYears(patient2);
  
          displayMaxHeartRate(patient1);
          displayMaxHeartRate(patient2);
  
          displayTargetHeartRate(patient1);
          displayTargetHeartRate(patient2);
  
  
      }
  }
  
  </code></pre>
  
  <p>Here is my Class</p>
  
  <pre><code>
  import java.time.LocalDateTime;
  
  public class TargetHeartRateCalculator {
      private String fName;
      private String lName;
      private int dOB;
      private int bMonth;
      private int bDay;
      private int bYear;
      private int ageYears;
      private double maxHeartRate;
      private double lowTargetHearRate;
      private double highTargetHearRate;
  
      LocalDateTime now = LocalDateTime.now();
      int cYear = now.getYear();
      int cMonth = now.getMonthValue();
      int cDay = now.getDayOfMonth();
  
      //constructor
      public TargetHeartRateCalculator(String fNameIn, String lNameIn, int monthIn, int dayIn, int yearIn) {
          fName = fNameIn;
          lName = lNameIn;
          bMonth = monthIn;
          bDay = dayIn;
          bYear = yearIn;
      }
  
      public String getfName() {
          return fName;
      }
  
      public void setfName(String fName) {
          this.fName = fName;
      }
  
      public String getlName() {
          return lName;
      }
  
      public void setlName(String lName) {
          this.lName = lName;
      }
  
      public int getBMonth() {
          return bMonth;
      }
  
      public void setBMonth(int month) {
          this.bMonth = month;
      }
  
      public int getBDay() {
          return bDay;
      }
  
      public void setBDay(int day) {
          this.bDay = day;
      }
  
      public int getBYear() {
          return bYear;
      }
  
      public void setBYear(int year) {
          this.bYear = year;
      }
  
      public int getAgeYear(){
          int currentAgeYear = cYear -bYear;
          return currentAgeYear;
      }
  
      public int getAgeMonth(){
          int currentAgeMonth =cMonth - bMonth;
          return currentAgeMonth;
      }
  
      public int getAgeDay(){
          int currentAgeDay =cDay - bDay;
          return currentAgeDay;
      }
  
  
  
      public String getdOB(TargetHeartRateCalculator patient) {
  
          String dOB = String.format("%s/%s/%s",
          patient.getBMonth(), patient.getBDay(), patient.getBYear());
  
          return dOB;
      }
  
      public void setdOB(int dOB) {
          this.dOB = dOB;
      }
  
      public static String displayAgeYears(TargetHeartRateCalculator patient) {
  
          String ageYears = String.format("%s %s is %s Years old",
                  patient. getfName(), patient.getlName(), patient.getAgeYear());
  
          return ageYears;
      }
  
      public void setAgeYears(int ageYears) {
  
          this.ageYears = ageYears;
      }
  
      public double getMaxHeartRate() {
          double maxHeartRate = (220 - getAgeYear()) ;
  
          return maxHeartRate;
      }
  
      public void setMaxHeartRate(int maxHeartRate) {
          this.maxHeartRate = maxHeartRate;
      }
  
      public double getLowTargetHearRate() {
            lowTargetHearRate = getMaxHeartRate() * .5;
  
          return lowTargetHearRate;
      }
  
      public void setLowTargetHearRate(int lowTargetHearRate) {
          this.lowTargetHearRate = lowTargetHearRate;
      }
  
      public double getHighTargetHeartRate(){
          highTargetHearRate = getMaxHeartRate() * .85;
  
          return highTargetHearRate;
      }
  
      public void setHighTargetHearRate(){
          this.highTargetHearRate = highTargetHearRate;
      }
  
      public static String displayTargetHeartRate(TargetHeartRateCalculator patient){
          String hRateRange = String.format("%.2f BPM - %.2f BPM", patient.getLowTargetHearRate(), patient.getHighTargetHeartRate());
  
          return hRateRange;
      }
  
      public static String displayMaxHeartRate(TargetHeartRateCalculator patient){
          String mHeartRate = String.format("%.2f BPM", patient.getMaxHeartRate());
  
          return mHeartRate;
      }
  
  
  
  
      public static String patientInfo(TargetHeartRateCalculator patient) {
  
          String result = String.format("Patient Name: %s %s DOB: %d/%d/%d",
                  patient.getfName(), patient.getlName(), patient.getBMonth(), patient.getBDay(), patient.getBYear());
  
          return result;
  
  
      }
  }
  
  </code></pre>