• Post Reply Bookmark Topic Watch Topic
  • New Topic

Radio  RSS feed

 
Casper Shoemaker
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone!
i need a little help..i am soo new in Java.

In previous exam i had to do a Radio, with a method volume and frequency set. This is without buttons and so on with GUi.

Now i would like to have in Radio class methods radioOn(), freqSrc(), radioVol() and radioOff() if?
Can i choose between 5 stations in our range? i am from one small village ;)
i think is simply but i need help.

thank you,
giboo
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Well ... What have you coded so far? What issues / questions are you running into?
 
Campbell Ritchie
Marshal
Posts: 56595
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
Casper Shoemaker
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for Welcome!
I have learning some basics, mostly from HeadFirstJava2ndEdition, TheNewBoston and LearnJavaTogether (They are great)..and now i'am on the best forum too

For excample:
- i want two methods
- one for set volume down, if it's too loud or up if it's too quiet
- another method for set frequency to search one of my favorite station, or other if there is no good music on it

I hope you understand me, if not i'll try better.


 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gasper Sustar wrote:
For excample:
- i want two methods
- one for set volume down, if it's too loud or up if it's too quiet
- another method for set frequency to search one of my favorite station, or other if there is no good music on it

For you volume up/down, I recommend a single method setVolume(int volume). Try creating a bare bones class with just this method and then post it here with any specific questions you have about your code. (You'll have to show some effort on your part.)
 
Casper Shoemaker
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something like this..

 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Did you compile your code? If so, what do you think is wrong with it?

Henry
 
Casper Shoemaker
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'we done!
Something like this. Tnx for pushing me foward
Now i just have to solve the problem with Math.random().
Sometimes it gives me an empty value.

 
Campbell Ritchie
Marshal
Posts: 56595
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean about Math#random giving an empty value? I never thought such a thing was possible.

Actually I try to avoid Math#random as far as possible, using the Random class instead. Math#random actually uses a Random object behind the scenes.
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggest replacing your old style "Math.random()" with the newer "Random" object.

Your loops around your calls to Math.random() don't really accomplish much, a single call to Math.random() would suffice, or better yet, use the "rand" object as shown above. Also, your approach would occasionally leave volume set to zero.
Replace:

With
 
Casper Shoemaker
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, i made it!
Problem solved.
I think when i'll have it in a pinky finger, it will be easier and more fun.

regards
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!