java - Storing from one class to another in an array -
i have make program uses different class each part. first class: quest1, calculated rate of growth in population. second class: quest2, have store growth array, theres im having problem, how go doing that?
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; (double = 0; < day; i++) { popul = pop + (pop * rate/100); population = day*popul; } return population; }
}
public class main { public static void main(string[] args) throws ioexception{ scanner kd = new scanner(system.in); quest1 = 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 = new quest1(); public void storearray(){ double scores [] = new double[(int) a.getdays()]; for(int = 0; < a.getdays(); i++) { scores[i] = a.getnew(a.getpop(), i+1, a.getrate()); system.out.println(scores[i]); } return; }
i think need pass quest1 object quest2 class.
b.storearray(a);
you creating new object of quest1 in quest2.so not calculate growth. modify in quest2 class.
public void storearray(quest1 a){..}
hope asking this.
Comments
Post a Comment