SHARE
TWEET

Untitled

a guest Jan 28th, 2020 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package ChenIkCie_A2;
  2. import java.io.File;
  3. import java.io.FileNotFoundException;
  4. import java.util.Scanner;
  5.  
  6. // Name : Chen Ik Cie
  7. // Full time student
  8. // Tutorial group : T05
  9. // Declaration : I do this on my own
  10.  
  11. public class ChenIkCie_A2 {
  12.  public static void main(String[] args) throws FileNotFoundException{
  13.     new HRatesTest();
  14. }
  15. }
  16. class HRates {
  17.  
  18.     String fName;
  19.     String lName;
  20.     Date dob;
  21.     int Year;
  22.  
  23.     //Constructor
  24.     public HRates (String fName, String lName, Date dob, int Year) {
  25.         setfName(fName);
  26.         setlName(lName);
  27.         setDOB(dob);
  28.         setYear(Year);
  29.     }
  30.     //Copy Constructor
  31.         public HRates (HRates hr) {
  32.             setfName(hr.getfName());
  33.             setlName(hr.getlName());
  34.             setDOB(hr.getDOB());
  35.             setYear(hr.getYear());
  36.         }
  37.  
  38.         public void setfName (String fName) {
  39.             this.fName = fName;
  40.         }
  41.        
  42.         public String getfName () {
  43.             return fName;
  44.         }
  45.  
  46.         public void setlName (String lName) {
  47.             this.lName = lName;
  48.         }
  49.  
  50.         public String getlName () {
  51.             return lName;
  52.         }
  53.  
  54.         public void setDOB (Date dob) {
  55.             this.dob = dob;
  56.         }
  57.        
  58.         public Date getDOB () {
  59.             return dob;
  60.         }
  61.  
  62.         public void setYear (int Year) {
  63.             this.Year = Year;
  64.         }
  65.  
  66.         public int getYear () {
  67.             return Year;
  68.         }
  69.    
  70.         int maxHRate;
  71.         public int getMaxHRate () {
  72.         maxHRate = 220-getAge();
  73.             return maxHRate;
  74.         }
  75.        
  76.        
  77.         int age;
  78.         public int getAge () {
  79.             age = getYear() - getDOB().getYear();
  80.             return age;
  81.         }
  82.  
  83.  
  84.         double minTarget;
  85.         public double getMinTargetHRate () {
  86.             minTarget = (getMaxHRate()*50)/100;
  87.             return minTarget;
  88.         }
  89.  
  90.         double maxTarget;
  91.         public double getMaxTargetHRate () {
  92.             maxTarget = (getMaxHRate()*85)/100;
  93.             return maxTarget;
  94.         }
  95.  
  96.         public void printWord()
  97.         {
  98.             System.out.printf ("\nName = %s%s", fName, lName);
  99.             System.out.printf ("\nDate of birth = %d %s %d", dob.getDay(), dob.getMonth(), dob.getYear());
  100.             System.out.printf ("\nCurrent Year = " + Year);
  101.             System.out.printf ("\nYour Age = %d %n", getAge());
  102.  
  103.             System.out.printf ("Clinic analysis, based on your age: ");
  104.             System.out.printf ("\n\tYour maximum heart rate is " + getMaxHRate());
  105.             System.out.printf ("\n\tYour minimum heart rate is " + getMinTargetHRate());
  106.             System.out.printf ("\n\tYour maximum target heart rate is " + getMaxTargetHRate());
  107.             System.out.printf ("\n");
  108.  
  109.         }
  110.        
  111. }
  112.  
  113.  
  114. class Date {
  115.  
  116.    
  117.     int day;
  118.     Month month;
  119.     int year;
  120.     int age;
  121.  
  122.     //Constructor
  123.     public Date () {
  124.         setDate(1, Month.Jan, 2019);
  125.     }
  126.    
  127.     //Copy Constructor
  128.         public Date (Date d) {
  129.             setDate(d.getDay(), d.getMonth(), d.getYear());
  130.         }
  131.  
  132.         public int getDay () {
  133.             return day;
  134.         }
  135.  
  136.         public Month getMonth () {
  137.             return month;
  138.         }
  139.  
  140.         public int getYear () {
  141.             return year;
  142.         }
  143.  
  144.     //Parameter Constructor
  145.     public Date (int day, Month month, int year) {
  146.         setDate(day, month, year);
  147.     }
  148.  
  149.  
  150.     public void setDate (int day, Month month, int year) {
  151.         this.day = day;
  152.         this.month = month;
  153.         this.year = year;
  154.     }
  155. }
  156. //Enum for defining months
  157. enum Month {
  158.     Jan,
  159.     Feb,
  160.     Mar,
  161.     Apr,
  162.     May,
  163.     Jun,
  164.     Jul,
  165.     Aug,
  166.     Sept,
  167.     Oct,
  168.     Nov,
  169.     Dec
  170. }
  171.  
  172. class HRatesTest {
  173.  
  174.     public HRatesTest () throws FileNotFoundException {
  175.  
  176.         //creating file and object to be read
  177.         File files = new File ("src/infile.txt");
  178.         Scanner input = new Scanner (files);
  179.  
  180.         Date date = new Date ();
  181.  
  182.         String fName, secondfName;
  183.         String lName, secondlName;
  184.         int Year, secondYear;
  185.  
  186.         //store details in variables
  187.  
  188.         fName = input.nextLine();
  189.         lName = input.nextLine();
  190.         date.setDate (input.nextInt(), Month.valueOf (input.next()), input.nextInt());
  191.         Year = input.nextInt();
  192.  
  193.         //object for this class
  194.         HRates hr1 = new HRates (fName, lName, date, Year);
  195.         hr1.printWord();
  196.  
  197.         input.nextLine();
  198.  
  199.         //second data
  200.         secondfName = input.nextLine();
  201.         secondlName = input.nextLine();
  202.         Date date1 = new Date();
  203.         date1.setDate (input.nextInt(), Month.valueOf (input.next()), input.nextInt());
  204.         secondYear = input.nextInt();
  205.  
  206.         HRates hr2 = new HRates (secondfName, secondlName, date1, secondYear);
  207.  
  208.         hr2.printWord();
  209.  
  210.     }
  211. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top