Amazon Interview Question for Software Engineer / Developers
- 0of 0 votes
Design an object oriented console application named universe that reads in a file containing the schema of a two- AnonD June 24, 2015 in United States
dimensional (2D) universe and outputs certain information about the universe.
A 2D universe is a simplified universe that contains galaxies, stars, and planets, all of which are located on a flat plane
specified using 2-coordinates (x-axis and y-axis).
There is only one universe and it contains one or more galaxies.
A galaxy may contain one or more stars located in it.
A star may contain zero or more planets located near it in the same galaxy.
A planet may belong to one or two stars located near it in the same galaxy (Planet E465D in the sample file below is an example).
In order to allow the objects to support more descriptive attributes and functionality in future revisions of the
application, all the object types described above should be represented using separate classes. Parent-Child relationships should also be represented using links between the various object instances.
The program will run with three arguments specified: the input-file, and the name of two objects of any type, A and B.
Example command-line: universe text.txt Alpha_Dra E465D
Based on the command line arguments specified, the program will compute and display:
1. The parents location for both object A and B. (If needed, assume the coordinate of the universe is 0,0)
2. The minimum distance between object A (Alpha_Dra) and B (E465D). This is the distance between the two objects
3. Any of the two closest stars in the entire universe.
4. The farthest object from A, that is of the same type as A; and the farthest object from B, that is of the same type as
B. (if one exists)
The input file contains new-line separated lines each describing one object using the format:
Example test.txt input file:
The Universe object that serves as a parent to the galaxies is implicit, and will not be explicitly defined in the input
The input lines may occur in any order
The file may contain millions of lines.
Example output of running: universe test.txt Alpha_Dra E465D
Parent of Alpha_Dra is located at: 75434.2,89151.4
Parent of E465D is located at: 26413.83,-2727.73
Distance between Alpha_Dra and E465D: 99635.8
Closest two stars in the universe are: Alpha_And and Beta_And
| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm
Interview Type: Written Test
Open Chat in New Window