subject

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

ansver
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 22:10, Metlife
Asequential circuit contains a register of four flip-flops. initially a binary number n (0000 ≤ n ≤ 1100) is stored in the flip-flops. after a single clock pulse is applied to the circuit, the register should contain n + 0011. in other words, the function of the sequential circuit is to add 3 to the contents of a 4-bit register. design and implement this circuit using j-k flip-flops.
Answers: 1
image
Computers and Technology, 23.06.2019 09:30, Cocco
You have been supporting csm tech publishing's windows server 2016 server network for over a year. the office has two windows server 2016 servers running active directory and a number of other roles. management has informed you that a small sales office is opening in the same building three floors up. the sales manager wants to install a sales application on a server located in the sales office. this server will have limited physical security because there's no special room dedicated for it, which means it will be accessible to non-it personnel and visitors. you're considering installing windows server 2016 server core on the new server because accessing its console regularly probably won't be necessary, and this server will be managed from one of the other csm tech publishing servers. what are the benefits and drawbacks of using server core for this branch office? what are some things you should do to set up this server management environment?
Answers: 1
image
Computers and Technology, 23.06.2019 23:00, minosmora01
How do you know if the website is secure if you make a purchase
Answers: 2
image
Computers and Technology, 24.06.2019 07:00, jared2461
Jean has kept the content of her website limited to what is important; she has also ensured that the text follows a particular style and color all throughout her website. which website features has jean kept in mind? jean has limited the content of her website to what is important; this ensures (clarity, simplicity, harmony and unity) of the content. she has also formatted the text in a particular style and color throughout her website, ensuring (balance, simplicity, consistency)
Answers: 2
You know the right answer?
Questions 5 - 7 refer to the following code:

public class Whatchamacallit {
privat...

Questions in other subjects:

Konu
Mathematics, 26.01.2021 07:20
Konu
Mathematics, 26.01.2021 07:20