Amazon Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

class VendingMachine
	- boolean takeMoney(Money money);
	//Here item will contain type & quantity, no smart search required 
	//say user need half litere Coke.
	- Item pickItem(Item item); 
	- boolean isAvilable(Item item)
	- Double askForAmount(Input input);
	- Double valiDateAndReturnBalance(Money money);
class Money
	-CurrencyType type;
	-Double amount	
class MoneyValidator
    - boolean validate(Money amount);
class Item
	-ItemType type;
	-Double quantity
	-String barcode; // May be anything else to identify it
class Input
    - CommandType type;
    - Double quantity
	- ItemType type;
class display
    - void updateDisplay(String instructions)
class KeyPad
    - Input readUserInput(Key key);
class Key
    -KeyType type
    -Double value
	
enum CurrencyType
enum ItemType
enum KeyType
enum CommandType

- Ajeet January 17, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Ajeet, quite sufficient and detailed interfaces. But some can be merged i think. like:

Class Input, Class KeyPad, Class Key and Class display can be merged into like: UserInterface
Class MoneyValidator can be merged with Class Money itself (this class will have enough info regarding the value of currency and cost should be passed as parameter to validate function)

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

@saurabh
Yes we can, but i will prefer it as abstract as possible. It provides us more flexibility and fine grained design.
Agree with Class MoneyValidator, we can be merged it with Class Money, because its validation will depend of Money's format.

- Ajeet January 28, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

import java.util.ArrayList;

public class VendingMachine {
	private ArrayList<Item> itemlList;
	private ArrayList<Item> selectedItems;
	private Coin receivedCoin;	
	public VendingMachine(ArrayList<Item> itemlList) {
		this.itemlList = itemlList;
	}
	public ArrayList<Item> getItemlList() {
		return itemlList;
	}
	public ArrayList<Item> giveCoins(Coin coin){
		this.receivedCoin = coin;
		return showUserChoiceList();
	}
	private ArrayList<Item> showUserChoiceList() {
		ArrayList<Item> userChoiceList = new ArrayList<Item>();
		for(Item item: itemlList){			
			if(item.getPrice()<=receivedCoin.getValue()){
				userChoiceList.add(item);
			}
		}				
		return userChoiceList;
	}
	public Coin getSelectedItem(ArrayList<Item> selectedItems){
		this.selectedItems = selectedItems;
		return giveSelectedItem();
	}
	private Coin giveSelectedItem() {
		Coin returnCoin=null;
		double value = receivedCoin.getValue();
		for(Item item: selectedItems){
			System.out.println(item.getName()+" | "+item.getPrice());
			value=value-item.getPrice();
		}		
		return new Coin(value, receivedCoin.getCurrency());
	}
}

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

Item's availability (more specifically nos. available) is one of the keys information here.
And considering that, storing Items with available count in a structure similar to Map (i.e. Hashtable or Hashmap in Java) makes more sense. This ways, when you implement isAvailable(Item item), you can validate Item's Stock.

- Himanshu Patel May 12, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think we can give user , 2 interfaces one for "item code selection" and second "enter money" , it looks like state pattern. user can go from 1 state to another based on input.
classes :- product , states(entercode,entermoney,gioveproduct ) , any time we can add more states.

- mittal September 28, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

here is my design

Interface Iteam{
	id
	price
	discription
	inventory
	sell(){
	//reduce inventory
	}
}

Class Menu{
	Map<Id,Iteam> iteams;
	display(){
		return iteams.values();
	}

	Iteam select(int id){
		return items.get(id);
	}
}

class vandingMachine{
	Menu menu;
	start(){
		menu.display();
	}

	getUserInput(id){
		Iteam selection = menu.select(id);
		Order order = new Order(selection);
		order.process();
		(order.status==sucess){
			dispatch(selectio);
		}
	}

	dispatch(){
	
	}
}

class Order{
	Iteam iteam;
	PaymentManager payment;
	Status 
	acceptPayment(){

	}
	process(){
		if(payment.isSucess()){
			iteam.sell();
		}
	}

}

PaymentManager{
	PaymentStatus {SUCESS,PENDING,FAILED};
	charge(double Price){

	}
}

- vijayparashar.eca October 08, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

below is my code for vendor machine ..there could be additional list of item and some low level plumbering needed:-

import java.util.* ; 
public class Vendor {
	
	int choice ; 
	ArrayList<Item> al ;
	ArrayList<Item> al1 ;
	HashMap<Integer , ArrayList> hm = new HashMap<Integer , ArrayList>();
	HashMap<Integer , Integer> price = new HashMap<Integer , Integer>();
	
	public int get_price(int item_id)
	{
	 return price.get(item_id);	
	}
	
	public Vendor(ArrayList al , ArrayList al1)
	{
	 this.al = al ; 
	 this.al1 = al1 ; 
	 hm.put(1, al);
	 hm.put(2, al1);
	 price.put(1, 20);
	 price.put(2, 30);
	 price.put(3, 40);
	 }
	
	
	
