Amazon Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Written Test




Comment hidden because of low score. Click to expand.
2
of 2 vote

typedef long ID;


Class Client
{
	ID clientId;
	string Name; //This can be struct will details
	string location;  //This can be struct will details
	ID zipcode; //Again this can be part of location
	list<Transaction> transactionIDs; 

	public:
	list< Transaction > getTransactions () { return transactionIDs; }
	int getPincode () { return zipcode;}
	string getClientDetails() {return Name;} //Like: first name, last name, age, gender etc
};

class Product
{
	ID productId;
	double productCost;
	string productName;
	public:
	ID getProductID () {return productId};
	string getProductName () {return productName; }
	double getProductCost () {return productCost; }
};

class Service 
{
		ID serviceId;
	double serviceCost;
	string serviceName;
	public:
	ID getServiceID ();
	string getServiceName ();
	double getServiceCost ();
};
struct trxDetail
{
	enum typeOfTransaction;
	ID itemId;
	int itemQuatity;
};
class Transaction
{
	client clientName;
	timestamp purchaseDate;
	timestamp dueDate;
	ID transactionID;
	trxDetail purchasedItem;
public:
	client getClient ();
	ID getTransactionID ();
	date getTransactionDate ();
	date getTransactionDueDate ();
	trxDetails getTransactionDetail ();
	//long transactionCost (); // can be calculated using serviceCost/ProductCost & quantity. tax can be added at time of invoice generation
	//addTransaction (client, transactiontime, duedata, <type, id, quantity>);
};

class taxDetails
{
	ID zipcode;
	double taxAmount;
public:
	double getTax ();
};

class invoiceManagement
{
	map<ID, Client> clientMap;
	map<ID, Service> serviceMap;
	map<ID, Product> productMap;
	map<ID, Transaction> transactionMap;
	map<ID, taxDetails> taxMap;
	static invoiceManagement *instance;

public:
	static invoiceManagement  *getInstance ()
	{
		if (instance == NULL)
		{ 
			instance = new invoiceManagement;
		}
		return instance;
	}
	Client getClient ( ID clientId ) {  return clientMap[clientID]; }
	Service getService (ID serviceId ) { return serviceMap[serviceID];  }
	Product getProduct (ID productId ) { return productMap[productID];  }
	Transaction getTransaction (ID transactionId ) { return transactionMap[transactionID];  }
	taxDetails getTaxDetails (ID zipcode ) { return taxMap[zipcode];  }

};

class invoice
{
	invoiceManagement *IM;
public:
	invoice () { IM = invoiceManagement::getInstance(); }

	void generateInvoice (ID clientID)
	{
		Client *client = IM->getClient (clientID);
		list<Transaction> trxList= client-> getTransactions ();

		//print: customer details, address
		for (trx: trxList)
		{
			trxDetail td = trx. getTransactionDetail ();
			ID zipcode =  client->getzipcode();
			string clientname = client->getClientDetails ();
			timestamp duedate = trx.getDueDate ();
			timestamp trxdate = trx.getTransactionDate ();
			double unitcost = 0;
			double tax = 0;
			string name = "";
			int quantity = 0;
			if (td.type == PRODUCT)
			{
				quantity = td.quantity;
				Product product = IM->getProduct (td.itemID);
				unitcost = product.getCost ();
				name = product.getName ();
				tax = IM.->getTaxDetails (zipcode);
			}
			else if (td.type == SERVICE)
			{
				quantity = td.quantity;
				Service service = IM->getProduct (td.itemID);
				unitcost = service.getCost ();
				name = service.getName ();
			}

			int totalCost = unitcost * quantity + tax;
			//print: name, unit cost, quantity, totalcost, due date, transaction date
		}
	}
};

- SK January 26, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Transactio should be a very big class with details of each purchase. Think about a situation where company wants to print details of all transaction, details of all transactions for one customer. It'll use map for all transactions and multimap for per person transaction because a person can do multiple transactions. Only transaction class (and Purchase class in bigger scenario) should interact with product and Services class.

- Pramod January 03, 2016 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Create following classes
-invoice
-customers
-Collector
-InvoiceManagement
-Items <--Services/products
-BillProcessor(IRuleEngine)
-IRuleEngine

- shsf January 25, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Appreciate the effort, although you have not used inheritance at all. One use might be while inheriting product and services from the item.

- nitinsh99 January 29, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

yes, I have not used inheritance.
I had tried to keep objects separate and later on we can remove or merge un-necessary classes during discussion.

- SK January 29, 2014 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More