CMPS 260 Programming Assignment #4 solution

$24.99

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (4 votes)

Assignment Description
1. First, create an Intellij Java project and name it “pa4_your-id”.
2. Create a normal (POJO, JavaBean) but immutable class to represent, i. e. model, samples of dirt.
Following the steps shown in “Assignment: Tutorial on Creating Classes in IntelliJ”, create the class in a
file of its own in the same package as class Main. Name the class an appropriate name. The class must
have
(a) private field variables to hold the percent of sand, clay and other materials. The range of values for
each of these is zero to one inclusive, i. e. [0, 1]. The three values stored must add up to 1.
(b) a private field variable to hold the pH value of the sample. The range of values for pH in the soil is
zero to 14, i. e. [0, 14].
(c) a public getter (accessor) method for each private field variable. The getters must not have
parameters.
(d) a public default constructor, i. e. a constructor without parameters.
(e) a parametrized constructor, i. e. a constructor with parameters, one parameter each for sand, clay and
pH. Note that the value of other materials can be calculated given the percent of sand and clay.
3. Create a class to represent, i. e. model, a collection of samples of dirt. Following the steps shown in
“Assignment: Tutorial on Creating Classes in IntelliJ”, create the class in a file of its own in the same
package as class Main. Name the class an appropriate name. The class will store dirt class objects in an
array and have methods to provide information about the samples stored. The class must have
(a) a private reference variable for an array of the dirt class created in step 2.
(b) a private variable to keep track of the number of dirt objects stored in the array.
(c) a public default constructor that creates a default size dirt class array object, assigning its reference to
the variable created in (a). The default size must be 2 elements or greater.
(d) a public parametrized constructor that creates a dirt class array object of the size passed in as a
parameter. The array size must be valid or an array of the default size is created. The reference of the
array is assigned to the variable created in (a).
CMPS 260 Spring 2019 Programming Assignment #4 (2019.02.28) 2
(e) two public methods to add dirt class objects to the list stored in the array, but only if there is room in
the array.
i. One method must receive as a parameter a reference to a dirt class object to be added to the list
of dirt class objects stored in the array.
ii. One method must receive as a parameters the percent of clay, percent of sand and the pH value of
a sample. This method will then create a dirt class object and add it to the list of dirt class
objects stored in the array.
(f) public methods to return the
i. number of dirt samples stored.
ii. maximum number of dirt samples that can be stored.
(g) public methods to return the
i. average clay percentage in the samples stored.
ii. average sand percentage in the samples stored.
iii. average other material percentage in the samples stored.
iv. average pH of the samples stored.
(h) public methods to return the highest percentage in the samples stored of
i. clay
ii. sand
iii. other materials
iv. pH
(i) public methods to return the lowest percentage in the samples stored of
i. clay
ii. sand
iii. other materials
iv. pH
CMPS 260 Spring 2019 Programming Assignment #4 (2019.02.28) 3
4. In method main of class Main, create a program that uses an object of the dirt samples collection class
and, as needed, objects of the dirt samples class to
(a) at start up, have the user input the number of dirt samples to be stored in the dirt samples collection
class object by calls to the appropriate method.
(b) allow the user to enter the values to be used in the dirt samples, which are then stored in the dirt
samples collection object by calls to the appropriate method(s) of the dirt samples collection class
object. If the data entered is not valid, the entry must be rejected and repeated.
(c) once all the data has been entered, use calls the appropriate dirt samples collection class object to
show the user the
i. sample count
ii. maximum number of samples that can be stored
iii. average percentage of clay, sand, other materials and pH of the samples stored
iv. high percentage of clay, sand, other materials and pH of the samples stored
v. low percentage of clay, sand, other materials and pH of the samples stored
Example of User Input (user input in red)
The following is provided for example purposes only. Your program’s user input may look completely different
from this as long as it is complete, clear and functional.
Enter the number of samples: 5
Sample 1
Sand + Clay must be <= 1
Enter sand percent: 0.77
Enter clay percent: 0.12
Enter pH (0 ­ 14): 7.07
Sample Accepted.
Sample 2
Sand + Clay must be <= 1
Enter sand percent: 0.9
Enter clay percent: 0.05
Enter pH (0 ­ 14): 15.92 <== example of a bad pH value entry
Bad values. Please reenter.
Sample 2
Sand + Clay must be <= 1
Enter sand percent: 0.13
Enter clay percent: 0.44
Enter pH (0 ­ 14): 1.62
Sample Accepted.
CMPS 260 Spring 2019 Programming Assignment #4 (2019.02.28) 4
Sample 3
Sand + Clay must be <= 1
Enter sand percent: 0.92
Enter clay percent: 0.04
Enter pH (0 ­ 14): 13.11
Sample Accepted.
Sample 4
Sand + Clay must be <= 1
Enter sand percent: 0.29
Enter clay percent: 0.36
Enter pH (0 ­ 14): 0.25
Sample Accepted.
Sample 5
Sand + Clay must be <= 1
Enter sand percent: 0.88
Enter clay percent: 0.6 <== example of bad clay + sand value
Enter pH (0 ­ 14): 7.98
Bad values. Please reenter.
Sample 5
Sand + Clay must be <= 1
Enter sand percent: 0.44
Enter clay percent: 0.28
Enter pH (0 ­ 14): 6.83
Sample Accepted.
Sample 6
Sand + Clay must be <= 1
Enter sand percent: 0.61
Enter clay percent: 0.2
Enter pH (0 ­ 14): 13.55
No room for sample.
(continued on the next page)
CMPS 260 Spring 2019 Programming Assignment #4 (2019.02.28) 5
Example of Report to User
The following is provided for example purposes only. Your program’s user report output may look completely
different from this as long as it is complete, clear and functional.
Sample Count: 5
Maximum Samples: 5
Average Clay: 0.248
Clay High: 0.44
Clay Low: 0.04
Average Sand: 0.510
Sand High: 0.92
Sand Low: 0.13
Average Other: 0.242
Other High: 0.43
Other Low: 0.04
Average pH: 5.776
pH High: 13.11
pH Low: 0.25
(continued on the next page)
CMPS 260 Spring 2019 Programming Assignment #4 (2019.02.28) 6
Additional Requirements
(a)A reference variable and instance object of class java.util.Scanner must be used to read the input from the
user. Prompts for user input must be clear and relevant.
(b)Output to the user must include appropriate labels.
(c)Identifiers must be descriptive, i. e. must self document. The only exception granted is in the case of a
“for variable”, that is a variable created as a simple counter as in the control variable in a “for” loop
statement.
(d)Indention of all code blocks (compound statements, anything in braces), including single statements
following selection or while statements, is required.
(e)The main “.java” file [the one with the method public static void main(String[] args)] of your Intellij
projects must contain this minimal documentation as the first lines of the file (i. e. above the package
statement):
// Your Name
// Your ID
// CMPS 260
// Programming Assignment : #
// Due Date :
// Program Description: (a brief description of actions of your code)
// Certificate of Authenticity:
(Choose one of the two following forms:)
// I certify that the code of this project, other than that that was generated by Intellij, is entirely
// my own work.
{or}
// I certify that the code of this project, other than that that was generated by Intellij, is entirely
// my own work, but I received some assistance from {name}. Follow this with a description of
// the type of assistance. (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 text, the author of the course text or the instructors examples.
Submitting
In Intellij, select File, Save All, then select File, Export to Zip File and click OK to save the Zip archive
file. Finally, upload the zip archive file to Moodle.
Helpful Hint: Keep a backup copy of your project folder on a Google Drive, a Drop Box Account, a USB
memory device, etc., or even on Moodle! Finally, once you turn in your final version, create a copy
before the due date and do not change this copy in any way. This final copy can be consulted if there is
an upload disaster, but only if the “.java” files have not been changed in any way after the due date.