New to this, need help with arrays please.
I am trying to make a function that checks to see if my array is full, and if it is, 5 slots are added to the end of the array. This is waht I havve so far, I've been given two errors.
publicvoid add(double opening,double high,double low,double closing,long volume)
{
Cdate.add(Calendar.DATE, 1);
if(Cdate.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)
{
Cdate.add(Calendar.DATE, 2);
}
DailyInfo[] D2 = newDailyInfo[currentSize];
->if(DailyInfo D2[D1[].length] = D1[] - 1)
{
currentSize = currentSize + 5;
D2 = D1.clone();
D1 = D2;
}
->}
I get a ' ) ' expected error on the top arrow
I get an 'Illeal start of expression' errow on the bottom arrow.
Any Idea why? And I just missing something really simple?
Can you explain what you expect this line to do?if(DailyInfo D2[D1[].length] = D1[] - 1)
There's several problem with it and it may be causing the second error. You definitely want to remove the DailyInfo and use == instead of =, but I can't figure out what you want "D1[]-1" to do.
WEll, I'm past that. I'm now trying to construct an array that has six bvariables per slot. A GregorianCalander, four doubles and one long.
this is the coding I ahve so far.
import java.lang.*;
import java.util.*;
import java.io.*;
public class Company{
DailyInfo[] D1;
final int BASESIZE = 5;
int current=0;
GregorianCalendar Cdate;
String name, symbol;
public void Company(String Cname, String Csymbol, GregorianCalendar
startDate)
{
//D1 = new DailyInfo[BASESIZE];
name = Cname;
symbol = Csymbol;
Cdate = (GregorianCalendar)startDate.clone();
System.out.printf("\n\n%tm/%1$td/%1$tY%n", Cdate);
}
public void add(double opening, double high, double low, double closing,
long volume)
{
Cdate.add(Calendar.DATE, 1);
current++;
if(Cdate.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)
{
Cdate.add(Calendar.DATE, 2);
}
if(current>=D1.length)
{
DailyInfo[] D2 = new DailyInfo[current+5];
D2 = D1.clone();
D1 = D2;
}
DailyInfo[] D1 = new DailyInfo(GregorianCalendar, double, double, double, double, long)
}
public double getHighest()
{
int cur = 0;
for(int high=0; high <= current; high++)
{
if(D1[high].high > cur)
cur = D1[high];
}
return(cur);
}
public double getLowest()
{
int curr = 10000000;
for(int low=0; low <= current; low++)
{
if(D1[low].low < curr)
curr = D1[low];
}
return(curr);
}
public String toString()
{
return(null);
}
}
ummm, sry, I wasn't to explicit in what I was trying to accomplish or what my problem was.
[code]DailyInfo[] D1 = new DailyInfo(GregorianCalendar, double, double, double, double, long);/code
its saying: Class Expected and ')' expected. on that line of code. and I apologize for the spacing, my program isn't great for copy paste.
allright, figured out the class problem. I still have the ' ) ' expected error.DailyInfo[] D1 = new DailyInfo[GregorianCalendar, double, double, double, double, long];
code]DailyInfo[] D1 = new DailyInfo[GregorianCalendar, double, double, double, double, long];[/code]Are you trying to declare an array or trying to instantiate a D1 object? The left side of the = is declaring an array. Then "new DailInfo" is the start of instantiating an object. But then you have the arguments inside [ and ]. And you need to supply variable names for the arguments. My guess is you meanDailyInfo D1 = new DailyInfo(GregorianCalendar cal, double first ,
double second, double third, double fourth, long fifth);
yeah, that's what I'm looking for, and i've tried that before
DailyInfo D1 = new DailyInfo(GregorianCalendar date, double opening , double high, double low, double closing, long volume);
That's what I have inputted based on what you said. It has all the variable names I am looking for.
I still get the ' ] ' expected though... I'm beggining to think its just the program.
I also tried
DailyInfo[] D1 = new DailyInfo(GregorianCalendar date, double opening , double high, double low, double closing, long volume);