CMPS 260 Programming Assignment #4 - Fall 2020 CMPS 260, Fall 2020 Programming Assignment #4 (300 points) All coding to solve the following problem is to be done by you and only you. You may discuss...

Its basic java.we learned : loops, methods, Arrays, objects and classes, object- oriented thinking and Inheritance and polymorphism.


CMPS 260 Programming Assignment #4 - Fall 2020 CMPS 260, Fall 2020 Programming Assignment #4 (300 points) All coding to solve the following problem is to be done by you and only you. You may discuss the requirements of this project, Java, or Intellj with anyone, but you must code your own solution. You may use text, class notes and examples, and online Java resources. You may discuss your code with the instructor, TAs or mentors, but no one else. You may not provide your solution to anyone else. The project is to be created using IntelliJ and Azul Zulu Java 11. Assignment Purpose This assignment models a photograph and camera in two classes to emphasize the concepts of object-oriented programming and composition. Assignment Follow the numbered instructions below. 1. First, create an IntelliJ Java project and name it pa4-ULID, replacing the term ULID with your University-issued ULID (e.g., C00000000). 2. Starting at the topmost line of the file, insert the following minimally required documenta- tion, filling in your name, ULID, the assignment number, due date and a brief description of what the program will do. You must select one of the two forms of certification of Au- thenticity. (And, no, it is not permissible to substitute your own form.) Submissions not including a certification of authenticity will not be graded. Note that IntelliJ auto-saves only when the program is run. // Your Name // Your ULID // CMPS 260 // Programming Assignment : [insert assignment number here] // Due Date : [insert date here] // Program Description: [insert brief description here] // Certificate of Authenticity: (choose one from below) // I certify that the code in the Main, Photograph, and Camera classes // of this project is entirely my own work with the exception of the // provided factory methods. (or) // I certify that the code in the Main, Photograph, and Camera classes // of this project is entirely my own work with the exception of the // provided factory methods. However, I received assistance from // [insert name]. // Follow this with a description of the type of assistance. This document is copyrighted by Nicholas Lipari, PhD and is meant for the sole use of students enrolled in CMPS 260 at UL Lafayette. No reproduction or posting of any portion is permitted. 1 of 9 CMPS 260 Programming Assignment #4 © Nicholas Lipari, PhD — Fall 2020 For example, if you consulted a book, and your solution incorporates ideas found in the book, give appropriate credit; that is, include a bibliographical reference. Note: You do not have to list the course textbook or the instructor’s examples. 3. In a new file located in the same package as the class Main, create a public Java class to represent a photograph that consists of a linear (not 2D) array of pixels. Each pixel is stored as an integer. The photograph class must have: (a) Two private fields to represent the information stored about the photograph. These are the array of integers and the date the photograph was taken (stored as a String). The values in the array must be in the range 0 ≤ pixel ≤ 255. The default size of the array is 100, and the default date is “19000101”. A valid array size is at least 4, and a valid date has exactly 8 characters (e.g., 19000101 for January 1, 1900). (b) A public “getter” for the date field, a public method to return the size of the pixel array, and a public method setPixel to change an individual element in the pixel array. The setPixel method receives two parameters: the index of the pixel to be changed and the value it is to be set to as long as both are valid based on the size of the array and the range given above. (c) A public “default” constructor, (i.e., a constructor that receives no parameters). The default constructor may initialize the class fields or default initial values may be assigned to the class fields at their declaration. (d) A public parametrized constructor that receives two parameters, the size of the pixel array and the date the photograph was taken. The two fields are initialized with the received values if the received values are valid. (e) The three static “factory” methods given at the end of this document. Note that the class name is chosen as “Photograph” and may need to be changed given the name of your class. 4. In class Main, use the photograph class to create reference variables and objects using each of the three factory methods. Display the size and date of each object by calling the appropriate “getter” on the appropriate reference variable. The sizes and dates for these test objects have been hard-coded. 5. In a new file located in the same package as the class Main, create a public Java class to represent a camera that consists of a memory card able to store a number of photographs (represented by an array of reference variables), a zoom lens (represented by a zoom level), a calendar holding the current date (represented as a String), and a button to take a picture (represented by two methods to add a photograph reference to the memory card). The camera class must have the following: (a) Four private fields as data members: i. An array of photograph reference variables. The size of the array (i.e., memory card) is set when the camera class object is created, but the array’s size must be at least 16 regardless of user input. This document is copyrighted by Nicholas Lipari, PhD and is meant for the sole use of students enrolled in CMPS 260 at UL Lafayette. No reproduction or posting of any portion is permitted. 2 of 9 CMPS 260 Programming Assignment #4 © Nicholas Lipari, PhD — Fall 2020 ii. The number of photographs currently in the memory card (i.e., the number of photograph objects currently being referenced by elements of the array). The number of photographs referenced in the array always begins at zero. iii. The current zoom level stored as a floating point number. The zoom level defaults to 1.0 and is always in the range 1.0 ≤ zoom ≤ 4.0. iv. The current date stored as a String. The date defaults to January 1, 1900 and always has exactly 8 characters (see above). (b) A parameterized constructor that receives two parameters giving the maximum number of photographs (i.e., giving the size of the array of photograph class type to be created) and the current date. The photograph array reference variable is assigned to a new photograph array object of the size value received, but with at least 16 elements. (c) A default constructor that sets the fields to their default or minimum values and otherwise acts just as the parameterized constructor. (d) A public “getter” (but no “setter”) method for the number of photographs field. This returns the number of photographs stored in the array, not the number of elements in the array. (e) Public “getter” and “setter” methods for each of the zoom level and date fields. The “setter” methods must enforce the rules for valid values given above. (f) Two public methods that each add one photograph to the memory card as long as there is room in the array of photographs. Note that the number of photographs field is the location of the next available element in the array. i. One boolean method to add a photograph that receives one parameter, a photograph reference variable, and stores the reference in the first available position in the photograph array. Upon successfully storing the photograph, the number of photographs is increased and true is returned. Otherwise, false is returned. ii. Another boolean method to add a photograph that receives one integer parameter, the number of pixels in the photograph. The method then creates a new photograph class object with the given number of pixels and the date from the camera’s calendar. Each pixel of the photograph is set to a random integer in the range of valid values given above. The reference to the new object is stored in the first available position in the photograph array. Upon successfully storing the photograph, the number of photographs is increased and true is returned. Otherwise, false is returned. (g) A public int method that receives a photograph number that is used as the index in the photograph array and returns the size of the photograph. If the photograph number received is outside of the range of indexes or refers to an element in the array that does not reference a photograph, the value -1 is returned. (h) A public String method that receives a photograph number that is used as the index in the photograph array and returns the date of the photograph. If the This document is copyrighted by Nicholas Lipari, PhD and is meant for the sole use of students enrolled in CMPS 260 at UL Lafayette. No reproduction or posting of any portion is permitted. 3 of 9 CMPS 260 Programming Assignment #4 © Nicholas Lipari, PhD — Fall 2020 photograph number received is outside of the range of indexes or refers to an element in the array that does not reference a photograph, the value “00000000” is returned. 6. In class Main, use the camera and photograph classes to create an application that allows the user to create then manage a virtual camera. Use user input to set the number of photographs allowed in the camera object and the current date, then, in a loop, present a menu of options for the user to select. The loop should continue until the user elects to stop. The minimum options in the menu are: (a) Display the number of photographs in the camera (b) Add a photograph to the camera by getting its number of pixels from the user and indicate whether or not the photograph was added successfully. (c) Add a photograph to the camera by giving a factory-defined object and indicate whether or not the photograph was added successfully. You may use one of the static “factory” methods to create a photograph object. • createAll255sPhotograph() • createMinimumPhotograph() • create7x7Checkerboard() (d) Choose one of : Set the calendar date of the camera to a value from the user (or) Display the date and size of all photographs in the camera (e) Choose one of : Display the date and size of the oldest photograph in the camera (e.g., by using String’s compareTo method) (or) Display the date and size of the largest photograph in the camera (e.g., by comparing the sizes of the pixel arrays) (f) Halt the application Example Program Executions User input is indicated as red text. (Example For Items 3 and 4) createAll255sPhotograph Factory: 100 19000101 createMinimumPhotograph Factory: 4 19000102 create7x7Checkerboard Factory: 49 19000103 This document is copyrighted by Nicholas Lipari, PhD and is
Nov 05, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here