Hey all!
The only thing left that bugs me in my into java class is this - picking random objects from arrays or arraylists or wherever. After that I'm sailing free and moving to more advanced stuff
Alright people, please give me tips or hints about this thing, as I really want to improve my object to int/string/double/etc. skills. The bottom line is the use of Random generator - not Math.methods or similar. So how can I tune this thing?
Assume following thing, example with objects of Employee class.
Code with comments:
import java.util.*; import java.util.Random; class Employee{ private int salary; public void setSalary(int s){ s= salary; } public int getSalary(){ return salary; } } class rand{ public Employee [] get(Employee [] arr){ Employee [] arr2 = new Employee [3]; //three (or whatever) values. Random rand = new Random(); //setting up the Random generator - How to with Objects?? //unique numbers can be fixed through while loops by adding to the new array manually - no problem here. } } public class Job{ public static void main(String [] args){ Employee [] list = new Employee [5]; //Lets say 5 (or whatever). Employee e1 = new Employee(); Employee e2 = new Employee(); Employee e3 = new Employee(); Employee e4 = new Employee(); Employee e5 = new Employee(); e1.setSalary(10000); e2.setSalary(2000); e3.setSalary(15000); e4.setSalary(18000); e5.setSalary(23000); list[0] = e1; list[1] = e2; list[2] = e3; list[3] = e4; list[4] = e5;//Yep, doing it with lots of code :) //Here I will call on the class rand.get(list) - so it will make wonders and I can do whatever I want with the new array (or whatever) :P } }
Any suggestions will be greatly appreciated! But people, focus on the Random generator please, I know that there are other methods that will work besides this.