Microsoft Interview Question
Software Engineer / DevelopersCountry: -
Interview Type: In-Person
I suppose it's good to ask the interviewer what the wrist watch should do. Does it just have the time, or does it also have a Material, Price, etc.? From a business perspective (say, if this is part of an ordering system), the time wouldn't even be part of the data. From a timekeeping perspective, the time is important information, and perhaps the only information that needs to be stored. So, it's really important to examine what problem this class will solve.
good question rajat. i would approach to this question after a lil chat with the interviewer. i would ask him the following questions.
1. should it display date and week day ?
2. should it emit light when the button is pressed ?
3. should it support alarm feature ?
4. should it contain features for displaying heart rate ?
if the answer to all of them is yes then i would design it as:
public class watch{
int sec;
int min;
int hrs;
int day;
int month;
int year;
int alarm;
int heart;
public void settime(){}
public void setdate(){}
public void setalarm(){}
public void stopalarm(){}
public void gettime(){}
public void getdate(){}
public void getalarm(){}
public void displayheartbeat(){}
}
all constructive comments are always welcome. please correct me if i'm wrong or if there is any problem with the answer.
Good Question . I guess it depends on designer how do you design your class. For me..
- hprem991 November 03, 2011Base class watch should have private methods like ..
int seconds () // returns seconds from 0-59
int Minutes ()
int Hours ()
// can extends to calender feature
public methods like set and get function
You can now extend this base class to derived class called
class Wrist watch extends Watch
Now putting wrist watch features accordingly..