Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help with this code Assignment Description 1. First, create an Intellij Java project. 2. Create a normal (POJO, JavaBean) but immutable class to represent,

Please help with this code

Assignment Description

1. First, create an Intellij Java project.

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).

(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

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 italics)

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.

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.

Example of Report to User

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

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.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Analytics Systems Engineering Cybersecurity Project Management

Authors: Christopher Greco

1st Edition

168392648X, 978-1683926481

More Books

Students also viewed these Databases questions