Browse Source

Small changes by Building and WireNode. Creation of Switch and Transformer. Extension of Test1 class

Edgardo Palza 8 years ago
parent
commit
f01502259d

BIN
bin/tests/Tests1.class


BIN
bin/ui/controller/Building.class


BIN
bin/ui/controller/Buildings.class


BIN
bin/ui/controller/Gadget.class


BIN
bin/ui/controller/Switch.class


BIN
bin/ui/controller/Transformer.class


+ 6 - 6
src/tests/Tests1.java

@@ -9,13 +9,13 @@ import ui.controller.*;
 public class Tests1 {
 public class Tests1 {
 	
 	
 	/**
 	/**
-	 * Create some CPS object
+	 * Create some CPS object and Gadgets
 	 */
 	 */
 	public static void main(String[] args) {
 	public static void main(String[] args) {
-		Buildings b1 = new Buildings();
-		System.out.println(b1.getID());
-		System.out.println(b1.getName());
-		Buildings b2 = new Buildings();
-		System.out.println(b2.getID());
+		Building b1 = new Building();
+		Building b2 = new Building();
+		Switch s1 = new Switch();
+		Transformer t1 = new Transformer();
+		Gadget g1 = new Gadget();
 	}
 	}
 }
 }

+ 4 - 2
src/ui/controller/Buildings.java → src/ui/controller/Building.java

@@ -1,6 +1,6 @@
 package ui.controller;
 package ui.controller;
 
 
-public class Buildings extends CPSObj {
+public class Building extends CPSObj {
 	
 	
 	/*Array of all consumers*/
 	/*Array of all consumers*/
 	Gadget[] consumers;
 	Gadget[] consumers;
@@ -20,9 +20,11 @@ public class Buildings extends CPSObj {
 	 * Constructor
 	 * Constructor
 	 * Set by default the name of the object equals to the category name, until the user changes it.
 	 * Set by default the name of the object equals to the category name, until the user changes it.
 	 */
 	 */
-	public Buildings() {
+	public Building() {
 		super.setObjName("House");
 		super.setObjName("House");
 		super.name = super.getObjName();
 		super.name = super.getObjName();
+		System.out.println("You create a " + super.objName + " with ID " + super.ID);
+		System.out.println("It's actual name is: " + super.name);
 	}
 	}
 	
 	
 }
 }

+ 2 - 0
src/ui/controller/Gadget.java

@@ -19,6 +19,8 @@ public class Gadget {
 		setEnergy(10);
 		setEnergy(10);
 		this.isWorking = true;
 		this.isWorking = true;
 		this.totalEnergy = getTotalEnergy();
 		this.totalEnergy = getTotalEnergy();
+		System.out.println("You create some " + name + "'s. The amount is:" + amount);
+		System.out.println("It's actual status is: " + isWorking);
 	}
 	}
 
 
 	public String getName() {
 	public String getName() {

+ 22 - 0
src/ui/controller/Switch.java

@@ -0,0 +1,22 @@
+package ui.controller;
+
+public class Switch extends WireNode {
+	/*True, if this wire is working (capable of carrying electricity), else false*/
+	boolean isWorking;
+
+	public Switch() {
+		super.setObjName("Switch");
+		super.name = super.getObjName();
+		System.out.println("You create a " + super.objName + " with ID " + super.ID);
+		System.out.println("It's actual name is: " + super.name);
+	}
+	
+	public void switchState(boolean desired_state) {
+		this.isWorking = desired_state;
+	}
+	
+	
+	public boolean getTransformRatio() {
+		return this.isWorking;
+	}
+}

+ 38 - 0
src/ui/controller/Transformer.java

@@ -0,0 +1,38 @@
+package ui.controller;
+
+public class Transformer extends WireNode {
+
+	/* Ratio of the transformer */
+	float transformRatio;
+
+	/**
+	 * Constructor Set type of object (Transformer), its transform ratio and the
+	 * default name ("Transformer");
+	 */
+	public Transformer() {
+		super.setObjName("Transformer");
+		setTransformRatio(100);
+		super.name = super.getObjName();
+		System.out.println("You create a " + super.objName + " with ID " + super.ID);
+		System.out.println("It's actual name is: " + super.name);
+	}
+
+	/**
+	 * Set transform ratio
+	 * 
+	 * @param ratio
+	 *            desired ratio
+	 */
+	public void setTransformRatio(float ratio) {
+		this.transformRatio = ratio;
+	}
+
+	/**
+	 * Output the actual ratio of the transformer
+	 * 
+	 * @return actual ratio of the transformer
+	 */
+	public float getTransformRatio() {
+		return this.transformRatio;
+	}
+}

+ 0 - 4
src/ui/controller/WireNode.java

@@ -22,8 +22,4 @@ abstract class WireNode extends CPSObj {
 	/**
 	/**
 	 * Double inheritance for WireNodes? Or should we treat them as a normal class, like Buildings?
 	 * Double inheritance for WireNodes? Or should we treat them as a normal class, like Buildings?
 	 */
 	 */
-//	public WireNode() {
-//  	super.setObjName("Switch");
-//		super.name = super.getObjName();
-//	}
 }
 }