Note that there are some explanatory texts on larger screens.

plurals
  1. POStoring from one class to another in an array
    primarykey
    data
    text
    <p>I have to make a program which uses a different class for each part. For the first class: Quest1, I calculated the rate of growth in a population. Second class: Quest2, i have to store the growth into an array, theres where im having a problem, how would I go about doing that? </p> <pre><code>public class Quest1 { public double pop, rate; public int day; public void setPop(double population) { pop = population; } public double getPOP() { return pop; } public void setRate(double rates) { rate = rates; } public double getRate() { return rate; } public void setDay(int days) { day = days; } public double getDays() { return day; } public double getNew(double pop, int day, double rate) { double popul, population = 0; for (double i = 0; i &lt; day; i++) { popul = pop + (pop * rate/100); population = day*popul; } return population; } </code></pre> <p>}</p> <pre><code>public class Main { public static void main(String[] args) throws IOException{ Scanner kd = new Scanner(System.in); Quest1 a = new Quest1(); Quest2 b = new Quest2(); double tempPop, tempRate; int tempDay; System.out.println("Enter Population: "); tempPop = kd.nextDouble(); a.setPop(tempPop); System.out.println("Enter Days: "); tempDay = kd.nextInt(); a.setDay(tempDay); System.out.println("Enter Rate: "); tempRate = kd.nextDouble(); a.setRate(tempRate); b.storeArray(); } public class Quest2 { Quest1 a = new Quest1(); public void storeArray(){ double scores [] = new double[(int) a.getDays()]; for(int i = 0; i &lt; a.getDays(); i++) { scores[i] = a.getNew(a.getPOP(), i+1, a.getRate()); System.out.println(scores[i]); } return; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload