Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

n celebration of completing two-thirds of CSCI 111, I am giving you the opportun

ID: 3859144 • Letter: N

Question

n celebration of completing two-thirds of CSCI 111, I am giving you the opportunity to create a truly world-changing piece of technology: a program to simulate sorting a bunch of unwanted Item’s into various bins each corresponding to a means of disposal. (trash, glass recycling, paper recycling, compost, thrift store.)For each Item we sort, our Sorter program must decide which bin to place it into and output this information to the user. The Sorter will also keep track of the total weight of items processed. (For extra credit, it can also compute the ratio of recycled items to trashed items.) I provide a Driver which will run the simulation; you may not alter this Driver.

Rules

Don’t modify the Driver, unless you are doing the extra credit in which case you may un-comment the final two lines of the main method.

All instance or static variables must be private

The .equals method is the correct way to compare strings; you will not lose points for using == so long as one of the strings is a “literal”

The Specifics

Each Item has a corresponding name, weight (measured in pounds), material, and condition.

The condition of an item can be excellent, good, or gross

All of our Items are made of one of the following materials: newspaper, cardboard, glass, plastic, wood, or organic

Each item will be placed into one of the following bins: trash, glass recycling, paper recycling, compost, thrift store

The sorting process is prioritized as follows:

READ THESE CAREFULLY. Work down the list, until an item matches a condition.

o If an Item’s condition is excellent or good, and it is not made of paper, take it to the thrift store

If an Item is made of paper, and its condition is not gross, put it in the paper recycling bin

If an item is made of glass, put it in the glass recycling bin

If an item is made of organic material put it in compost, unless it weighs more

than 10 pounds.

It’s hard to know whether plastics can be recycled or is trash. The best we can do is guess. If an item is made of plastic, randomly decide whether to put the item in the trash or in the plastic recycling bin.

If an item didn’t meet any of the above rules, put it in the trash.

Statistics which the Sorter must keep track of:

Total weight of items sorted

Extra credit--also have the Sorter keep track of:

Ratio of recycled items to trashed items

For example, if 2 items were recycled and 4 were put in trash, the ratio would be 2/4 = 0.5

An item is considered to have been recycled if it goes into any bin other than trash. An item is only considered to have been trashed if it goes into the trash bin.

/**

The Driver for our trash sorter.

DO NOT MODIFY THIS DRIVER!

**/

public class Driver {

public static void main(String[] args) {

    // Create some Items

    Item item1 = new Item("banana peel", 0.4, "organic", "gross");

    Item item2 = new Item("table", 75, "wood", "excellent");

    Item item3 = new Item("milk jug", 0.1, "plastic", "gross");

    Item item4 = new Item("Voodoo Ranger bottle", 0.4, "glass", "gross");

    Item item5 = new Item("yard waste", 425, "organic", "gross");

    Item item6 = new Item("Wallstreet Journal", 2.1, "paper", "good");

    Item item7 = new Item("beer pong table", 110, "wood", "gross");

    Item item8 = new Item("red Solo cup", 0.1, "plastic", "gross");

    Item item9 = new Item("Nalgene bottle", 0.7, "plastic", "gross");

    Item item10 = new Item("Refrigerator box", 13.4, "cardboard", "gross");

    // Sort these Items

    // Hmmm...I didn't make any instances of Sorter...

    Sorter.sortItem(item1);

    Sorter.sortItem(item2);

    Sorter.sortItem(item3);

    Sorter.sortItem(item4);

    Sorter.sortItem(item5);

    Sorter.sortItem(item6);

    Sorter.sortItem(item7);

    Sorter.sortItem(item8);

    Sorter.sortItem(item9);

    // Print a blank line before statistics

    System.out.println();

    // Print out statistics

    double totalWeight = Sorter.getTotalWeight();

    System.out.println("Total weight of sorted items: " + totalWeight);

    // EXTRA CREDIT-- uncomment if you want to give it a shot!

    // double recycledRatio = Sorter.getRecycledRation();

    // System.out.println("Ratio of items recycled to items trashed: " + recycledRatio);

}

}

sample output

Expert Answer

Explanation / Answer

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chegg.july;

/**
*
* @author Sam
*/

/**

The Driver for our trash sorter.

DO NOT MODIFY THIS DRIVER!

**/
public class Sorter{

    static double totalWeight = 0;
    static int trash = 0;
    static int glassRecycling = 0;
    static int paperRecycling = 0;
    static int compost = 0;
    static int thriftStore = 0;
    static int plasticRecycling = 0;
    private static int recyled = 0;
    static void sortItem(Item item) {
        if ((item.condition.equals("excellent") || item.condition.equals("good") ) && !item.material.equals("paper"))
            thriftStore++;
        else if (item.material.equals("paper") && !item.condition.equals("glass")){ // i dont know if this was glass or gross!
            paperRecycling++;
            recyled++;
        }
        else if (item.material.equals("glass")) {
            glassRecycling++;
            recyled++;
        }
        else if (item.material.equals("organic") && item.weight <= 10)
            compost++;
        else if (item.material.equals("plastic")){
            if (Math.random()< 0.5)
                trash++;
            else {
                plasticRecycling++;
                recyled++;
            }
        }
        else
            trash++;
        totalWeight += item.weight;
      
                  
    }

    static double getTotalWeight() {
        return totalWeight;
    }

    static double getRecycledRation() {
        return (double)recyled/trash;
    }
  
}

class Item {
    String name;
    double weight;
    String material;
    String condition;

    public Item(String name, double weight, String material, String condition) {
        this.name = name;
        this.weight = weight;
        this.material = material;
        this.condition = condition;
    }
  
}

class Driver {

public static void main(String[] args) {

    // Create some Items

    Item item1 = new Item("banana peel", 0.4, "organic", "gross");

    Item item2 = new Item("table", 75, "wood", "excellent");

    Item item3 = new Item("milk jug", 0.1, "plastic", "gross");

    Item item4 = new Item("Voodoo Ranger bottle", 0.4, "glass", "gross");

    Item item5 = new Item("yard waste", 425, "organic", "gross");

    Item item6 = new Item("Wallstreet Journal", 2.1, "paper", "good");

    Item item7 = new Item("beer pong table", 110, "wood", "gross");

    Item item8 = new Item("red Solo cup", 0.1, "plastic", "gross");

    Item item9 = new Item("Nalgene bottle", 0.7, "plastic", "gross");

    Item item10 = new Item("Refrigerator box", 13.4, "cardboard", "gross");

    // Sort these Items

    // Hmmm...I didn't make any instances of Sorter...

    Sorter.sortItem(item1);

    Sorter.sortItem(item2);

    Sorter.sortItem(item3);

    Sorter.sortItem(item4);

    Sorter.sortItem(item5);

    Sorter.sortItem(item6);

    Sorter.sortItem(item7);

    Sorter.sortItem(item8);

    Sorter.sortItem(item9);

    // Print a blank line before statistics

    System.out.println();

    // Print out statistics

    double totalWeight = Sorter.getTotalWeight();

    System.out.println("Total weight of sorted items: " + totalWeight);

    // EXTRA CREDIT-- uncomment if you want to give it a shot!

    double recycledRatio = Sorter.getRecycledRation();

    System.out.println("Ratio of items recycled to items trashed: " + recycledRatio);

}

}

I have included the driver also in the answer code! please chk!