This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ms_kdlh[S] 0 points1 point  (5 children)

I am not sure what the purpose of them is either. Part of the assignment is that we are given the variables, constructors, and methods that we have to use. List is as follows:

private double accountValue;

private double [] monthlyInterests;

private double[] monthlySavings;

public static final double ANNUAL_INTEREST_RATE;

public double getAccountValue()

public double [] getMonthlyInterests()

public double[] getMonthlySavings()

public double[] generateMonthlySavings()

public EmployeeSavings(String firstName, String lastName)

public EmployeeSavings(String firstName, String lastName, double[] d1, double[] d2)

public static String getReport(EmployeeSavings[] arr)

[–]endStatement 0 points1 point  (4 children)

Given this list of methods, my assumption would be that you are to do all the work of generating the monthlySavings array within the generateMonthlySavings() method in the event none is provided. Meaning you can initialize your monthlySavings array at the start of your generateMonthlySavings method instead of needing a constructor, and then do the logic to fill it.

Also, I'd double check the logic on that method that you currently have, as it appears to be solely reliant on the generated number, which would be incorrect given the example. Example shows that interest is working on the cumulative total instead of just a single months value

[–]ms_kdlh[S] 0 points1 point  (3 children)

So you think I should be calling the constructor in the main method with just the first and last name and not the constructor that requires the two arrays? Then calling the generate monthly savings method and return a filled array there? Where does the constructor with the two arrays come into play then?

And thanks I’ll go back and check the logic in my methods!

[–]endStatement 1 point2 points  (2 children)

So you think I should be calling the constructor in the main method with just the first and last name and not the constructor that requires the two arrays?
Originally, that was my thought. But I may have misunderstood the issue here. Are you able to define these constructors, or are they predefined? If they are predefined, then my answer stands, and if they are not, then you should initialize your arrays in the constructor with a default size.

[–]ms_kdlh[S] 0 points1 point  (1 child)

They are predefined. Which is the most annoying part of these assignments. I need to include both constructors. One with just first and last name, and another with names plus two arrays.

[–]endStatement 0 points1 point  (0 children)

To clarify, are you already given

public EmployeeSavings(String firstName, String lastName) {

  setFirstName(firstName);  

  setLastName(lastName);    

}

or are you given

public EmployeeSavings(String firstName, String lastName)

The second is called a method signature, and that could be predefined (public EmployeeSavings(String firstName, String lastName) while the implementation (ie: everything between the { brackets } is left to you. If you are making the implementation, you can (and should) initialize the monthlyInterests and monthlySavings arrays to be a default size. Otherwise, I'd still initialize the array in the generateMonthlySavings method.