473,322 Members | 1,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

please help me (object modelling)

Hi. I hope someone can help me with this-

First there is a category Human, which has information about name, gender, age and unique ID.

Human shall be saved in a class Town using a table.

The constructor Town(int numberhumans) has parameters, which says the number of humans the town can have (maximum). The program shall let the user do as followed:

- make a Town
- add a Human
- change the information to the Human
- delete the Human
- get out a list with the context
- print the context in Human to a text file
- read the context in Human from a text file
- print the Humans in correct order of age (1,2,3...).

I hope someone can help me :) I really need it...
Nov 15 '06 #1
8 1489
Ganon11
3,652 Expert 2GB
What have you done so far?
Nov 16 '06 #2
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();
}
}
Nov 17 '06 #3
horace1
1,510 Expert 1GB
a couple of things
(1) in class Human you missed the {} off the constructor
Expand|Select|Wrap|Line Numbers
  1. Human() {}     //** missing {}
  2.  
did you mean to set the instance variables to default values?

and in class Client1 in main() you missed the Human. off FEMALE and MALE (which are data members of Human) in the statements
Expand|Select|Wrap|Line Numbers
  1. new Human("Alex",Human.FEMALE,2,1),  // ** missing Human.
  2. new Human("John",Human.MALE,3,2)
  3.  
Nov 17 '06 #4
a couple of things
(1) in class Human you missed the {} off the constructor
Expand|Select|Wrap|Line Numbers
  1. Human() {}     //** missing {}
  2.  
did you mean to set the instance variables to default values?

and in class Client1 in main() you missed the Human. off FEMALE and MALE (which are data members of Human) in the statements
Expand|Select|Wrap|Line Numbers
  1. new Human("Alex",Human.FEMALE,2,1),  // ** missing Human.
  2. new Human("John",Human.MALE,3,2)
  3.  

Yeah, you're correct. Had actually done that, seems like it got lost... The program worked when I compiled it. Probably forgot to save the last changes.

And yes, this: new Human("John",Human.MALE,3,2). This should be default. Should be read in from the keyboard by the user of the program. The same is this: HumanTable = new Human[30];
Nov 17 '06 #5
horace1
1,510 Expert 1GB
Yeah, you're correct. Had actually done that, seems like it got lost... The program worked when I compiled it. Probably forgot to save the last changes.

And yes, this: new Human("John",Human.MALE,3,2). This should be default. Should be read in from the keyboard by the user of the program. The same is this: HumanTable = new Human[30];
Your program appears to have much of the functionality required and you just need to test it.
A problem you do have is the output from main() is not correct -change the name of function twoString() in class Human and class Town to be called toString(). Fix it and the program output is then
Number of Humans: 2
name: Alex ID: 1 age: 2gender: FEMALE
name: John ID: 2 age: 3gender: MALE
The Town has 2 Humans.
Nov 18 '06 #6
Your program appears to have much of the functionality required and you just need to test it.
A problem you do have is the output from main() is not correct -change the name of function twoString() in class Human and class Town to be called toString(). Fix it and the program output is then
Number of Humans: 2
name: Alex ID: 1 age: 2gender: FEMALE
name: John ID: 2 age: 3gender: MALE
The Town has 2 Humans.
I fixed it, but the problem is that now I've just made some input (Alex, 1, 2, FEMALE), but this should be done by the user of the program. Do you know how to fix that?
Nov 20 '06 #7
horace1
1,510 Expert 1GB
I fixed it, but the problem is that now I've just made some input (Alex, 1, 2, FEMALE), but this should be done by the user of the program. Do you know how to fix that?
to read information from an input stream you can overload the >> (get from or extraction) operator, see
http://www.fredosaurus.com/notes-cpp/oop-friends/overload-io.html
Nov 20 '06 #8
Ganon11
3,652 Expert 2GB
...but not in Java. >> is a C++ operator.

In Java, I believe the new standard (as of Java5) is to use a Scanner class as follows:

Expand|Select|Wrap|Line Numbers
  1. Scanner IN = new Scanner(System.in);
You can display an appropriate message to the user prompting input, and then use the different functions of the Scanner class to retrieve that input and process it. The ones I have seen are:

Expand|Select|Wrap|Line Numbers
  1. string input;
  2. int x;
  3. double y;
  4. x = IN.nextInt(); // Looks for an integer type variable in the stream and stores into x
  5. y = IN.nextDouble(); // See nextInt, but used for doubles
  6. input = IN.nextLine(); // Gets an entire line of string input
Nov 20 '06 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: geoff | last post by:
Has anyone used process modelling successfully and what do you think of it? Process modelling as opposed to say, collaborating objects to get a task done (I know the process model itself could be a...
2
by: Philip Battle | last post by:
Does a freely avalable object model for the XML language exist anywhere? I'm looking for a graphical representation to save me the hard work of modelling xml myself. I'm imagining a node table with...
0
by: zeroSpaMISBaDtype | last post by:
Hi, A friend of mine at Newcastle University is looking to get in touch with someone doing numerical modelling in C++ (preferably, but not essentially, using DEAL 2. To be honest, I think he'd...
1
by: m++ | last post by:
Hi there, I am looking for some C++(object oriented) source codes of applications designed for embedded systems. I am going to use them as benchmarks. I've faced with some of these applications in...
8
by: beza1e1 | last post by:
I see myself shifting more and more over to the functional kind of coding. Could be related to the Haskell, we had to learn in CS. Now i was wondering, how other people use Python? With...
1
by: Stephen Chell | last post by:
Hi, I'm new to DB2 and I'll be doing some data modelling for a UDB 8.1 database. I'll need a data modelling tool that is capable of generating DDL. Does IBM provide such a tool? Is there a...
1
by: jkelly | last post by:
Hi all, I’m trying to model an object that represents the equipment that is required on a boat. As the size of the boat increases so does the amount of gear. Currently I have a different form...
2
by: Irfan | last post by:
hi, Although it is not direcltly relevant to .NET but i would like the expert views. Until now we did not have a formal requirments capture tool and UML diagramming tool. But our projects are...
2
by: Veloz | last post by:
Hiya My question is whether or not you should associated related objects in your software using a scheme of id's and lookups, or wether objects should actually hold actual object references to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.