This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Random to the colour object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Random to the colour object" Watch "Random to the colour object" New topic
Author

Random to the colour object

raj david
Greenhorn

Joined: Dec 21, 2009
Posts: 9
[strike]Hello,

I Have three colours which have been initialised using the getters and setters ( for example brown, blue and black). I have also generated values 0,1 and 2 by using Random. I just need to know how do I point 0 to the colour brown, 1 to the colour blue and 2 to the colour black in a public method called change. So randomly the cream object changes to those colour.

Thanks in advance.

This is what I got so far...

[/code][/strike]
Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

There are several control structures in java and all of them can be used to solve this problem. You should write out what you need to do in psuedocode to determine which structure is best for you. I have posted a link to a control structure tutorial.

An example of pseudocode:

Student class

create student object
initialize name, gpa, and major of student
print students information



Control structure tutorial: http://java-programming.suite101.com/article.cfm/introduction_to_java_control_structures
-Hunter


"If the facts don't fit the theory, get new facts" --Albert Einstein
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Random to the colour object
 
It's not a secret anymore!