	public void dispatch(Menu m)
	{
	 int choice =  m.choice(); 
	 int rate = price.get(choice);
	 int coin_recieved = m.coin();
	 if(coin_recieved<rate)
	 {
	 System.out.println("please enter the coin greater than or equal to of amount "+rate+" INR");
	 System.out.println(); 
	  }
	 else{
	 int rem = coin_recieved-rate ; 
	 Item str = (Item)hm.get(choice).get(0);
	 
	 System.out.println("get the item "+str.item_name);
	 this.al.remove(al.size()-1);
	 System.out.println("collect your remaining amount of "+rem+" Ruppee");
	 System.out.println(); 
	 }
	 //m.coin();
	}
	
	public static void main(String args[])
	{
	  Item i1 = new Item(1 , "Biscuit" , 20);
	  Item i2 = new Item(1 , "Biscuit" , 20);	
	  Item i3 = new Item(2 , "Cold Drink" , 30);	
	  Item i4 = new Item(2 , "Cold Drink" , 30);
	  
	  ArrayList<Item> al = new ArrayList<Item>();
	  ArrayList<Item> al1 = new ArrayList<Item>();
	  al.add(i1);
	  al.add(i2);
	  al1.add(i3);
	  al1.add(i4);
	  
	  Menu m = new Menu();	
	  Vendor v = new Vendor(al , al1 );
	  while(1==1)
	  v.dispatch(m);
	
	  }
}


class Item 
{
 int item_id ; 
 String item_name ; 
 int item_price ; 
 
 public Item(int a , String b , int c)
 {
	item_id = a ;
	item_name = b ; 
	item_price = c ; 
 }
} 


class Menu
{
	
  public int choice()
  {
		 
	System.out.println("Biscuit packet : 20 INR      Press:1");  
	System.out.println("Cold Drink : 30 INR      Press:2"); 
	System.out.println();  
	Scanner sc = new Scanner (System.in);
	int x = sc.nextInt();
	return x ;
  }
  
 public int coin()
 {
  Scanner s = new Scanner(System.in);
  int y = s.nextInt();
  return y ; 
 }

}

- Sonia June 27, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.* ; 
public class Vendor {
	
	int choice ; 
	ArrayList<Item> al ;
	ArrayList<Item> al1 ;
	HashMap<Integer , ArrayList> hm = new HashMap<Integer , ArrayList>();
	HashMap<Integer , Integer> price = new HashMap<Integer , Integer>();
	
	public int get_price(int item_id)
	{
	 return price.get(item_id);	
	}
	
	public Vendor(ArrayList al , ArrayList al1)
	{
	 this.al = al ; 
	 this.al1 = al1 ; 
	 hm.put(1, al);
	 hm.put(2, al1);
	 price.put(1, 20);
	 price.put(2, 30);
	 price.put(3, 40);
	 }
	
	
	
	public void dispatch(Menu m)
	{
	 int choice =  m.choice(); 
	 int rate = price.get(choice);
	 int coin_recieved = m.coin();
	 if(coin_recieved<rate)
	 {
	 System.out.println("please enter the coin greater than or equal to of amount "+rate+" INR");
	 System.out.println(); 
	  }
	 else{
	 int rem = coin_recieved-rate ; 
	 Item str = (Item)hm.get(choice).get(0);
	 
	 System.out.println("get the item "+str.item_name);
	 this.al.remove(al.size()-1);
	 System.out.println("collect your remaining amount of "+rem+" Ruppee");
	 System.out.println(); 
	 }
	 //m.coin();
	}
	
	public static void main(String args[])
	{
	  Item i1 = new Item(1 , "Biscuit" , 20);
	  Item i2 = new Item(1 , "Biscuit" , 20);	
	  Item i3 = new Item(2 , "Cold Drink" , 30);	
	  Item i4 = new Item(2 , "Cold Drink" , 30);
	  
	  ArrayList<Item> al = new ArrayList<Item>();
	  ArrayList<Item> al1 = new ArrayList<Item>();
	  al.add(i1);
	  al.add(i2);
	  al1.add(i3);
	  al1.add(i4);
	  
	  Menu m = new Menu();	
	  Vendor v = new Vendor(al , al1 );
	  while(1==1)
	  v.dispatch(m);
	
	  }
}


class Item 
{
 int item_id ; 
 String item_name ; 
 int item_price ; 
 
 public Item(int a , String b , int c)
 {
	item_id = a ;
	item_name = b ; 
	item_price = c ; 
 }
} 


class Menu
{
	
  public int choice()
  {
		 
	System.out.println("Biscuit packet : 20 INR      Press:1");  
	System.out.println("Cold Drink : 30 INR      Press:2"); 
	System.out.println();  
	Scanner sc = new Scanner (System.in);
	int x = sc.nextInt();
	return x ;
  }
  
 public int coin()
 {
  Scanner s = new Scanner(System.in);
  int y = s.nextInt();
  return y ; 
 }

}

- Sonia June 27, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Implement the interface scalable given below for rectangle class.

interface scalable
{
void setScale(double x,double y);
void calculateScale(double scalex,double scaley);
}

- Anonymous November 29, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

In online railway reservation system consider three threads 1.check seat availability 2.book my ticket 3. cancle my ticket explain life cycle of above three threads

- Asha sirsath November 29, 2018 | Flag Reply


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