• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Adapter Design Pattern Problem

 
Greenhorn
Posts: 3
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working on the following problem in which I need to apply the Adapter Design Pattern. The description makes it sound like the Adapter class should adapt the new temperature sensor's Celsius calculation to the Fahrenheit calculation of the other 3 sensors. However, there is no mention of passing temperature to any method. Does the Adapter instead seem to be handling the adaptation of TS1, 2, and 3's args of dat/time vs. TS4's args of year/month/day/hour/min/sec? Any thoughts here would be greatly appreciated. Here's the problem:

A system uses three (3) temperature sensors produced by the same vendor V1 to monitor the condition of a hardware device at a specific time:
– The first sensor is of type TS1.
– The second sensor is of type TS2.
– The third sensor is of type TS3.

TS1, TS2, and TS3 accept as input a date and time (given in Eastern Standard Time or EST) and return a temperature in Fahrenheit. Time is in the 24-hour time keeping system (e.g., 23:59:59). V1 supplies a class to interface with its sensors:



We would like to add a third sensor of type TS4 provided by vendor V2. TS4 accepts as inputs a year, month, day, and time (specified in Pacific Standard Time or PST) and returns a temperature in 1/10 of Celsius. Time is specified in the AM/PM format (12-hour clock). Below is the interface for TS4:



1) Give the UML class diagram for the application using the object adapter pattern.
2) Provide the implementation code of the UML class diagram given in question 1 in the programming language of your choice. The client application should read a date and time from the user and compute the average temperature of the four sensors at that date and time.
 
Sheriff
Posts: 15038
251
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by 1/10 Celsius? Do you mean if the temperature is 10.0 degrees Celsius, the returned value would be 1.0?
 
Ben Shapes
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do believe the problem is asking for 1/10 of the returned C value. ie, 10.0 would be 1.0 as Junilu suggests.

 
Junilu Lacar
Sheriff
Posts: 15038
251
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems to me that what you need is to be able to write something like this:

So what the TS4Adapter.getTemp() method needs to do is to translate its parameters into equivalent values that the TS4.getTS4Temp() method expects. Then it would take the returned value and translate it to Fahrenheit.
 
Junilu Lacar
Sheriff
Posts: 15038
251
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and Welcome to the Ranch!
 
Ben Shapes
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much. I will use your advice and report back if I can get it working. Cheers!
 
Marshal
Posts: 6827
182
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome again to the Ranch, Ben Shapes!  I gave you a thumbs-up for using code tags correctly, replying instead of quoting when it isn't necessary, and writing a clear and complete question.
 
I'd appreciate it if you pronounced my name correctly. Pinhead, with a silent "H". Petite ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!