Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Information on building a program

Status
Not open for further replies.

frankcpl

Technical User
Mar 16, 2007
77
US
I am having trouble understanding how to create a script on creating a schedule with conditions. I am not asking for anyone to provide code, unless they just want to, just help me understand the concept so I can learn to code it.

Thanks for any help
 
First of all, "script" implies maybe you're thinking of javascript rather than java. If so, you're in the wrong forum. If you're asking about a java program, then you need to think in classes. What kind of objects will you have? I suggest you think of the GUI itself (I assume you'll have some kind of GUI) as an object. Then, your schedule can be an object or less elegantly it could be a property of the GUI. Each object needs to be constructed, that is, there needs to be a method that creates the object and in so-doing, assigns its attributes. For the GUI, for instance, there are frames and buttons and choices and maybe even a canvas. For the schedule class, if you go that way, there are items and (as you said in the OP) conditions.

You might want to look at some examples, for instance, here:

_________________
Bob Rashkin
 
Thanks for the clarification. I am working with java, so classes is what I am after. Thanks again for the help. The next thing is, anyone explain how to randomly pick from a list without having duplicates. I am confused on how to "scratch" an array item from the selection list. Really do appreciate the help understanding.
 
Hi

frankcpl said:
anyone explain how to randomly pick from a list without having duplicates.
You mean, pick more than one random element from a list ? Again, your question is not really Java, it is more about the algorithm. There are multiple ways depending on the size of the list, the count of needed items, whether the original list is disposable. Some possible approaches :
[ul]
[li]Do until reached n items : pick a random item, check the list of already picked items if it contains it, if not, add it.[/li]
[li]Do n times : pick a random item, then remove it from the list.[/li]
[li]Shuffle the entire array then get the first n items.[/li]
[/ul]


Feherke.
 
Thanks again for the help. I think I understand it now. I am going to try and work out the coding for it. Again thanks a lot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top