Amazon Interview Question for Software Engineer / Developers






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

public interface Furniture 
{
	public String getFurnitureType();
}


public class SimpleFurniture implements Furniture{
	public String getFurnitureType() {
		return "Simple Furnitue";
	}
}

public abstract class FurnitureDecorator implements Furniture{
	
	protected Furniture simpleFurniture;
	
	public FurnitureDecorator() {
	}
	
	public FurnitureDecorator(Furniture f) {
		this.simpleFurniture = f;
	}
	
	public String getFurnitureType() {
		return simpleFurniture.getFurnitureType();
	}

}

public class Table implements Furniture {
	
	private Furniture fTable;
	
	public Table() { 
		
	}
	
	public Table(Furniture f) { 
		fTable = f;
	}
	
	public String getFurnitureType() {
		return fTable.getFurnitureType() + " Table Furniture ";
	}

}

public class TableWithWoodDecorator extends FurnitureDecorator{

	protected Furniture f;
	
	public TableWithWoodDecorator() {
	}
	
	public TableWithWoodDecorator(Furniture f1) {
		f = f1;
	}
	
	public String getFurnitureType() {
		return f.getFurnitureType() + " with wood";
	}
	
	
}

public class TestFurniture {

	public static void main(String[] args) {
		
		Furniture f = new TableWithWoodDecorator(new Table(new SimpleFurniture()));
		
		System.out.println(f.getFurnitureType());
		
		
	}
}

- Amit R January 07, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

I would go with two base interface ,

IFurniture
{
void Init(IMaterial)
}

IMaterial
{
}

Now I will create furniture objects,

abstract class Chair : IFurniture
{
}

abstract Class Table : IFurniture
{
}

Class WoodMaterial : IFurniture
{
}

class SteelMaterial : IFurniture
{
}

Concrete classes

class WoodenChair:: Chair
{
Init(IMaterial material)
}

- Ashish February 08, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

My response was to create a interface as material to generalize or to add material appropriate stuff in common for all classes instead of adding subclasses again and again.

- GBC February 24, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

You might be better off having furniture as an abstract base class and then Table and Chair as its subclass with an attribute of material.

- Anonymous February 24, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

abstract factory pattern

- anson627 February 24, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is the most ridiculous and naive way of doing it. Each time you want to add a new type, you will have to create a new class for it.

- Anonymous January 09, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Furniture : Abstract Class
Furniture -> Table
Furniture -> Table -> IronTable
Furniture -> Table -> SteelTable
Furniture -> Chair
Furniture -> chair -> Woodchair
Furniture -> Chair-> Steel chair

- balaji February 25, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1) Abstract Class Furniture {
Material material;
}
2) table extends furniture
3) chair Extends furniture

4) Material
5) Wood implements material;
6) Iron Implements material;

- Puneet March 01, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Wood implements material; ???

I think you mean : Wood implements Material

But since Material is an interface, how can there exist an instance material ?

- Renji March 17, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

material is not an instance.. its just a variable that can be used to refer to object of type Material

- supriya March 25, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Strategy pattern can be used for this need.

- Maulish May 11, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

How Strategy Pattern??? Can you elaborate?

- Dev August 03, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Decorator pattern

- Jay - NY November 16, 2011 | 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