Method must have a return class and the name "lake" and thermocline" does not exist in the current c

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I;m trying to do my project but its proving very unsuccessful
Im getting different variatins of the 3 errors
1. Method must have a return class
2. The name "lake" does not exist in the current context
3. the name "thermocline" does not exist in the current context

<pre>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args);
public class Lake
{
private string name; // Lake name
private double depth; // Depth in m
private double area; // Area in km^2
private Observation[] data; // (Depth, temperature, oxygen concentration)

private static int nbrLakes = 0; // Number of lakes in program
public const double mino2 = 5; // Min allowable level (mg/L)

public Lake(string n, double a, double d, Observation[] dd)
{
name = n;
area = a;
depth = d;
data = dd;
nbrLakes++; // Increment number of lakes each time constructor run
}

public static int NbrLakes
{
get
{
return nbrLakes;
}
}

public double Area
{
get
{
return area;
}
}

public double Depth
{
get
{return depth;}
}

public string Name
{
get
{
return name;
}
}
double Thermocline;

public Array get ;
Thermocline()
{
double maxTempChange = 0;
int topOfThermocline = -1;
int bottomOfThermocline = -1;
double length;



// Loop thru temperatures, find biggest change between adjacent data
for (int i = 1; i < dd.length; i++)
{
double tempChange = data[i-1].temp - data.temp;
if (tempChange >= maxTempChange)
{
maxTempChange = tempChange;
topOfThermocline = i-1;
bottomOfThermocline = i;
}
}


// Starting from bottom of biggest change, see if equal or nearly equal
// (within 1 degree) changes continue below it. If so, expand cline
for (int i = bottomOfThermocline + 1; i < length; i++)
{
double tempChange = data[i-1].temp - data.temp;
if (tempChange > maxTempChange - 1)
{
bottomOfThermocline = i;
}
else
{
break;
}
}

// Starting from top of biggest change, see if equal or nearly equal
// (within 1 degree) changes continue above it. If so, expand cline
for (int i = topOfThermocline; i >= 0; i--)
{
double tempChange = data[i-1].temp - data.temp;
if (tempChange > maxTempChange - 1)
{
topOfThermocline = i-1;
}
else
{
break;
}
;
}}

}


// Static method must get data array as argument; it has no access to it
// in the object
public static double getMinTemp(Observation[] d)
{


double minTemp = 9999;

for (int i = 0; i < d.length; i++)
{
if (d.temp < minTemp)
{
minTemp = d.temp;

}
return minTemp;
}}


public static double getMaxTemp(Observation[] d)
{
double maxTemp = -9999;
for (int i = 0; i < d.length; i++)
{
if (d.temp > maxTemp)
{
maxTemp = d.temp;
}
}
return maxTemp;



}
public double[ ] AvgOxygen
{
get
{
// Run method to get thermocline; cant assume its been run
Array cline = Thermocline;
// Get the top and bottom depths of the cline
double top = (int)((double) Thermocline [0]);
double bottom = (int)((double) Thermocline [1]);


double length ;

// Find the indices in the data array of the top and bottom of cline
int topOfThermocline = -1, bottomOfThermocline = -1;
for (int i=0; i < length ; i++)
{

double depth;

if (depth == top)
{topOfThermocline= i;}
if (depth == bottom)
{bottomOfThermocline= i;}
}


// Compute avg oxygen concentration above cline
double sumOxyAbove = 0, sumOxyBelow = 0;
for (int i = 0; i < topOfThermocline; i++)
{
double oxygen;
sumOxyAbove += oxygen;
}
double avgOxyAbove = sumOxyAbove / topOfThermocline;

double length;



// Compute avg oxygen concentration below cline
for (int i = bottomOfThermocline + 1; i <length; i++)
{ double oxygen;

sumOxyBelow = + oxygen;
}
double avgOxyBelow = sumOxyBelow / (length - bottomOfThermocline-1);

// Place results into array, which is return value
double[] result = new double[2];
result[0]= avgOxyAbove;
result[1]= avgOxyBelow;
return result;
}
}

public bool isOxyBelowOK()
{



{

// Compute oxygen levels first (which in turn compute cline)
double[] oxygen = AvgOxygen;
double oxyBelow = oxygen[1]; // Bottom oxy concentration
return (oxyBelow > 5.0);
}
}
}


public class Observation
{
public double depth;
public double temp;
public double oxygen;

public Observation
(double d,
double t,
double o)
{
depth= d;
temp= t;
oxygen = o ;
}
}


public class LakeTest
{

static void Main(string[] args);

public class observation{


public class Laketest
{
public static void Main(string[] args)
{
// creates the four lakes, along with the data for each lake: (depth, temperature, oxygen concentration)

Observation[] Nepessing = new Observation[11];

Nepessing[0] = new Observation(0.0, 23.0, 15.0);
Nepessing[1] = new Observation(1.0, 23.0, 14.0);
Nepessing[2] = new Observation(2.0, 23.0, 14.0);
Nepessing[3] = new Observation(3.0, 22.0, 14.0);
Nepessing[4] = new Observation(8.0, 20.0, 14.0);
Nepessing[5] = new Observation(9.0, 20.0, 15.0);
Nepessing[6] = new Observation(10.0, 19.0, 14.0);
Nepessing[7] = new Observation(12.0, 12.0, 7.0);
Nepessing[8] = new Observation(18.0, 11.0, 7.0);
Nepessing[9] = new Observation(23.0, 10.0, 7.0);
Nepessing[10] = new Observation(29.0, 10.0, 6.0);

Observation[] Hadley = new Observation[11];

Hadley[0] = new Observation(0.0, 23.0, 15.0);
Hadley[1] = new Observation(1.0, 23.0, 14.0);
Hadley[2] = new Observation(2.0, 23.0, 14.0);
Hadley[3] = new Observation(3.0, 22.0, 14.0);
Hadley[4] = new Observation(8.0, 20.0, 14.0);
Hadley[5] = new Observation(9.0, 20.0, 15.0);
Hadley[6] = new Observation(10.0, 19.0, 14.0);
Hadley[7] = new Observation(12.0, 12.0, 7.0);
Hadley[8] = new Observation(18.0, 11.0, 7.0);
Hadley[9] = new Observation(23.0, 10.0, 7.0);
Hadley[10] = new Observation(29.0, 10.0, 6.0);

Observation[] Fish = new Observation[9];

Fish[0] = new Observation(0.0, 26.0, 11.0);
Fish[1] = new Observation(1.0, 25.0, 11.0);
Fish[2] = new Observation(2.0, 24.0, 11.0);
Fish[3] = new Observation(4.0, 24.0, 10.0);
Fish[4] = new Observation(5.0, 23.0, 11.0);
Fish[5] = new Observation(8.0, 20.0, 10.0);
Fish[6] = new Observation(9.0, 17.0, 9.0);
Fish[7] = new Observation(11.0, 17.0, 9.0);
Fish[8] = new Observation(13.0, 17.0, 10.0);

Observation[] Ortonville = new Observation[9];

Ortonville[0] = new Observation(0.0, 26.0, 11.0);
Ortonville[1] = new Observation(1.0, 25.0, 11.0);
Ortonville[2] = new Observation(2.0, 24.0, 11.0);
Ortonville[3] = new Observation(4.0, 24.0, 10.0);
Ortonville[4] = new Observation(5.0, 23.0, 11.0);
Ortonville[5] = new Observation(8.0, 20.0, 10.0);
Ortonville[6] = new Observation(9.0, 17.0, 9.0);
Ortonville[7] = new Observation(11.0, 17.0, 9.0);
Ortonville[8] = new Observation(13.0, 17.0, 10.0);



// Loop through ArrayList and invoke all methods on lakes
for (int i = 0; i < lakes.size(); i++)
{


// Get Lake from ArrayList; cast from Object to Lake


Lake o = (Lake) lakes.get(i);

if( Lake.GetType())

Console.WriteLine("Lake: " + o.Name);
Console.WriteLine(" Area: " + o.Area);
Console.WriteLine(" Depth: " + o.Depth);

// Get thermocline results and extract them from the ArrayList
// that is the return value.
// Cast from Object to Double, then extract double from Double!

Array cline = o.Thermocline;
double topZ = (double)( thermocline[0]);
double bottomZ = (double)( thermocline[1]);
double tempDiff = (double)( thermocline[2]);
Console.WriteLine(" Top of Thermocline: " + topZ);
Console.WriteLine(" Bottom of Thermocline: " + bottomZ);
Console.WriteLine(" Thermocline temperature diff: " + tempDiff);

// Get oxygen concentration results and extract them from array
// that is the return value.
double[] oxy = o.AvgOxygen;
Console.WriteLine(" Average oxygen top: " + oxy[0]);
Console.WriteLine(" Average oxygen bottom: " + oxy[1]);

bool oxyOK = o.OxyBelowOK;

Console.WriteLine("o2 below OK?: " + oxyOK);
}

// To invoke static methods, we must send in arguments for all the
// data on which they operate. Invoke method on class name, not
// object name, for clarity.





Console.WriteLine("nLake Nepessing temperatures");
Console.WriteLine(" Min temperature: " + Lake.getMinTemp(Nepessing));
Console.WriteLine(" Max temperature: " + Lake.getMaxTemp(Nepessing));

Console.WriteLine("nLake Hadley temperatures");
Console.WriteLine(" Min temperature: " + Lake.getMinTemp(Hadley));
Console.WriteLine(" Max temperature: " + Lake.getMaxTemp(Hadley));

Console.WriteLine("nLake Ortonville temperatures");
Console.WriteLine(" Min temperature: " + Lake.getMinTemp(Ortonville));
Console.WriteLine(" Max temperature: " + Lake.getMaxTemp(Ortonville));

Console.WriteLine("nFish Lake temperatures");
Console.WriteLine(" Min temperature: " + Lake.getMinTemp(Fish));
Console.WriteLine(" Max temperature: " + Lake.getMaxTemp(Fish));

Console.WriteLine("nNumber of lakes: "+ Lake.nbrLakes);
}
}
}
}
}






[/code]



View the full article
 
Back
Top