Question: public class Whatchamacallit { private double price; private String title; public Whatchamacallit() { this (0, none); } public Whatchamacallit(double p, String t) { price =

public class Whatchamacallit { private double price; private String title; public Whatchamacallit() { this (0, "none"); } public Whatchamacallit(double p, String t) { price = 0; if (p > 0) { price = p; } title = t; } public String toString() { return title + " costs $" + price; } }

The following code segment appears in another class:

ArrayList list = new ArrayList(); list.add(new Whatchamacallit()); list.add(new Whatchamacallit(3.5, "book")); list.add(new Whatchamacallit(-17, "CD")); list.add(new Whatchamacallit(18.95, "sweater")); list.add(new Whatchamacallit(5, "notebook")); /* Missing Code */

Suppose the following line is used to replace /* Missing Code */.

System.out.println(list.get(list.size() - 1));

What is printed as a result of executing the code segment?

notebook costs $5.0

CD costs $0.0

book costs $3.5

none costs $0.0

sweater costs $18.95

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!