You will take some existing code and add new features to it. You will also add some new testing of the code. The starting program for this is the flashlight code we went over in class. You should use the code in this zip file rather than the code in examples. This includes the .class files that I built. Ignore the makefile and run files.
I also have this zip file that contains the class files for a solution to the problem. You should be able to run the program using
First, add a new bulb type called LED. It's rating is 10 times the rating for the TUNGSTEN bulb.
Add a new data field to the Battery class. It is called power and is a double. The initial power value for a battery is its amperage times the voltage and divided by 5. There is no actual electrical justification for this, its just something you have to figure out.
Add a method that takes no arguments and returns nothing. It reduces the power in the battery by 10% of its current value. So the first time it is called, it reduces the power from 100 to 90. Once the value has gone below 1.0, set it to 0.
You will also need a method to get the current power level.
double r = Math.random(); if(r < 0.5) // whatever you will do if the wires are good else // whatever you will do if the wires are bad
You will have to add a Wires object to the Light class.
It will call adjustpower() on each of the batteries. It will then check the power levels on each battery. If any of them are 0, the light fails.
Lastly, it will call check checkWires() on the Wires object To see if the wires failed.
If any of these checks fail, then the method (pressSwitch()) returns false. It should also print a message telling what failed.
Back in the main(), you will create a light, like it already does. Then you will press the switch on the light until it fails. Count how many times it took until it failed.
You should turn in a listing of the program. Staple the cover sheet to that.
Think about how you will do this so you can ask questions.
ASK if you have any questions. Use the existing code as a model for new classes. Remember to update comments and printouts if things are changed.