Help - Search - Members - Calendar
Full Version: Simple Java Help
Achaea's Forums > Off-Topic > Tech Support
Spudd
Ok, so I'm doing a beginner Java course, and the aim of this part was to make a class for a simple water tank. When I try to create a new object I get an error, ';' expected, but I can't see where I left out the semicolon! Anyone able to point out where I've gone wrong? I don't get any errors when I compile.

CODE
/**
* Class WaterTank - a simple mode of a water tank, that has
* inflows and outflows, designed to illustrate the concepts
* of classes, objects and methods.
*/
public class WaterTank
{
private int volume;
private int tankID;
private String tankName;
private int capacity;
private boolean isFull;
private int numInflows;
private int numOutflows;
private int MaximumVolume;
private int MinimumVolume;

public WaterTank(String tName, int tID, int vol, int cap)
{
volume = vol;
tankID = tID;
tankName = tName;
numInflows = 1;
capacity = cap;
MaximumVolume = volume;
MinimumVolume = volume;
}

public int getVolume()
{
return volume;
}

public void inflow(int amount)
{
volume = volume + amount;
numInflows = numInflows + 1;
if (volume > MaximumVolume) {
MaximumVolume = volume;
}
}

public void outflow(int amount)
{
volume = volume - amount;
numOutflows = numOutflows + 1;
if (volume < MinimumVolume) {
MinimumVolume = volume;
}
}

public int getTotalInflows()
{
return numInflows;
}

public int getTotalOutflows()
{
return numOutflows;
}

public boolean isFull()
{
if (volume >= capacity) {
return true;
} else {
return false;
}

}

public int getMaximumVolume()
{
return MaximumVolume;
}

public int getMinimumVolume()
{
return MinimumVolume;
}

public int draining(double rate)
{
int seconds;
int x = volume - capacity;
double y = rate;

seconds = (int) (x/y);
return seconds;
}
}
Soludra
This probably isn't the best place to ask for Java help - this forum is mostly about Achaea-related scripting/triggers/etc. That said...

Getting an error about missing a semicolon makes no sense unless it's at compile time. What're the error details? Can you tell us anything else about what's going on? Where are you creating a WaterTank object? That seems like a possible place if it occurs when you're creating a new one.

In the interest of keeping the forum on topic, feel free to PM me if you want to continue it in private. smile.gif
Bannin
QUOTE
this forum is mostly about Achaea-related scripting/triggers/etc.
No, that's what the "Client Help" subforum is for.

My java is a bit rusty, but is that the entire error message?
Lana
Compiled okay for me. Can't spot any errors either.

Post the complete output from the compiler?
Soludra
It's almost definitely not the WaterCooler class. If that class compiles fine, and you get a compile error about a semicolon where you instantiate an object of that class, then it's almost certainly a problem with the class that's instantiating a new WaterCooler.

(I already PM'ed him this.)
Spudd
Oh my god, noob noob noob. I didn't put inverted commas around the string when creating the object. The message was

Error. ";" expected.

The commas were so small it only looked like one though. Thanks for your intent to help, though!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.