Hi, I'm having some trouble figuring out how to change the value of a variable that is passed into a class.
I've tried just changing the variable, I've tried changing it by using the this.variable command, and I've even tried calling the setter class from within the class to change it, but it's still not working right. Any help would be appreciated.
The first class is the one with Main in it and I just feed it some dummy data:
public class ExamConverter { public static void main(String[] args) { // TODO Auto-generated method stub Age testAge = new Age(); testAge.setTestDay(4); testAge.setTestMonth(5); testAge.setTestYear(2014); testAge.setClientDay(5); testAge.setClientMonth(5); testAge.setClientYear(1971); System.out.println("Test: " + testAge.getTestMonth() + "/" + testAge.getTestDay() + "/" + testAge.getTestYear()); System.out.println("DOB: " + testAge.getClientMonth() + "/" + testAge.getClientDay() + "/" + testAge.getClientYear()); System.out.println("Age Years: " + testAge.AgeYears() + " Months: " + testAge.AgeMonths() + " Days: " + testAge.AgeDays()); } }
This is the other class to calculate the age the way we do it on psych tests - it might not be mathematically accurate, but it's what all the tables and such for raw to scaled score conversion are based on, so the math needs to be the same as opposed to "accurate" because of some months having 30 or 31 days, etc.
public class Age { //==================Properties================== // Variables for the test date and client date of birth private int TestMonth; private int TestDay; private int TestYear; private int ClientMonth; private int ClientDay; private int ClientYear; //==================Constructor================== public Age(){ } //=================Property Methods================ // Used to change state of the class - getters and setters public int getTestMonth() { return TestMonth; } public void setTestMonth(int testMonth) { TestMonth = testMonth; } public int getTestDay() { return TestDay; } public void setTestDay(int testDay) { TestDay = testDay; } public int getTestYear() { return TestYear; } public void setTestYear(int testYear) { TestYear = testYear; } public int getClientMonth() { return ClientMonth; } public void setClientMonth(int clientMonth) { ClientMonth = clientMonth; } public int getClientDay() { return ClientDay; } public void setClientDay(int clientDay) { ClientDay = clientDay; } public int getClientYear() { return ClientYear; } public void setClientYear(int clientYear) { ClientYear = clientYear; } //=================General Methods================== // Calculate years, months, days old based on pen & paper // methods. public int AgeDays(){ int Days = 0; if (ClientDay > TestDay){ this.TestMonth--; this.TestDay = TestDay+30; }else{ Days = TestDay - ClientDay; } return Days; } public int AgeMonths(){ int Months = 0; if (ClientMonth > TestMonth){ this.TestYear--; this.TestMonth = TestMonth+12; }else{ Months = TestMonth - ClientMonth; } return Months; } public int AgeYears(){ int Years = 0; Years = TestYear - ClientYear; return Years; } }
Based on this dummy data, the output is:
Test: 5/4/2014
DOB: 5/5/1971
Age Years: 43 Months: 0 Days: 0
However, it should be:
Test: 5/4/2014
DOB: 5/5/1971
Age Years: 42 Months: 11 Days: 29
Thanks in advance!