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.

