代写 html android Java junit graph software network Assignment 1: Camera Depth of Field – Java – Rev 3 CMPT 276 with Dr. Fraser

Assignment 1: Camera Depth of Field – Java – Rev 3 CMPT 276 with Dr. Fraser
Assignment 1: Camera Depth of Field – Java
Revisions
Rev 1: Initial version
Rev 2: Added instructions for providing TAs access to repo.
Rev 3: Added necessary closing ) to some formulas. (Great job spotting this!))
Notes
1. Java Work
In this assignment you will be writing a Java application, not an Android app. Much of what you create will then be used in assignment 2 when we implement a similar Android app.
For this assignment, you should do it all using the IntelliJ IDE. Later we will switch to using Android Studio, which is built on top of IntelliJ, so what you learn now will help later.
Install the latest Java SE JDK (it includes the JRE)
http://www.oracle.com/technetwork/java/javase/downloads/index.html
Install IntelliJ Community edition (free)
https://www.jetbrains.com/idea/download/
1.1 Depth of Field (DoF) Background
When using a camera to take a photograph, the camera will focus on one point (the focal point), and then anything at that distance from the camera will be in focus.
In fact, some things closer to the camera, and some things farther from the camera, than the focal point are also in focus too.
You are going to write a program to help photographers know how much will be in focus. Read the resources listed on the course website to understand more about depth of field. See Appendix B at the end of this document for details on what you will calculate.
1.2 GitLab
You must use SFU’s GitLab for this assignment.
See Appendix A at the end of this document for directions, or a video tutorial linked on the course website.
You must commit your work to GitLab reasonably frequently. I suggest you do so about every hour or so of work.
You must have 3 or more commits by the time you are done the assignment. (It might be significantly higher!)
Late penalty is 10% per calendar day (each 0 to 24 hour period past due). Maximum submission 2 days late.
This assignment is to be done individually. Do not share your code or solution, do not copy code found online, ask all questions on Piazza discussion forum (see webpage).
You may use code provide by the instructor, or in the guides/videos provided by the instructor (such as instructor’s YouTube videos).
You may follow any guides you like online as long as it is providing you information on how to solve the problem vs a solution to the assignment.
If receiving help from someone, they must be teaching you not writing your code. You may not resubmit code you have previously submitted for any course or offering.
Generated Jan 18, 2020, 11:08 PM Page 1/7 Dr. Fraser ©

Assignment 1: Camera Depth of Field – Java – Rev 3 CMPT 276 with Dr. Fraser
1.3 The Program
Your program must have two packages, as shown in the posted Java videos:
Model Package
The model is the part of program which manages the data and much of the application logic.
The UI class(es) will call classes in the model.
Classes in the model must not call the UI classes1. Have at least three classes in the model package:
Lens: Store info about a single lens such as its:
make: a string such as Canon, or Tamron, …
maximum aperture: the F-number of the lens. For an F5.6 lens, store 5.6. This represents how much light the lens can let in. Note that a larger aperture (more light, wider open) has a smaller F numbers. So, for a lens that can do F2.8 through F22, the “maximum aperture” (wide open) is 2.8.
focal length: Related to the magnification of the lens. Smaller focal lengths are wide- angle, larger focal lengths are more zoomed in. So an 18mm lens sees quite a wide area; a 200mm lens is quite zoomed in; and the Hubble telescope is 57,600mm.
Lens manager: Store a collection of lenses.
Class must support adding new lenses, retrieving a specific lens by its index, and be iterable over lenses.
Hint: Watch the videos on the course website about learning Java: they show how to create a class very much like this!
Depth of field calculator: Given a lens and some info about the camera settings, it can compute the depth of field values.
See Appendix B for what this class must compute.
Classes in the model package must not print to the screen or read from the keyboard. Instead they should work with (be called by) the classes in the UI which handle the screen and keyboard.
Text UI Package
Have a text UI class which interacts with the user by printing to the screen and reading from the keyboard.
Your interface must loop through:
Display the list of known lenses. Allow the user to select a lens.
Exit if user enter -1.
Fail if user entered an invalid valid index. Ask user for the aperture
Fail if the aperture is larger than the lens’s maximum aperture (i.e., the aperture
number entered is smaller than the lens maximum aperture number). Ask user for the distance to the subject
See the sample output on the course website.
1 A model class can only ‘call’ a UI class via the observer pattern, which we will learn later in the course.
Generated Jan 18, 2020, 11:08 PM Page 2/7 Dr. Fraser ©

Assignment 1: Camera Depth of Field – Java – Rev 3 CMPT 276 with Dr. Fraser
Text UI Details
See the sample text UI code (on website) for how to use the screen and keyboard.
You may change this provided code if you like. Note that this code tries to make use
of the lens manager class.
When reading from the keyboard (using the ‘in’ Scanner), assume the user always enters the correct type of value. For example, if you are expecting an int (using in.nextInt()), then assume the user types an int.
When printing out a distance, use the provided formatM() function for formatting a distance (in meters) to 2 decimal places.
Note that the distances must be shown to the user in meters [m], but the calculations in Appendix B are in millimeters [mm].
1.4 Testing
Write a JUnit 5 test class for your depth of field calculator class.
You must test each of the methods in your depth of field calculator class.
You must test at least three different lens/camera setting combinations and achieve as close to 100% code coverage of the target class as possible.
Generated Jan 18, 2020, 11:08 PM Page 3/7 Dr. Fraser ©

Assignment 1: Camera Depth of Field – Java – Rev 3 CMPT 276 with Dr. Fraser
2. Getting to Know Android Studio
Nothing from this section is to be submitted or for marks. However, the next assignment will require to to create an Android app. Therefore, it is strongly recommended that you start learning Android now.
Install and configure an Android development environment on a computer. Download the latest Java SE JDK (it includes the JRE) http://www.oracle.com/technetwork/java/javase/downloads/index.html Android studios:
https://developer.android.com/studio/index.html
You are encouraged to install this software on your own computer; however, if you wish, you can complete this assignment without doing an installation using the Linux CSIL labs.
2.1 Resources
Read chapters 1 to 5 of Android Programming: The Big Nerd Ranch book.
You may also want watch some of the provided videos on YouTube. Suggested videos:
Creating a button
UI Layouts
Java Objects in Android Activities Creating a 2nd activity.
Generated Jan 18, 2020, 11:08 PM Page 4/7 Dr. Fraser ©

