ASSIGNMENT

Job ID: 39635500

Budget: £10 – £15 GBP

NO AI IS ALLOWED.
IntelliJ IDEA 2024.2.4.

Write a class called Pollutant to store details of a single pollutant found in the water source. The class must define fields to store the following details:

• The name of the pollutant. The value will be a String which will always have a length of at least 1 character.

• The parts per billion ppb of the pollutant detected. This is an integer value. The value will always be greater-than or equal to zero.

The class must have a single constructor that takes the name of a pollutant. You do not need to check that the value passed to the constructor is valid. You may assume that it always will be. In other words, you may assume that the name String will be at least one character long. The initial value of ppb must always be zero when the object is constructed and it is not passed as a parameter to the constructor.

The class must define the following methods:

A method called ppb which prints: "ppb stands for parts per billion."

• A getter method for each field.

• A method called adjust that takes a single integer parameter and adds the value+1 to the ppb field. The parameter’s value may be any positive or negative integer and does not need to be checked. However, if after adding to the ppb field the ppb field has a value less than zero, then the ppb must be set to zero as it must never contain a negative value.
• A method called print to print the values of the fields on a single line in exactly the following format:

Arsenic is 5 ppb.

where "Arsenic" is an example of a String in the name field and 5 is an example of the current value in the ppb field. Each Pollutant object will have its own particular values for these fields. Take careful note of the formatting given above and reproduce it exactly in your implementation.
• A method called about that prints:

Pollutant written by login

where you must replace login with your University login. For instance:

Pollutant written by djb247

Write a class called Source that will store Pollutant objects for a particular source of water, representing the different pollutants found in that source.
Write the Source class with the following features:
• It must use a suitable list-style collection class from the java.util package to store multiple
Pollutant objects.
• An addPollutant method that takes a
Pollutant object as parameter and stores it in the collection. You may assume that no two Pollutant objects with the same name will be stored via this method. Note that this method must not create a Pollutant object.
• A getPollutants method that returns the collection of Pollutant objects.
• A printAll method that iterates over the collection and prints out details of all the pollutants in the collection by calling each Pollutant object's print method. At the end of the method, a summary of the total number of ppb for all pollutants must be printed. For instance:
Arsenic is 5 ppb.
Cyanide is 12 ppb.
Lead is 6 ppb.
Total ppb: 23
• A findPollutant method that takes a String as a parameter and returns the Pollutant object whose name field exactly matches the parameter's value. If there is no match, return null. It is guaranteed that all pollutants will have different names.
• A findTopPollutants method that takes a single integer as a parameter (representing a number of ppb) and returns a separate list of all Pollutant objects whose ppb field has a value greater-than or equal-to the parameter's value.
No Pollutant objects are to be removed from the Source object's list and the list object returned must be a different object from the Source object's list of all pollutants. The returned list must be empty if no pollutant has a ppb that is greater-than or equal-to the parameter's value.
• A removeLowest method that removes the Pollutants) with the lowest number of ppb from the collection. The method must return the number of pollutants removed, which could be zero - see below.
The following rules apply to the removal process: If more than one pollutant has the lowest number of ppb then all of those matching pollutants must be removed, unless removing them all would mean that there were no pollutants left. For instance:
• Three pollutants with 15, 9 and 4 ppb each: the one with 4 ppb would be removed, leaving two remaining. The method returns 1.
• Three pollutants with 25, 4 and 4 ppb each: the ones with 4 ppb would be removed, leaving one remaining. The
method returns 2.
• Three pollutants with 4, 4 and 4 ppb each: none would be removed, leaving three remaining. The method returns 0.
Write a class that tests and demonstrates that your Pollutant and Source classes implement the specification given above. Note that this does not need to be a JUnit test class (as covered in Chapter 9 of the course textbook) because we did not formally cover JUnit in COMP3200.
Your test class must illustrate all of the features that you have implemented. This will best be done by having at least one separate test method for each feature. For instance:
• A method that creates a Pollutant object and prints out the result of calling each of its accessor (get) methods;
• A method that increases the number of ppb of an existing Pollutant object.
• A method that decreases the number of ppb of an existing Pollutant object.
• A method that decreases the number of ppb of an existing Pollutant object below zero but checks that the resulting value of ppb is zero.
• A method that creates a Source object, creates a few Pollutant objects and adds them to it, and then calls the printAll method;
• A method that finds a matching Pollutant;
• A method that does not find a matching
Pollutant;
• etc.
Note that the list above is not a complete list of the test class's methods and you will need to define more than those to achieve full marks for this part. It will be worth writing this test class alongside writing the other classes. For instance, develop the test methods for the basic Pollutant class before going on to write the Source class.