Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Programming Languages
Java
Sort from an array of objects into stacks without using java.util
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="lfernandez, post: 5168630, member: 87629"] I want to create an object array of 50 people by randomly generating their ages and IDs. After that I must classify each of the people generated in the list in 2 stack arrays, where the first stack will contain the people that have an age lower than 18 and the second stack will contain the people older than 18. The classification of the people, which consists of removing each of the elements of the initial list and inserting them in the corresponding stack, must be a process that is performed automatically. I already made the first part but I'm having problems with the classification since I can't use the java.util to create the stacks. I'd really appreciate it if you could help me with this. [CODE=java]public class Stacks01 { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here //create array of employee object Person[] person = new Person[50] ; Person[] minors = new Person[50]; Person[] adults = new Person[50]; for (int i = 0; i < 50; i++) { person[i] = new Person (generatorId(100000000, 999999999), generatorAge(0,100)); } for (int j = 0; j < 50; j++) { System.out.println("Person "+(j+1)+": "); person[j].showData(); } } //Person class with Id and age as attributes static class Person{ int Id; int age; //Person class constructor Person(int pId, int e){ Id = pId; age = e; } public void showData(){ System.out.print("Id: "+Id + " " + " age: "+age); System.out.println(); } } public static int generatorId(int min, int max){ double id; id = ((Math.random() * (max - min)) + min); return (int) id; } public static int generatorAge(int min, int max){ double age; age = ((Math.random() * (max - min)) + min); return (int) age; } [/CODE] [/QUOTE]
Verification
Post reply
Forums
Programming Languages
Java
Sort from an array of objects into stacks without using java.util
Top