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

Create, save and compile the following interface definition in a file called Car

ID: 3638355 • Letter: C

Question

Create, save and compile the following interface definition in a file called Carryable.java:
public interface Carryable {
public GroceryItem[] getContents();
public String getDescription();
public float getPrice();
}
Here is a class that represents a GroceryItem that you buy at the grocery store:
public class GroceryItem implements Carryable {
String name;
float price;
float weight; // in kg
public GroceryItem(String n, float p, float w) {
name = n;
price = p;
weight = w;
}
}
Complete this class by implementing a public toString() method that returns a String representing a
GroceryItem with the format shown below. Note that the RED bolded text should represent the
values from the attributes ... and so should vary from item to item (do not worry about the exact
formatting of the price amount):
SnackPack Pudding weighing 0.396 kg with price $0.99

Since the class implements the Carryable interface, you will need also need to write a
getContents(), getDescription() and getPrice() method. The contents should return an empty
array of size 0. The description should be the item name. The price should be the item price.

how would i write the methods for getdiscription get contents and getprice

Explanation / Answer

public class Print{ public static void main(String[] args){ int i=1; int j; while(i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote