Help with class

Hello I had to make a class and a program for a school class. The main idea the Professor wanted us to learn is taking input from a dialog box, and changing the value of the number typed in that input box. Do I have the class done correctly?

public class House

{

// Constructors (remove this comment line)

/** Constructs a brand new House with NO aliens (initialized to 0) */

public House()

{

alienPopulation = 0;

}

/** Constructs a House with a construction parameter */

public House(int alienPopulation)

{

alienPopulation = 0;

}

// Mutator methods (remove this comment line)

/** Leave food on the counter, increasing the population */

public void foodOut(int alienPopulation)

{

int x = (int)(alienPopulation*.5);

int newAlienPopulation = alienPopulation + x;

alienPopulation = newAlienPopulation;

}

/** Clean counters, put away food,

slightly decreasing the population by starvation */

public void foodCleaned(int alienPopulation)

{

int x = (int)(alienPopulation*.2);

int newAlienPopulation = alienPopulation - x;

alienPopulation = newAlienPopulation;

}

/** Take action and spray them with smelly concoction */

public void sprayConcoction(int alienPopulation)

{

int x = (int)(alienPopulation*.4);

int newAlienPopulation = alienPopulation - x;

alienPopulation = newAlienPopulation;

}

/** Take drastic action and call the NASA exterminator */

public void callExterminator(int alienPopulation)

{

int x = (int)(alienPopulation*.9);

int newAlienPopulation = alienPopulation - x;

alienPopulation = newAlienPopulation;

}

// Accessor methods (remove this comment line)

/** Get current number of aliens in house

@return the alienPopulation */

public int getCount()

{

return alienPopulation;

}

// declare your class variable(s) here

private int alienPopulation;

{

alienPopulation = Population.getCount();

}

private int newAlienPopulation;

}

Alien population would go in the input box by the user, and then we have to make the program change that value with the mutator methods.

[2343 byte] By [A_Naked_Penguina] at [2007-11-26 20:32:40]
# 1

> Do I have the class done correctly?

Well, does it compile, run, and give the behavior expected? That's the bare minimum. Beyond that, if your prof had any specific requirements as far as layout, method names, test driver, etc., you'll have to refer to the assignment statement or ask him.

jverda at 2007-7-10 1:23:00 > top of Java-index,Java Essentials,New To Java...
# 2
Well, It compiles fine, but I'm not overwriting any variables? Am I supposed to put the System.in command in the class anywhere or would that go into the tester file?
A_Naked_Penguina at 2007-7-10 1:23:00 > top of Java-index,Java Essentials,New To Java...
# 3

> Well, It compiles fine, but I'm not overwriting any

> variables?

I don't know. Your unformatted code is too hard to read. But even if you were overwriting one or more variables, so what? Is there some reason you're not supposed to?

> Am I supposed to put the System.in command

> in the class anywhere or would that go into the

> tester file?

System.in is not a command. It's a static member variable of the system class, but yes, you'd use that if you want to get user input into a non-GUI app. (Although I think 1.6 has a Console class that hides that.)

For details, go here:

http://java.sun.com/docs/books/tutorial/essential/io/index.html

jverda at 2007-7-10 1:23:00 > top of Java-index,Java Essentials,New To Java...