Advertisement
lrm2000

Lightbulb 2017 P2

Sep 19th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.36 KB | None | 0 0
  1. /*
  2. * AP CS MOOC
  3. * Term 2 - Assignment 2, Part 2: Strand
  4. * A class which represents a strand of lights.
  5. */
  6.  
  7. import java.util.ArrayList;
  8.  
  9. public class Strand
  10. {
  11. // An ArrayList that stores a strand of lights
  12. private ArrayList<Light> strand = new ArrayList<Light>();
  13.  
  14. // Default constructor that sets strand to an ArrayList holding one
  15. // turned on white bulb, that is not burnt out.
  16. public Strand()
  17. {
  18. Light bulb = new Light();
  19. strand.add(bulb);
  20. }
  21.  
  22. // A constructor that sets strand to an ArrayList of size n, holding
  23. // n white bulbs, that are all turned on and not burnt out. If n <= 0,
  24. // then the strand should be set to size one, with a white bulb, on
  25. // and not burnt out.
  26. public Strand(int n)
  27. {
  28. if(n<=0) {
  29. Light bulb = new Light();
  30. strand.add(bulb);
  31. } else {
  32. for(int x = 0; x < n; x++) {
  33. strand.add(new Light());
  34. }
  35. }
  36. }
  37.  
  38. // This method returns a String representation of the
  39. // Light objects in the ArrayList, one per line. For example,
  40. // here is the String returned when toString is called on a
  41. // Strand with 5 lights:
  42. //
  43. // green on not burnt out
  44. // red off not burnt out
  45. // green off burnt out
  46. // blue on not burnt out
  47. // red on not burnt out
  48. //
  49. // Note: there is a tab between the value for color and "off"/"on,"
  50. // and one space before the "burnt out" or "not burnt out".
  51. public String toString()
  52. {
  53. String returned = "";
  54. for(int x = 0; x < strand.size(); x++) {
  55. returned += strand.get(x).toString() + "\n";
  56. }
  57. return returned;
  58. }
  59.  
  60. // This method sets the color of all the light bulbs in the entire Strand.
  61. public void setColor(String c)
  62. {
  63. for(int x = 0; x < strand.size(); x++){
  64. strand.get(x).setColor(c);
  65. }
  66. }
  67.  
  68. // This method sets the light bulbs to the pattern "blue", "red", "green",
  69. // "blue", "red", "green", ... until the end of the strand.
  70. public void setMulti()
  71. {
  72. strand.get(0).setColor("blue");
  73. for(int x = 1; x < strand.size(); x++) {
  74. if(strand.get(x-1).getColor() == "blue") {
  75. strand.get(x).setColor("red");
  76. } else if(strand.get(x-1).getColor() == "red") {
  77. strand.get(x).setColor("green");
  78. } else {
  79. strand.get(x).setColor("blue");
  80. }
  81. }
  82. }
  83.  
  84. // This method turns on all the lights in the strand. Each individual bulb
  85. // can only be turned on if it's burntOut variable is false.
  86. public void turnOn()
  87. {
  88. for(int x = 0; x < strand.size(); x++) {
  89. if(strand.get(x).isOn() != true) {
  90. strand.get(x).flip();
  91. }
  92. }
  93. }
  94.  
  95. // This method turns off all the lights in the strand.
  96. public void turnOff()
  97. {
  98. for(int x = 0; x < strand.size(); x++) {
  99. if(strand.get(x).isOn() == true) {
  100. strand.get(x).flip();
  101. }
  102. }
  103. }
  104.  
  105. // This method sets the Light at location i’s burntOut variable to true.
  106. public void burnOut(int i)
  107. {
  108. strand.get(i).burnOut();
  109. }
  110.  
  111. public static void main(String[] args)
  112. {
  113. // *************************************************************************
  114. // 1. Test Strand()
  115. // *************************************************************************
  116. System.out.println("1. Test the default constructor Strand()");
  117. Strand strand1 = new Strand();
  118. if (strand1.strand.size() == 1)
  119. System.out.println("*** PASS: Strand() creates a list of size 1");
  120. else
  121. System.out.println("*** FAIL: Strand() creates a list of size "
  122. + strand1.strand.size()
  123. + ", when a list of size 1 is expected.");
  124.  
  125. // ***********************************
  126. // 2. Test Strand(n)
  127. // ***********************************
  128. System.out.println("\n2. Test the constructor Strand(n)");
  129. // Try to create a strand of lights with 0 bulbs
  130. Strand emptyStrand = new Strand(0);
  131. if (emptyStrand.strand.size() == 1)
  132. System.out.println("*** PASS: Strand(0) creates a list of size 1");
  133. else
  134. System.out.println("*** FAIL: Strand(0) creates a list of size "
  135. + emptyStrand.strand.size()
  136. + ", when a list of size 1 is expected.");
  137. // Try to create a strand of lights with a negative number
  138. Strand negativeStrand = new Strand(-7);
  139. if (negativeStrand.strand.size() == 1)
  140. System.out.println("*** PASS: Strand(-7) creates a list of size 1");
  141. else
  142. System.out.println("*** FAIL: Strand(-7) creates a list of size "
  143. + negativeStrand.strand.size()
  144. + ", when a list of size 1 is expected.");
  145. // Try to create a strand of lights with a positive number
  146. Strand strandWithFiveBulbs = new Strand(5);
  147. if (strandWithFiveBulbs.strand.size() == 5)
  148. System.out.println("*** PASS: Strand(5) creates a list of size 5");
  149. else
  150. System.out.println("*** FAIL: Strand(5) creates a list of size "
  151. + strandWithFiveBulbs.strand.size()
  152. + ", when a list of size 5 is expected.");
  153. // Verify that all the light bulbs are initialized properly
  154. boolean success = true;
  155. for (Light bulb : strandWithFiveBulbs.strand)
  156. {
  157. if (!(bulb.isOn() && bulb.getColor().equals("white")))
  158. {
  159. success = false;
  160. }
  161. }
  162. if (strandWithFiveBulbs.strand.size() > 0 && success)
  163. {
  164. System.out.println("*** PASS: Strand(5) initialized bulbs correctly");
  165. }
  166. else
  167. {
  168. System.out.println("*** FAIL: Strand(5) did not initialize bulb(s) correctly");
  169. }
  170.  
  171.  
  172. // ***********************************
  173. // 3. Test setColor(String)
  174. // ***********************************
  175. System.out.println("\n3. Test setColor(String)");
  176. // All of the bulbs in our strandWithFiveBulbs are white. Set them to
  177. // green.
  178. strandWithFiveBulbs.setColor("green");
  179. success = true;
  180. for (Light light : strandWithFiveBulbs.strand)
  181. {
  182. if (!light.getColor().equals("green"))
  183. success = false;
  184. }
  185. if (strandWithFiveBulbs.strand.size() > 0 && success)
  186. System.out.println("*** PASS: setColor worked as expected (green test)");
  187. else
  188. System.out.println("*** FAIL: setColor did not work as expected (green test)");
  189. // Now try to set them to a color that is not supported. This should
  190. // cause all the bulbs to be set back to white.
  191. strandWithFiveBulbs.setColor("pink");
  192. success = true;
  193. for (Light light : strandWithFiveBulbs.strand)
  194. {
  195. if (!light.getColor().equals("white"))
  196. success = false;
  197. }
  198. if (strandWithFiveBulbs.strand.size() > 0 && success)
  199. System.out.println("*** PASS: setColor worked as expected (pink test)");
  200. else
  201. System.out.println("*** FAIL: setColor did not work as expected (pink test)");
  202.  
  203.  
  204. // ***********************************
  205. // 4. Test turnOff()
  206. // ***********************************
  207. System.out.println("\n4. Test turnOff()");
  208. strand1.turnOff();
  209. if (strand1.strand.size() > 0 && !strand1.strand.get(0).isOn())
  210. {
  211. System.out.println("*** PASS: turnOff() worked as expected");
  212. }
  213. else
  214. {
  215. System.out.println("*** FAIL: turnOff() did not work as expected");
  216. }
  217.  
  218. // ***********************************
  219. // 5. Test turnOn()
  220. // ***********************************
  221. System.out.println("\n5. Test turnOn()");
  222. strand1.turnOn();
  223. if (strand1.strand.size() > 0 && strand1.strand.get(0).isOn())
  224. {
  225. System.out.println("*** PASS: turnOn() worked as expected");
  226. }
  227. else
  228. {
  229. System.out.println("*** FAIL: turnOn() did not work as expected");
  230. }
  231.  
  232. // ***********************************
  233. // 6. Test burnOut(int)
  234. // ***********************************
  235. System.out.println("\n6. Test burnOut(n)");
  236. strand1.burnOut(0);
  237. if (strand1.toString().equals("white\toff burnt out\n"))
  238. {
  239. System.out.println("*** PASS: burnOut(1) works as expected.");
  240. }
  241. }
  242. }
  243.  
  244.  
  245.  
  246.  
  247.  
  248. /*
  249. * AP CS MOOC
  250. * Term 2 - Assignment 2, Part 2: Strand
  251. * A class which represents a strand of lights.
  252. */
  253.  
  254. import java.util.ArrayList;
  255.  
  256. public class Strand
  257. {
  258. // An ArrayList that stores a strand of lights
  259. private ArrayList<Light> strand = new ArrayList<Light>();
  260.  
  261. // Default constructor that sets strand to an ArrayList holding one
  262. // turned on white bulb, that is not burnt out.
  263. public Strand()
  264. {
  265. Light bulb = new Light();
  266. strand.add(bulb);
  267. }
  268.  
  269. // A constructor that sets strand to an ArrayList of size n, holding
  270. // n white bulbs, that are all turned on and not burnt out. If n <= 0,
  271. // then the strand should be set to size one, with a white bulb, on
  272. // and not burnt out.
  273. public Strand(int n)
  274. {
  275. if(n<=0) {
  276. Light bulb = new Light();
  277. strand.add(bulb);
  278. } else {
  279. for(int x = 0; x < n; x++) {
  280. strand.add(new Light());
  281. }
  282. }
  283. }
  284.  
  285. // This method returns a String representation of the
  286. // Light objects in the ArrayList, one per line. For example,
  287. // here is the String returned when toString is called on a
  288. // Strand with 5 lights:
  289. //
  290. // green on not burnt out
  291. // red off not burnt out
  292. // green off burnt out
  293. // blue on not burnt out
  294. // red on not burnt out
  295. //
  296. // Note: there is a tab between the value for color and "off"/"on,"
  297. // and one space before the "burnt out" or "not burnt out".
  298. public String toString()
  299. {
  300. String returned = "";
  301. for(int x = 0; x < strand.size(); x++) {
  302. returned += strand.get(x).toString() + "\n";
  303. }
  304. return returned;
  305. }
  306.  
  307. // This method sets the color of all the light bulbs in the entire Strand.
  308. public void setColor(String c)
  309. {
  310. for(int x = 0; x < strand.size(); x++){
  311. strand.get(x).setColor(c);
  312. }
  313. }
  314.  
  315. // This method sets the light bulbs to the pattern "blue", "red", "green",
  316. // "blue", "red", "green", ... until the end of the strand.
  317. public void setMulti()
  318. {
  319. strand.get(0).setColor("blue");
  320. for(int x = 1; x < strand.size(); x++) {
  321. if(strand.get(x-1).getColor() == "blue") {
  322. strand.get(x).setColor("red");
  323. } else if(strand.get(x-1).getColor() == "red") {
  324. strand.get(x).setColor("green");
  325. } else {
  326. strand.get(x).setColor("blue");
  327. }
  328. }
  329. }
  330.  
  331. // This method turns on all the lights in the strand. Each individual bulb
  332. // can only be turned on if it's burntOut variable is false.
  333. public void turnOn()
  334. {
  335. for(int x = 0; x < strand.size(); x++) {
  336. if(strand.get(x).isOn() != true) {
  337. strand.get(x).flip();
  338. }
  339. }
  340. }
  341.  
  342. // This method turns off all the lights in the strand.
  343. public void turnOff()
  344. {
  345. for(int x = 0; x < strand.size(); x++) {
  346. if(strand.get(x).isOn() == true) {
  347. strand.get(x).flip();
  348. }
  349. }
  350. }
  351.  
  352. // This method sets the Light at location i’s burntOut variable to true.
  353. public void burnOut(int i)
  354. {
  355. strand.get(i).burnOut();
  356. }
  357.  
  358. public static void main(String[] args)
  359. {
  360. // *************************************************************************
  361. // 1. Test Strand()
  362. // *************************************************************************
  363. System.out.println("1. Test the default constructor Strand()");
  364. Strand strand1 = new Strand();
  365. if (strand1.strand.size() == 1)
  366. System.out.println("*** PASS: Strand() creates a list of size 1");
  367. else
  368. System.out.println("*** FAIL: Strand() creates a list of size "
  369. + strand1.strand.size()
  370. + ", when a list of size 1 is expected.");
  371.  
  372. // ***********************************
  373. // 2. Test Strand(n)
  374. // ***********************************
  375. System.out.println("\n2. Test the constructor Strand(n)");
  376. // Try to create a strand of lights with 0 bulbs
  377. Strand emptyStrand = new Strand(0);
  378. if (emptyStrand.strand.size() == 1)
  379. System.out.println("*** PASS: Strand(0) creates a list of size 1");
  380. else
  381. System.out.println("*** FAIL: Strand(0) creates a list of size "
  382. + emptyStrand.strand.size()
  383. + ", when a list of size 1 is expected.");
  384. // Try to create a strand of lights with a negative number
  385. Strand negativeStrand = new Strand(-7);
  386. if (negativeStrand.strand.size() == 1)
  387. System.out.println("*** PASS: Strand(-7) creates a list of size 1");
  388. else
  389. System.out.println("*** FAIL: Strand(-7) creates a list of size "
  390. + negativeStrand.strand.size()
  391. + ", when a list of size 1 is expected.");
  392. // Try to create a strand of lights with a positive number
  393. Strand strandWithFiveBulbs = new Strand(5);
  394. if (strandWithFiveBulbs.strand.size() == 5)
  395. System.out.println("*** PASS: Strand(5) creates a list of size 5");
  396. else
  397. System.out.println("*** FAIL: Strand(5) creates a list of size "
  398. + strandWithFiveBulbs.strand.size()
  399. + ", when a list of size 5 is expected.");
  400. // Verify that all the light bulbs are initialized properly
  401. boolean success = true;
  402. for (Light bulb : strandWithFiveBulbs.strand)
  403. {
  404. if (!(bulb.isOn() && bulb.getColor().equals("white")))
  405. {
  406. success = false;
  407. }
  408. }
  409. if (strandWithFiveBulbs.strand.size() > 0 && success)
  410. {
  411. System.out.println("*** PASS: Strand(5) initialized bulbs correctly");
  412. }
  413. else
  414. {
  415. System.out.println("*** FAIL: Strand(5) did not initialize bulb(s) correctly");
  416. }
  417.  
  418.  
  419. // ***********************************
  420. // 3. Test setColor(String)
  421. // ***********************************
  422. System.out.println("\n3. Test setColor(String)");
  423. // All of the bulbs in our strandWithFiveBulbs are white. Set them to
  424. // green.
  425. strandWithFiveBulbs.setColor("green");
  426. success = true;
  427. for (Light light : strandWithFiveBulbs.strand)
  428. {
  429. if (!light.getColor().equals("green"))
  430. success = false;
  431. }
  432. if (strandWithFiveBulbs.strand.size() > 0 && success)
  433. System.out.println("*** PASS: setColor worked as expected (green test)");
  434. else
  435. System.out.println("*** FAIL: setColor did not work as expected (green test)");
  436. // Now try to set them to a color that is not supported. This should
  437. // cause all the bulbs to be set back to white.
  438. strandWithFiveBulbs.setColor("pink");
  439. success = true;
  440. for (Light light : strandWithFiveBulbs.strand)
  441. {
  442. if (!light.getColor().equals("white"))
  443. success = false;
  444. }
  445. if (strandWithFiveBulbs.strand.size() > 0 && success)
  446. System.out.println("*** PASS: setColor worked as expected (pink test)");
  447. else
  448. System.out.println("*** FAIL: setColor did not work as expected (pink test)");
  449.  
  450.  
  451. // ***********************************
  452. // 4. Test turnOff()
  453. // ***********************************
  454. System.out.println("\n4. Test turnOff()");
  455. strand1.turnOff();
  456. if (strand1.strand.size() > 0 && !strand1.strand.get(0).isOn())
  457. {
  458. System.out.println("*** PASS: turnOff() worked as expected");
  459. }
  460. else
  461. {
  462. System.out.println("*** FAIL: turnOff() did not work as expected");
  463. }
  464.  
  465. // ***********************************
  466. // 5. Test turnOn()
  467. // ***********************************
  468. System.out.println("\n5. Test turnOn()");
  469. strand1.turnOn();
  470. if (strand1.strand.size() > 0 && strand1.strand.get(0).isOn())
  471. {
  472. System.out.println("*** PASS: turnOn() worked as expected");
  473. }
  474. else
  475. {
  476. System.out.println("*** FAIL: turnOn() did not work as expected");
  477. }
  478.  
  479. // ***********************************
  480. // 6. Test burnOut(int)
  481. // ***********************************
  482. System.out.println("\n6. Test burnOut(n)");
  483. strand1.burnOut(0);
  484. if (strand1.toString().equals("white\toff burnt out\n"))
  485. {
  486. System.out.println("*** PASS: burnOut(1) works as expected.");
  487. }
  488. }
  489. }
  490.  
  491.  
  492.  
  493.  
  494.  
  495. /*
  496. * AP CS MOOC
  497. * Term 2 - Assignment 2, Part 2: Strand
  498. * A class which represents a strand of lights.
  499. */
  500.  
  501. import java.util.ArrayList;
  502.  
  503. public class Strand
  504. {
  505. // An ArrayList that stores a strand of lights
  506. private ArrayList<Light> strand = new ArrayList<Light>();
  507.  
  508. // Default constructor that sets strand to an ArrayList holding one
  509. // turned on white bulb, that is not burnt out.
  510. public Strand()
  511. {
  512. Light bulb = new Light();
  513. strand.add(bulb);
  514. }
  515.  
  516. // A constructor that sets strand to an ArrayList of size n, holding
  517. // n white bulbs, that are all turned on and not burnt out. If n <= 0,
  518. // then the strand should be set to size one, with a white bulb, on
  519. // and not burnt out.
  520. public Strand(int n)
  521. {
  522. if(n<=0) {
  523. Light bulb = new Light();
  524. strand.add(bulb);
  525. } else {
  526. for(int x = 0; x < n; x++) {
  527. strand.add(new Light());
  528. }
  529. }
  530. }
  531.  
  532. // This method returns a String representation of the
  533. // Light objects in the ArrayList, one per line. For example,
  534. // here is the String returned when toString is called on a
  535. // Strand with 5 lights:
  536. //
  537. // green on not burnt out
  538. // red off not burnt out
  539. // green off burnt out
  540. // blue on not burnt out
  541. // red on not burnt out
  542. //
  543. // Note: there is a tab between the value for color and "off"/"on,"
  544. // and one space before the "burnt out" or "not burnt out".
  545. public String toString()
  546. {
  547. String returned = "";
  548. for(int x = 0; x < strand.size(); x++) {
  549. returned += strand.get(x).toString() + "\n";
  550. }
  551. return returned;
  552. }
  553.  
  554. // This method sets the color of all the light bulbs in the entire Strand.
  555. public void setColor(String c)
  556. {
  557. for(int x = 0; x < strand.size(); x++){
  558. strand.get(x).setColor(c);
  559. }
  560. }
  561.  
  562. // This method sets the light bulbs to the pattern "blue", "red", "green",
  563. // "blue", "red", "green", ... until the end of the strand.
  564. public void setMulti()
  565. {
  566. strand.get(0).setColor("blue");
  567. for(int x = 1; x < strand.size(); x++) {
  568. if(strand.get(x-1).getColor() == "blue") {
  569. strand.get(x).setColor("red");
  570. } else if(strand.get(x-1).getColor() == "red") {
  571. strand.get(x).setColor("green");
  572. } else {
  573. strand.get(x).setColor("blue");
  574. }
  575. }
  576. }
  577.  
  578. // This method turns on all the lights in the strand. Each individual bulb
  579. // can only be turned on if it's burntOut variable is false.
  580. public void turnOn()
  581. {
  582. for(int x = 0; x < strand.size(); x++) {
  583. if(strand.get(x).isOn() != true) {
  584. strand.get(x).flip();
  585. }
  586. }
  587. }
  588.  
  589. // This method turns off all the lights in the strand.
  590. public void turnOff()
  591. {
  592. for(int x = 0; x < strand.size(); x++) {
  593. if(strand.get(x).isOn() == true) {
  594. strand.get(x).flip();
  595. }
  596. }
  597. }
  598.  
  599. // This method sets the Light at location i’s burntOut variable to true.
  600. public void burnOut(int i)
  601. {
  602. strand.get(i).burnOut();
  603. }
  604.  
  605. public static void main(String[] args)
  606. {
  607. // *************************************************************************
  608. // 1. Test Strand()
  609. // *************************************************************************
  610. System.out.println("1. Test the default constructor Strand()");
  611. Strand strand1 = new Strand();
  612. if (strand1.strand.size() == 1)
  613. System.out.println("*** PASS: Strand() creates a list of size 1");
  614. else
  615. System.out.println("*** FAIL: Strand() creates a list of size "
  616. + strand1.strand.size()
  617. + ", when a list of size 1 is expected.");
  618.  
  619. // ***********************************
  620. // 2. Test Strand(n)
  621. // ***********************************
  622. System.out.println("\n2. Test the constructor Strand(n)");
  623. // Try to create a strand of lights with 0 bulbs
  624. Strand emptyStrand = new Strand(0);
  625. if (emptyStrand.strand.size() == 1)
  626. System.out.println("*** PASS: Strand(0) creates a list of size 1");
  627. else
  628. System.out.println("*** FAIL: Strand(0) creates a list of size "
  629. + emptyStrand.strand.size()
  630. + ", when a list of size 1 is expected.");
  631. // Try to create a strand of lights with a negative number
  632. Strand negativeStrand = new Strand(-7);
  633. if (negativeStrand.strand.size() == 1)
  634. System.out.println("*** PASS: Strand(-7) creates a list of size 1");
  635. else
  636. System.out.println("*** FAIL: Strand(-7) creates a list of size "
  637. + negativeStrand.strand.size()
  638. + ", when a list of size 1 is expected.");
  639. // Try to create a strand of lights with a positive number
  640. Strand strandWithFiveBulbs = new Strand(5);
  641. if (strandWithFiveBulbs.strand.size() == 5)
  642. System.out.println("*** PASS: Strand(5) creates a list of size 5");
  643. else
  644. System.out.println("*** FAIL: Strand(5) creates a list of size "
  645. + strandWithFiveBulbs.strand.size()
  646. + ", when a list of size 5 is expected.");
  647. // Verify that all the light bulbs are initialized properly
  648. boolean success = true;
  649. for (Light bulb : strandWithFiveBulbs.strand)
  650. {
  651. if (!(bulb.isOn() && bulb.getColor().equals("white")))
  652. {
  653. success = false;
  654. }
  655. }
  656. if (strandWithFiveBulbs.strand.size() > 0 && success)
  657. {
  658. System.out.println("*** PASS: Strand(5) initialized bulbs correctly");
  659. }
  660. else
  661. {
  662. System.out.println("*** FAIL: Strand(5) did not initialize bulb(s) correctly");
  663. }
  664.  
  665.  
  666. // ***********************************
  667. // 3. Test setColor(String)
  668. // ***********************************
  669. System.out.println("\n3. Test setColor(String)");
  670. // All of the bulbs in our strandWithFiveBulbs are white. Set them to
  671. // green.
  672. strandWithFiveBulbs.setColor("green");
  673. success = true;
  674. for (Light light : strandWithFiveBulbs.strand)
  675. {
  676. if (!light.getColor().equals("green"))
  677. success = false;
  678. }
  679. if (strandWithFiveBulbs.strand.size() > 0 && success)
  680. System.out.println("*** PASS: setColor worked as expected (green test)");
  681. else
  682. System.out.println("*** FAIL: setColor did not work as expected (green test)");
  683. // Now try to set them to a color that is not supported. This should
  684. // cause all the bulbs to be set back to white.
  685. strandWithFiveBulbs.setColor("pink");
  686. success = true;
  687. for (Light light : strandWithFiveBulbs.strand)
  688. {
  689. if (!light.getColor().equals("white"))
  690. success = false;
  691. }
  692. if (strandWithFiveBulbs.strand.size() > 0 && success)
  693. System.out.println("*** PASS: setColor worked as expected (pink test)");
  694. else
  695. System.out.println("*** FAIL: setColor did not work as expected (pink test)");
  696.  
  697.  
  698. // ***********************************
  699. // 4. Test turnOff()
  700. // ***********************************
  701. System.out.println("\n4. Test turnOff()");
  702. strand1.turnOff();
  703. if (strand1.strand.size() > 0 && !strand1.strand.get(0).isOn())
  704. {
  705. System.out.println("*** PASS: turnOff() worked as expected");
  706. }
  707. else
  708. {
  709. System.out.println("*** FAIL: turnOff() did not work as expected");
  710. }
  711.  
  712. // ***********************************
  713. // 5. Test turnOn()
  714. // ***********************************
  715. System.out.println("\n5. Test turnOn()");
  716. strand1.turnOn();
  717. if (strand1.strand.size() > 0 && strand1.strand.get(0).isOn())
  718. {
  719. System.out.println("*** PASS: turnOn() worked as expected");
  720. }
  721. else
  722. {
  723. System.out.println("*** FAIL: turnOn() did not work as expected");
  724. }
  725.  
  726. // ***********************************
  727. // 6. Test burnOut(int)
  728. // ***********************************
  729. System.out.println("\n6. Test burnOut(n)");
  730. strand1.burnOut(0);
  731. if (strand1.toString().equals("white\toff burnt out\n"))
  732. {
  733. System.out.println("*** PASS: burnOut(1) works as expected.");
  734. }
  735. }
  736. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement