I am writing a program which will take a list of temps and days and implement the list using an array of object. each object will store the temp(double) and day(string). then we need to sort the objects and output them. I created my first class(DailyTemperature) with the two variables, get/set methods, and a constructor. Now when I go to create my second class(DailyTemperatureList) with the ArrayList in it I get an error when trying to add to the list the error says "no suitable method found for add(java.lang.String,double) method java.util.ArrayList.add(int,DailyTemperature) is not applicable (actual argument java.lang.String cannot be converted to int by method invocation conversion) method java.util.ArrayList.add(DailyTemperature) is not applicable actualy and formal lists differ in length.
I assume its because I am trying to use variables from the DailyTemperature class.but when i extend it i get an error saying constructor DailyTemperature in class DailyTemperature cannot be applied to given types. I am not sure why. Am i not supposed to be extending and perhaps do something else?
Here is my code:
import java.io.*;
import java.util.Scanner;
import java.util.ArrayList;
public class DailyTemperature
{
//variables
private double temperature;
private String day;
//getTemp & setTemp methods
public double getTemp()
{
return temperature;
}
public void setTemp(double newTemp)
{
temperature = newTemp;
}
//getDay & setTEmp methods
public String getDay()
{
return day;
}
public void setDay(String newDay)
{
day = newDay;
}
public DailyTemperature(String day, double temperature) {
this.day = day;
this.temperature = temperature;
}
}
import java.io.*;
import java.util.Scanner;
import java.util.ArrayList;
public class DailyTemperatureList extends DailyTemperature
{
public static void main (String [] args) {
ArrayList<DailyTemperature> dailytemps = new ArrayList<DailyTemperature>();
dailytemps.add("Mon", 78.1);
}
}