• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Need help with a timezone converter

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am a total beginer and I have to write following program:

"Write a a timezone converter "TimezoneConversion,java". The program should query the following:
1. The time to convert, as double with format hh, mm (for example, 14:30 = 14.30)
2. The time zone code of the origin time zone in short form, e.g. CET
3.  The time zone code of the destination time zone

Example output: 14:45 Uhr in CET (UTC+1) is 21:45 Uhr in HKT (UTC+8)

After the user input and the output, the program should start again from the beginning. If the user enters "END" at the time, the program should end.


If the user enters a non-existent (unknown) timezone code, the program should issue an error message and the input of the time zone code must be repeated. The time should be between 00.00 (00:00 o'clock) and 23,59 (23:59 o'clock). If entered other Values, the input of the time must be repeated.


Be sure to implement the following method:
static double convertToTimezone(double time, String fromZone, String toZone)

Time zones (simplified):  
AMT (Amazon Time), WGT (West Greenland Time) = UTC-3
ACST (Australian Central Standard Time) = UTC+9:30
CAT (Central Africa Time), EET (Eastern European Time) = UTC+2
CET (Central European Time) = UTC+1
HKT (Hongkong Time), SGT (Singapore Time) = UTC+8
JST (Japan Standard Time) =UTC+9"

As I said I am a total beginer and need urgent someone who can help me with the task. We are not allowed to import something (except the BufferedReader)!

This is what I have done (not much because I don't now how to progress):


 
Saloon Keeper
Posts: 9735
80
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You 'time' variable will need to be a String, not a double.
Need Strings for 'fromZone' and 'toZone', with corresponding prompts and reads.
Call your convert method.

See how far you get with that.
 
Sheriff
Posts: 7123
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:You 'time' variable will need to be a String, not a double.


But that's not what the specs say.  14:30 = 14.30.
 
Saloon Keeper
Posts: 5168
207
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would make a method that for each timezone returns the time difference to UTC. For instance:

Now, if you have a time and a fromZone, then calculate the time according to UTC with this method, and then calculate the requested time, again with this method. This is what I would do in the method 'convertToTimezone'.

Follow Carey's advice. Be careful though: if you have a time like 14.55 and you need to add 2.30, what would be the result?
 
Happily living in the valley of the dried frogs with a few tiny ads.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic