Concept explainers
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);
}
}
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps
- Java Netbeansarrow_forwardCreate a Point class to hold x and y values for a point. Create methods show(), add() and subtract() to display the Point x and y values, and add and subtract point coordinates. Create another class Shape, which will form the basis of a set of shapes. The Shape class will contain default functions to calculate area and circumference of the shape, and provide the coordinates (Points) of a rectangle that encloses the shape (a bounding box). These will be overloaded by the derived classes; therefore, the default methods for Shape will only print a simple message to standard output. Create a display() function for Shape, which will display the name of the class and all stored information about the class (including area, circumference and bounding box). Build the hierarchy by creating the Shape classes Circle, Rectangle and Triangle. Search the Internet for the rules governing these shapes, if necessary. For these three Shape classes, create default constructors, as well as constructors…arrow_forwardUSING JAVA: Part A) Implement a superclass Appointment and subclasses Onetime, Daily, and Monthly. An Appointment has a description (for example, “See the dentist”) and a date. Write a method, occuresOn(int year, int month, int day) The check whether the appointment occurs on that date. For example, for appointment, you must check whether the day of the month matches. This fill an array of Appointment objects with a mixture of appointments. Have the user enter a date and print out all appointments that occur on that date. Part B) Improve the appointment book by giving the user the option to add new appointments. The user must specify the type of the appointment, the description, and the date.arrow_forward
- Java this piece of my code is not working .....I am trying to add Warship with a type or warship , but I keep getting an error ? //add another WarShip instance to the ArrayList. //use a foreach loop to process the ArrayList and print the data for each ship. //count the number of ships that are not afloat. Return this count to main for printing. //In the shipShow method: the number of ships that are still a Float public static int shipShow(ArrayList<Ship> fleetList) { //from the ArrayList, remove the CargoShip that was declared as type Ship. fleetList.remove(2); //Removing ElFaro form the list // review Type casting instanceof | up casting Ship < Warship , subclass is a object of its parents //add warship USS John Warner - add cast by (Ship) new WarShip Ship warship2 = (Ship) new WarShip("USS John Warner", 2015, true, "attack submarine", "United States"); fleetList.add(warship2); int count= 0; //use a foreach loop to process the ArrayList and print the data for each ship.…arrow_forwardLab 6 - Exercise 2. Write a test driver that reads data about two surgeons and print the specialization of the doctor with the highest salary using the method that compares the salary of surgeons. A Doctor class has the following private data members, constructor, and public methods: name (String) salary (int) End of document I A constructor without parameters, A constructor with parameters, A set method for the data variables (one method) A get method for each data members. A method to print Doctor information A Surgeon is a subclass of Doctor with the following private data members, constructor, and public methods: specialization (String) degree (string) A constructor without parameters, A constructor with parameters, · A set method for the data variables (one method) · A get method for each data member. · A method to print all Surgeon information. · A method that compares the salary of two Surgeons and return the specialization of the doctor with the higher salary. 1. Implement the…arrow_forwardJava Problem Create an object of type FitnessExperiment that stores an array ofStepsFitnessTracker, DistanceFitnessTracker, andHeartRateFitnessTracker objects. In the FitnessExperiment class Add to your FitnessExperimentclass a method called getTotalDistance() that calculates the total distance walked by all theobjects stored in your FitnessExperiment. appropriately both values (total number of steps and total distance walked in that experiment) usingthe printExperimentDetails() method. FitnessExperiemnt.java public class FitnessExperiment {FitnessTracker[] fitnessTrackers;public static void main(String[] args) {FitnessTracker[] trackers ={ new StepsFitnessTracker("steps", new Steps(230)),new StepsFitnessTracker("steps2", new Steps(150)),new StepsFitnessTracker("steps2", new Steps(150)),new HeartRateFitnessTracker("hr", new HeartRate(80)),new HeartRateFitnessTracker("hr", new HeartRate(80)),new DistanceFitnessTracker("dist1", new Distance(1000)),new DistanceFitnessTracker("dist2",…arrow_forward
- For the programming language Javaarrow_forwardCreate a class Course, which has one field: String courseName Create the constructor, accessor, and mutator for the class. Then, in the main method of this class, create an instance of the class with the name "CST1201". Write an equivalent while statement to replace the following for statement for (int i=2; i<100; i=i+2) { System.out.println(i); }arrow_forwardJava- Suppose that Vehicle is a class and Car is a new class that extends Vehicle. Write a description of which kind of assignments are permitted between Car and Vehicle variables.arrow_forward
- Write all the code within the main method in the TestTruck class below. Implement the following functionality. Construct two Truck objects: one with any make and model you choose and the second object with gas tank capacity 10. If an exception occurs, print the stack trace. Print both Truck objects that were constructed. import java.lang.IllegalArgumentException ; public class TestTruck { public static void main( String[] args ) { // write your code herearrow_forwardthis is for a python class 9.12 LAB: Product class In main.py define the Product class that will manage product inventory. Product class has three attributes: a product code, the product's price, and the number count of product in inventory. Implement the following methods: A constructor with 3 parameters that sets all 3 attributes to the value in the 3 parameters set_code(self, code) - set the product code (i.e. SKU234) to parameter code get_code(self) - return the product code set_price(self, price) - set the price to parameter price get_price(self) - return the price set_count(self, count) - set the number of items in inventory to parameter count get_count(self) - return the count add_inventory(self, amt) - increase inventory by parameter amt sell_inventory(self, amt) - decrease inventory by parameter amt Ex. If a new Product object is created with code set to "Apple", price set to 0.40, and the count set to 3, the output is: Name: Apple Price: 0.40 Count: 3 Ex. If 10…arrow_forwardIn Java, please. Complete the Course class by implementing the findStudentHighestGpa() method, which returns the Student object with the highest GPA in the course. Assume that no two students have the same highest GPA. Given classes: Class LabProgram contains the main method for testing the program. Class Course represents a course, which contains an ArrayList of Student objects as a course roster. (Type your code in here.) Class Student represents a classroom student, which has three fields: first name, last name, and GPA. (Hint: getGPA() returns a student's GPA.) Note: For testing purposes, different student values will be used. Ex. For the following students: Henry Nguyen 3.5 Brenda Stern 2.0 Lynda Robison 3.2 Sonya King 3.9 the output is: Top student: Sonya King (GPA: 3.9) LabProgram.java import java.util.Scanner; public class LabProgram { public static void main(String args[]) { Scanner scnr = new Scanner(System.in); Course course = new Course(); int…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education