Assignment 1: Camera Depth of Field – Java – Rev 3 CMPT 276 with Dr. Fraser
3. Deliverables
To CourSys (https://courses.cs.sfu.ca/) you must submit:
1. Screenshot of the commits page of GitLab repo (on csil-git1.cs.surrey.sfu.ca).
– In web browser, open your repository and click “Commits”. – It should now show at least 3 commits.
– Screenshot this and submit the image.
2. URL and Tag for your Git repository:
1. Add the TA for the course as a “Developer” member of your repo:
– Goto csil-git1.cs.surrey.sfu.ca and select your project
– On the left hand side, click the cog-wheel drop-down (‘Settings’) – Select “Members”
– Add the TA to your repo as a Developer. TA SFU ID = tirthp
2. Create a tag for your submission as follows:
– In Android Studio, go to VCS –> Git –> Tag…
– Enter a name for your tag, such as: final_submission
– Leave Commit and Message blank.
– Click Create Tag
– Push changes to remote repo. On “Push Commits” dialog, select “Push Tags: All”. – You can check the tag was pushed correctly in GitLab online.
– (If you resubmit, create a new tag as above and submit the new tag via CourSys).
3. Submit the git@… URL and tag name to CourSys
– Find Git URL on csil-git1.cs.surrey.sfu.ca/. Should be similar to: git@csil-git1.cs.surrey.sfu.ca:yourid/myProjName.git
– The “tag” is the name you used above, such as “final_submission”
3. ZIP file of your project, as per directions on course website.
Please remember that all submissions will automatically be compared for unexplainable similar submissions. Please make sure you do your own original work.
Generated Jan 18, 2020, 11:08 PM Page 5/7 Dr. Fraser ©

Assignment 1: Camera Depth of Field – Java – Rev 3 CMPT 276 with Dr. Fraser
Appendix A: Git Lab
Initial GitLab Checkin
1. Install Git on your computer.
2. Create a new project on SFU Computing Science GitLab server
a. Via a web browser, log into https://csil-git1.cs.surrey.sfu.ca/ and click “New Project” (top right).
b. Name it something like cmpt276As1 and click “Create project”
c. Generate an SSH key on your computer and upload it to GitLab. See video on course
website for directions in Windows.
d. Copy the Git URL for the project. It’s near the top middle of the page.
In the drop-down to its left, select “SSH”, then the URL should be something like:
git@csil-git1.cs.surrey.sfu.ca:bfraser/cmpt276As1.git
3. In IntelliJ or Android Studio, enable Git and commit the project:
a. From the menu select VCS –> Enable Version Control Integration
b. Select Git and press OK.
c. In the very bottom left corner of IntelliJ / Android Studio, hover over the button to
show the applications menu and select “Version Control”
▪ If it’s not there, then enabling VCS likely failed because the IDE could not find
Git. Ensure you have Git installed and then go to:
File –> Settings –> Version Control –> Git, and set the path to Git
(on Windows likely “C:\Program Files\Git\bin\git.exe”)
d. Expand the Unversioned Files and select them all.
e. Right click the selected files and say “Add to VCS”
f. From the menu select VCS –> Commit Changes.
Enter a description like “Initial commit”.
Hover over the Commit button, from the drop-down select “Commit and Push”
▪ If asked about Code Analysis, for the time being you can just Commit instead of
reviewing issues.
▪ In the Push Commits window, click “Define remote” in the top left. Enter that
git@csil-git1.cs.surrey.sfu.ca:… URL you copied from above
and click OK. ▪ Click Push
4. Ensure the files were pushed by viewing the project in GitLab via the web.
Checking in Changes
After making changes to your app, commit the changes to Git and push them to the GitLab server.
1. Hover over the bottom-left corner of IntelliJ or Android Studio to see the applications menu. Select Version Control.
2. Right-click in the panel and select “Commit Changes”
3. Enter a meaningful commit message.
4. Hover over the Commit button and select “Commit and Push”
◦ If asked about any code analysis warnings, you should correct them and then repeat this process; however, you may just click Commit to push the code you currently have.
Generated Jan 18, 2020, 11:08 PM Page 6/7 Dr. Fraser ©

Assignment 1: Camera Depth of Field – Java – Rev 3 CMPT 276 with Dr. Fraser
Appendix B: Depth of Field
See resources linked on course website for more explanation of depth of field computations.
Your depth of field calculator class will be provided the following data:
a lens (specifically, we need the lens’s focal length and maximum aperture) distance to subject (i.e., how far away is the thing we are focusing on) aperture to use for the photo
A lens has a maximum aperture, like 2.8 (“F2.8”), which is “wide open”. Its aperture can close down to be smaller, such as 22 (“F22”).
The formulas below use the current aperture selected, not the lens’s maximum aperture.
“Circle of confusion” of the camera
We don’t really need know much of this. It can be derived for a specific cameras and it relates to how much blur the camera will record for a single point of light.
We will just always be using 0.029mm for this value, as listed in the sample text UI.
From these values, we can compute the following:
Hyperfocal distance
With a given lens and camera settings, the hyperfocal distance is the distance from the camera beyond which all objects will seem in focus.
Near focal point
Near focal point is distance from the camera to the nearest point which will seem in focus.
Far focal point
Far focal point is distance from the camera to the farthest point which will seem in focus.
If the subject is beyond the hyperfocal distance, then the far focal point is +Infinity (in Java use Double.POSITIVE_INFINITY).
Depth of field
Hyper focal distance [mm]
= (lens focal length [mm])2 / (selected aperture * camera’s circle of confusion [mm])
Near Focal Point [mm]
= (hyper focal point [mm] * distance to subject [mm]) /
(hyper focal point [mm] + (distance to subject [mm] – lens focal length [mm]))
Far Focal Point [mm]
= (hyper focal point [mm] * distance to subject [mm]) /
(hyper focal point [mm] – (distance to subject [mm] – lens focal length [mm]))
Depth of field [mm]
= (far focal point [mm]) – (near focal point [mm])
Generated Jan 18, 2020, 11:08 PM Page 7/7 Dr. Fraser ©