Wednesday, July 27, 2011

Assignment - Week 4

Create an object oriented hierarchy & solution to this analysis problem of three entities

- TV Remote
- VCD Remote
- Satellite Remote

Functionalities,
- Volume / Mute
- Program / Channels / Tuning
- Play / Stop / Resume / Pause / Record

Required (Minimum two from each point) concepts in solution.
- Inheritance / Abstraction / Polymorphism
- Interface / Abstract / Inner Class / Anonymous Class

Objective: Solution is not important but design of this solution is much more important in this. A simple diagram or code skeleton would be good enough as a solution to this assignment.

Second Interface


package com.evs.objava33.class8;

public interface SecondInterface {
public long secndTime();
}

First Interface


package com.evs.objava33.class8;

public interface FirstInterface extends SecondInterface {
public long time();
public long secndTime();
}

Palm Tree


package com.evs.objava33.class7;

import com.evs.objava33.class8.FirstInterface;

public class PalmTree extends Tree {
private int age;
private String breed;

private PalmTree(int age) {
super("DateTree");
this.age = age;
}

public PalmTree(int age, String breed) {
this(age);
this.breed = breed;
}

public String toString() {
return "PalmTree [age=" + age + ", breed=" + breed + "]";
}

public static void main(String[] args) {
PalmTree tree1 = new PalmTree(10, "Small");
DateTree tree2 = new DateTree(40, "tall");

// System.out.println(tree1);
// System.out.println(tree2);

Tree tree3 = new PalmTree(30, "Short");
System.out.println(tree3.getType());
Tree t5 = new PalmTree(23, "Dummy");
PalmTree t4 = (PalmTree) tree3;
// if (t5 instanceof PalmTree) {
if (t5.getClass() == PalmTree.class) {
t4 = (PalmTree) t5;
}

Tree[] trees = { tree1, tree2, tree3, t4, t5 };
FirstInterface[] ints = { tree1, tree2 };

for (FirstInterface t : ints) {
System.out.println(t.secndTime());
}

FirstInterface in = new FirstInterface() {
public long time() {
return 0;
}

public long secndTime() {
return 0;
}
};
System.out.println(in);
InnerFirstInterface ifi = tree1.new InnerFirstInterface();
System.out.println(ifi);
AnotherClass ac = new AnotherClass();

// Scope = Public, Private, Protected, Default
// Access = Default, Static

// Class Variable Method Constructor
// Public Y Y Y Y
// Private Y Y Y Y
// Protected Y Y Y Y
// Default Y Y Y Y

}

private interface AnotherInterface {
public void testing();
}

static class AnotherClass {
public int testing;
}

private class InnerFirstInterface implements FirstInterface {
public long time() {
return 0;
}

public long secndTime() {
return 0;
}
}

public long time() {
return System.currentTimeMillis();
}

public long secndTime() {
return time();
}
}

Date Tree


package com.evs.objava33.class7;


public class DateTree extends Tree {

private int age;
private String breed;

public DateTree(int age) {
super("DateTree");
this.age = age;
}

public DateTree(int age, String breed) {
this(age);
this.breed = breed;
}

public String toString() {
return "DateTree [age=" + age + ", breed=" + breed + "]";
}

public long time() {
return 10;
}

public long secndTime() {
return time();
}
}

Tree


package com.evs.objava33.class7;

import com.evs.objava33.class8.FirstInterface;

public abstract class Tree implements FirstInterface {
String type;

public Tree() {
type = "Unknown";
}

public Tree(String type) {
this.type = type;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public String toString() {
return "Tree [type=" + type + "]";
}

public abstract long secndTime();
}

Saturday, July 16, 2011