Hello evryone I'm having trouble undertstandoing how to use arraylist. Here is what i have to do:
You are to write a program to determine the daily temperature average and keep a running average for up to one week. You will record the temperatures for each day at 6am, noon, and 6pm. The daily average will be the average of these three temperatures. The running average will be the average of the daily averages. You need to be able to print the temperatures and the average for each day. The temperatures will be given in Fahrenheit and should fall between -70 and 130 inclusive.
-------------------------------------------------------------------------------
So far i have created my classes but I do not know how to create my ArrayList so i can retrieve an object from the my DailyTemperature class. Also my DailyTemperature class hass two strings, 3 ints, and 1 double
here is what I got so far from my WeeklyTemp class:
import java.util.ArrayList; public class WeeklyTemp { ArrayList<DailyTemp> dailyAvgs = new ArrayList<DailyTemp>(); DailyTemp obj_1 = new DailyTemp(); public void add(){ for(int i =0; i<dailyAvgs.size();i++){ dailyAvgs.add(obj_1); } } }
and here is my DailyTemp class
public class DailyTemp { private String day, date; private int sixAM, noon, sixPM; private double dailyAvg; public DailyTemp(){ day = ""; date = ""; sixAM = 0; noon = 0; sixPM = 0; dailyAvg = 0.0; } public DailyTemp(String day, String date, int sixAM, int noon, int sixPM, double dailyAvg ){ this.day = day; this.date = date; this.sixAM = sixAM; this.noon = noon; this.sixPM = sixPM; this.dailyAvg = dailyAvg; } public String getDay() { return day; } public void setDay(String day) { this.day = day; } public String getDate() { return date; } public void setDate(String date) { this.date = date; } public int getSixAM() { return sixAM; } public void setSixAM(int sixAM) { this.sixAM = sixAM; } public int getNoon() { return noon; } public void setNoon(int noon) { this.noon = noon; } public int getSixPM() { return sixPM; } public void setSixPM(int sixPM) { this.sixPM = sixPM; } public double getDailyAvg() { return dailyAvg; } public void setDailyAvg(double dailyAvg) { this.dailyAvg = dailyAvg; } @Override public String toString() { return "DailyTemp [day=" + day + ", date=" + date + ", sixAM=" + sixAM + ", noon=" + noon + ", sixPM=" + sixPM + ", dailyAvg=" + dailyAvg + "]"; } }
I will really appreciate any help.. Thanks