• 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

Method Return 0 Value

 
Ranch Hand
Posts: 119
Mac Eclipse IDE VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to calculate a certain value, but it is returning 0 and I'm not sure why. This is a measurement to define the angle from the equator and the center of the sun

 
Marshal
Posts: 4499
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does 360/365 equate to?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, it's that old integer-division gotcha again! When you write "360/365" in Java that results in an integer value with the remainder from the division thrown away. In other words, in this case it's zero, which isn't what you wanted. You want a double value there, so write "360.0/365.0" instead.

The other gotcha which you haven't hit yet is that the Math.sin() and other trignometric functions want parameters in radians, not degrees. Check the documentation for the Math class to find out how to convert degrees to radians.
 
Derek Smiths
Ranch Hand
Posts: 119
Mac Eclipse IDE VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you guys for your replies -- that fixed the problem. Now, I'm trying to get the local solar time which is defined as the highest point of the sun locally. double lst = LT + tc/60 LT is the local time. Is there a good way to calculate this, or is there a way to get the local time in minutes?

 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Java 8 you can get a LocalTime object representing now:



Then you can get the hours and minutes from it and do the obvious calculation to get the number of minutes since midnight, which I think is what you want? Only problem is you're then going to have to deal with daylight saving time, which you want to factor out -- I think, anyway. I can't quite tell what your code is supposed to be doing, for example based on the variable names it looks like it's subtracting a longitude from a time... so probably "ltm" doesn't mean what I guessed.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:In Java 8 you can get a LocalTime object representing now:



Then you can get the hours and minutes from it and do the obvious calculation to get the number of minutes since midnight...


Java8 provides two ways for doing that more succinctly.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Darryl Burke wrote:Java8 provides two ways for doing that more succinctly.



I'm not surprised. The pendulum swung from not enough classes for the job in Java 1 to a class for every single different thing in Java 8. I'm very far from understanding all of the new date and time variants.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suspect most people will go through the Java® Tutorials, find one way which works for them, and stick to that way for ever.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

A few hours ago, I wrote:I suspect most people will go through the Java® Tutorials, find one way which works for them, and stick to that way for ever.

I have just bought a copy of The Psychology of Everyday Things by Donald A Norman.

Page 8 of that book wrote:In England I visited a home with a fancy new Italian washer‑drier combination, with super‑duper multi‑symbol controls, all to do everything you ever wanted to do with the washing and drying of clothes. The husband (an engineering psychologist) said he refused to go near it. The wife (a physician) said she had simply memorized one setting and tried to ignore the rest.

 
Derek Smiths
Ranch Hand
Posts: 119
Mac Eclipse IDE VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Paul, to clarify my code, I am designing a program that will display a graph to continuously update the path of the sun throughout the day and will display it on an FX chart. I have a program that is attached to my arduino that has solar panel data passing (serial connection) to my FX program. The specific method above is to increase the accuracy of the solar position within the local time meridian for the specific region. This website might fill you in, IF you are interested: http://www.pveducation.org/pvcdrom/properties-of-sunlight/solar-time

The ltm value is derived from this method.I know getRawOffset() produces a value in microseconds so, I've converted to hours. I would imagine this is all overkill and I could just define this as a constant, but thought I would give it a go.

 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seems to me you have to take into account the DST offset for the date and time in question, not just the raw offset (which is the offset which applies whenever DST is applicable), don't you?
reply
    Bookmark Topic Watch Topic
  • New Topic