Computers and Technology

Questions 5 - 7 refer to the following code:

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
sweater costs $18.95
none costs $0.0

2nd part of question

Suppose the following lines are used to replace /* Missing Code */.

list. remove(1);
System. out. println(list. get(1));

What is printed as a result of executing the code segment?
none costs $0.0
book costs $3.5
sweater costs $18.95
CD costs $0.0
notebook costs $5.0

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 16:00, babyshazi
In a cellular network each cell is controlled by a tower what are these towers called?
Answers: 3
image
Computers and Technology, 22.06.2019 09:00, 19elbatawisaly
What is one way in which tablets differ from laptops and notebooks? tablets are designed for touch-based interaction. tablets are designed to be used as desktops. tablets are designed for input via a keyboard and mouse. tablets are designed to be larger than laptops.
Answers: 1
image
Computers and Technology, 23.06.2019 07:30, emilyplays474
What key should you press and hold to select and open multiple files at one time? enter alt control esc
Answers: 1
image
Computers and Technology, 24.06.2019 11:20, isabelperez063
Every telecommunication setup uses two devices: one device to transmit data and one device to receive data. which device transmits frequencies to mobile phones? towers transmit frequencies to mobile phones.
Answers: 1
Do you know the correct answer?
Questions 5 - 7 refer to the following code:

public class Whatchamacallit {
privat...

Questions in other subjects:

Konu
Mathematics, 08.10.2019 09:10