Which specifies the number of photos that the camera

This preview shows page 2 out of 2 pages.

which specifies the number of photos that the camera has taken so far (this is initially zero). Notice that if a camera object is not turned on, then it can not take any photos. public void start() { Camera myCamera = new Camera(true, 0); Camera yourCamera = new Camera(false, 0); System.out.println(myCamera.toString()); System.out.println(yourCamera.toString()); myCamera.takePhotos(7); yourCamera.takePhotos(4); System.out.println(myCamera.toString()); System.out.println(yourCamera.toString()); myCamera.setOn(false); yourCamera.setOn(true); yourCamera.takePhotos(3); yourCamera.takePhotos(2); System.out.println(myCamera.toString()); System.out.println(yourCamera.toString()); } Given a correct implementation of the Camera class, the output from the application above should be exactly as shown below: Camera on: true, photos taken: 0 Camera on: false, photos taken: 0 Camera on: true, photos taken: 7 Camera on: false, photos taken: 0 Camera on: false, photos taken: 7 Camera on: true, photos taken: 5 public class Camera { private boolean isOn; private int numPhotos; public Camera(boolean on, int num) { isOn = on; numPhotos = num; } public void setOn(boolean on) { isOn = on; } public void takePhotos(int n) { if (isOn) { numPhotos = numPhotos + n; } } public String toString() { return "Camera on: " + isOn + ", photos taken: " + numPhotos; } }
Image of page 2
You've reached the end of this preview.
  • Summer '12
  • AdrianaFerraro
  • Method, Subroutine, private int, Mutator method

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern