我必须制作一个程序,它为每个部分使用不同的类。对于第一类:Quest1,我计算了人口的增长率。第二类:Quest2,我必须将增长存储到一个数组中,我有问题,我该怎么做?
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 < 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 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 < a.getDays(); i++)
{
scores[i] = a.getNew(a.getPOP(), i+1, a.getRate());
System.out.println(scores[i]);
}
return;
}