Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In JAVA We used two types of lights: incandescent and flourescent. All lights ou

ID: 3713645 • Letter: I

Question

In JAVA

We used two types of lights: incandescent and flourescent. All lights output an amount of light measured in lumens. Incandescent lights also output a significant amount of heat, while flourescent lights output almost no heat (none for the purposes of this labtask). The amount of heat output by an incandescent light is 87.4 times the lumens of the light. While flourescent lights are cool, they are also harder to control - they are always either "on" or "off", so are therefore less useful in the theatre where effect is required. Thus, in any theatre light strip, it is important to monitor the total light output, the total heat output, and the number of flourescent lights.

In some initial analysis, design, and implementation, I produced an abstract superclass Light.java, and also a control program RunLights.java. You must implement the classes that represent incandescent lights, flourescent lights, and light strips. (The class for light strips must use a Vector to hold the lights in the strip.) With those completed, here's what a sample run should look like (with the keyboard input shown in italics) ...

Light.java

RunLights.java

Explanation / Answer

Given below is the code for the question. Please use this code along with Light.java and RunLights.java provided by instructor
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i
Please do rate the answer if it was helpful. Thank you


Flourescent.java
----------------

public class Flourescent extends Light {

public Flourescent(int lumens) {
super(lumens);
}

@Override
public double heatOutput() {
return 0;
}

@Override
public boolean isFlourescent() {
return true;
}

public String toString()
{
return "Flourescent light of " + getLumens() + " lumens";
}

}


Incandescent.java
---------------
public class Incandescent extends Light{

public Incandescent(int lumens) {
super(lumens);
}

@Override
public double heatOutput() {
return 87.4 * getLumens();
}

@Override
public boolean isFlourescent() {
return false;
}

public String toString()
{
return "Incandescent light of " + getLumens() + " lumens";

}

}


LightStrip.java
----------
import java.util.Vector;

public class LightStrip {
Vector<Light> lights;

public LightStrip()
{
lights = new Vector<Light>();
}

public void display() {
double totalLumens = 0;
double heat = 0;
int fCount = 0;

for(int i = 0; i < lights.size(); i++)
{
System.out.println(i + ": " + lights.get(i));
totalLumens += lights.get(i).getLumens();
heat += lights.get(i).heatOutput();
if(lights.get(i).isFlourescent())
fCount++;
}

System.out.printf("Total lumens = %.1f ", totalLumens);
System.out.printf("Flourescent = %d ", fCount);
System.out.printf("Heat output = %.1f ", heat);

}

public void addLight(Light light) {
lights.add(light);
}

public void removeLight(int index)
{
if(index >= 0 && index < lights.size())
lights.remove(index);
else
System.out.println("ERROR: No light at that index");
}
}

output
-------
------------------------------------
Total lumens = 0.0
Flourescent = 0
Heat output = 0.0
------------------------------------
(A)dd light, (R)emove light, e(X)it : a
(F)lourescent or (I)ncandescent : f
How many lumens : 1000
------------------------------------
0: Flourescent light of 1000 lumens
Total lumens = 1000.0
Flourescent = 1
Heat output = 0.0
------------------------------------
(A)dd light, (R)emove light, e(X)it : a
(F)lourescent or (I)ncandescent : i
How many lumens : 500
------------------------------------
0: Flourescent light of 1000 lumens
1: Incandescent light of 500 lumens
Total lumens = 1500.0
Flourescent = 1
Heat output = 43700.0
------------------------------------
(A)dd light, (R)emove light, e(X)it : a
(F)lourescent or (I)ncandescent : f
How many lumens : 800
------------------------------------
0: Flourescent light of 1000 lumens
1: Incandescent light of 500 lumens
2: Flourescent light of 800 lumens
Total lumens = 2300.0
Flourescent = 2
Heat output = 43700.0
------------------------------------
(A)dd light, (R)emove light, e(X)it : r
Index of light to remove : 6
ERROR: No light at that index
------------------------------------
0: Flourescent light of 1000 lumens
1: Incandescent light of 500 lumens
2: Flourescent light of 800 lumens
Total lumens = 2300.0
Flourescent = 2
Heat output = 43700.0
------------------------------------
(A)dd light, (R)emove light, e(X)it : r
Index of light to remove : 0
------------------------------------
0: Incandescent light of 500 lumens
1: Flourescent light of 800 lumens
Total lumens = 1300.0
Flourescent = 1
Heat output = 43700.0
------------------------------------
(A)dd light, (R)emove light, e(X)it : x

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote