• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Radio

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Well ... What have you coded so far? What issues / questions are you running into?
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
Casper Shoemaker
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Something like this..

 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
If you were a tree, what sort of tree would you be? This tiny ad is a poop beast.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic