What have you done so far?
Well, I done some stuff, but I'm uncertain about the rest. I have to classes and one client. It's working now, but as it should do. Now I've decided the Humans information, but this should also be done by the user. As you can see above, there are several things that ain't working... I hope you can help me a bit!
class Human {
// Constants
final static boolean MALE = false;
final static boolean FEMALE = true;
// Field variables
private String name;
private boolean gender;
private int age, ID;
// Constructors
Human()
Human(String name, boolean gender, int age, int ID) {
this.name=name;
this.gender=gender;
this.age=age;
this.ID=ID;
}
void putName(String HumanName) { name=HumanName; }
void putAge(int HumanAge) { age=HumanAge; }
void putID(int HumanID) { ID = HumanID; }
void putGender(boolean givenGender) { gender= givenGender; }
String getName() { return name; }
int getAge() {return age; }
int getID() {return ID; }
boolean getGender() {return gender; }
boolean isMALE() { return (gender == MALE); }
boolean isFEMALE() { return (gender == FEMALE); }
public String twoString() {
String genderInfo;
if (gender)
genderInfo = "FEMALE";
else
genderInfo = "MALE";
return String.format("name: %s ID: %d age: %d" + "gender: %-11s", name, ID, age, genderInfo);
}
}
public class Town {
// Field declaration
private Human[] HumanTable;
private int numberOfHumans;
// Standard constructor
Town() {
HumanTable = new Human[30];
}
// Establishes a Town from a Table with Humans
Town(Human[] givenHumanTable) {
HumanTable = new Human[30];
for(int i=0; i < givenHumanTable.length; i++)
addHuman(givenHumanTable[i]);
}
// Constructor which receives field values as parameters.
Town(Human[] HumanTable, int numberOfHumans) {
this.HumanTable = HumanTable;
this.numberOfHumans = numberOfHumans;
}
// Places a Human in the Human Table.
void addHuman(Human newHuman) {
assert numberOfHumans != HumanTable.length: "No more room for Humans.";
HumanTable[numberOfHumans] = newHuman;
numberOfHumans++;
}
// Selectors
int getnumberOfHumans() { return numberOfHumans; }
Human[] getHumanTable() { return HumanTable; }
// Returns Human which has a given ID.
Human getHuman(int ID) {
assert 0 <= ID && ID <= numberOfHumans : "Illegal ID-number";
return HumanTable[ID];
}
// Returns statistics over Humans.
public String twoString() {
return String.format("The Town has %d Humans.", getnumberOfHumans());
}
}
import java.util.Scanner;
public class Client1 {
// Field
private Town town1;
// Constructor
Client1() {
town1 = new Town();
}
Client1(Town town1) {
this.town1 = town1;
}
// Write statistics
void writeReport() {
System.out.print(town1);
}
void writeAllHumansToTerminalWindow() {
Human[] HumanTable = town1.getHumanTable();
int numberOfHumans = town1.getnumberOfHumans();
System.out.println("Number of Humans: " + numberOfHumans);
for (int i=0; i<numberOfHumans; i++)
System.out.println(HumanTable[i]);
}
public static void main(String[] args) {
// Establish a Table with Humans.
Human[] HumanInfo = {
new Human("Alex",FEMALE,2,1),
new Human("John",MALE,3,2)
};
// Establish a Town.
Town register = new Town(HumanInfo);
// Establish a Client.
Client1 Paris = new Client1(register);
// Write alle information about Humans to terminal window.
Paris.writeAllHumansToTerminalWindow();
Paris.writeReport();
}
}