Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question

this code is in java.

Explore the given classes. Implement a getter method on the WasteRobot class with the following method signature

public ArrayList<Waste> getWasteBin(String wasteType)


The method should return the proper waste bin based on the passed wasteType. Compare the given wasteType to each of the public static final constants in the Waste class to help determine which bin to return.

Given Classes :

WasteRobotTester.java 

import java.util.*;

public class WasteRobotTester
{
    public static void main(String[] args)
    {
        WasteRobot wallie = new WasteRobot();
        
        // Your test code.
    }
}


WasteRobot.java

import java.util.*;

public class WasteRobot
{
    private ArrayList<Waste> trashBin;
    private ArrayList<Waste> compostBin;
    private ArrayList<Waste> recyclingBin;

    public WasteRobot() 
    {
        trashBin = new ArrayList<Waste>();
        compostBin = new ArrayList<Waste>();
        recyclingBin = new ArrayList<Waste>();
        
        trashBin.add(new Trash("Plastic Bag"));
        compostBin.add(new Compost("Banana Peel"));
        recyclingBin.add(new Recycling("Soda Can"));
    }
    
    // Implement this! 
    // getWasteBin(String wasteType) 

}


Waste.java

public abstract class Waste
{
    public static final String TRASH_TYPE = "trash";
    public static final String COMPOST_TYPE = "compost";
    public static final String RECYCLING_TYPE = "recycling";

    private String wasteType;
    private String wasteName;

    public Waste(String wasteType, String wasteName) {
        this.wasteType = wasteType;
        this.wasteName = wasteName;
    }

    public String getWasteType()
    {
        return wasteType;
    }
    
    public String toString()
    {
        return wasteType + ": " + wasteName;
    }
}

Trash.java

public class Trash extends Waste
{
    public Trash(String wasteName)
    {
        super(Waste.TRASH_TYPE, wasteName);
    }
}

Recycling.java


public class Recycling extends Waste
{
    public Recycling(String wasteName)
    {
        super(Waste.RECYCLING_TYPE, wasteName);
    }
}

Compost.java

public class Compost extends Waste
{
    public Compost(String wasteName)
    {
        super(Waste.COMPOST_TYPE, wasteName);
    }
}

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education