I'm new to java and am given a task to construct a class "magazine" with arrays of "supplements".The supplements have a name and cost to it. What i'm trying to figure out is, how to add like say, 3 supplements into an array under the "magazine".
This is the code for "supplements"
public class Supplements {
String Supplement;
double cost;
public Supplements ()
{
Supplement="abcdef";
cost= 10;
}
public Supplements(String sp, double ct )
{
Supplement = sp;
cost=ct;
}
public String getSupplement()
{
return Supplement;
}
public void setSupplement(String sp)
{
Supplement=sp;
}
public void setcost(double ct)
{
cost=ct;
}
public double getcost()
{
return cost;
}
public String toString()
{
return ("Supplements: "+ Supplement + "\n" + "Weekly cost: "+ cost);
}
And beginning of "magazine". It's suppose to have cost and array of supplements (s1="abc",10; ,s2="def",11; etc etc)
public class Magazine {
double cost;
Supplements[] supplist;
public Magazine ()
{
cost=20;
Supplements[] supplist= new Supplements[1];
I am so sorry if this sounds like gibberish, i have not much experience with coding