Question
public class Drink { private int size, amount; public Drink(int size) { this.size = size; this.amount = size; } public int sip() { amount?; return
public class Drink { private int size, amount; public Drink(int size) { this.size = size; this.amount = size; } public int sip() { amount?; return amount; } public int gulp(int n) { for (int i = 0; i < n; i++) { sip(); } return amount; } public int refill() { amount = size; return amount; } }
1) Choose a sequence of statements that prints 2. Do not include unneeded statements
a) Drink drink1 = new Drink(12);
b) Drink drink1 = new Drink(16);
c) int n = 7;
d) int n = 13;
e) int r = drink1.gulp(n);
f) if (r <= 0) r = drink1.refill();
g)r = drink1.sip();
h) System.out.print(r);
2) Choose a sequence of statements that prints 36. Do not include unneeded statements.
a)Drink drink1 = new Drink(12);
b) Drink drink1 = new Drink(16);
c) Drink drink2 = new Drink(32);
d) Drink drink2 = drink1;
e) drink1.gulp(2);
f) drink2.gulp(drink1.sip() / 2);
g) int r = drink1.sip() + drink2.sip();
h) System.out.print(r);
3) Choose a sequence of statements that prints 38. Do not include unneeded statements
a)Drink drink1 = new Drink(12);
b) Drink drink1 = new Drink(16);
c) Drink drink2 = new Drink(32);
d) Drink drink2 = drink1;
e) drink1.gulp(2);
f) drink2.gulp(drink1.sip() / 2);
g) int r = drink1.sip() + drink2.sip();
h) System.out.print(r);
4) Choose a sequence of statements that prints 37. Do not include unneeded statements.
a)Drink drink1 = new Drink(12);
b) Drink drink1 = new Drink(16);
c) Drink drink2 = new Drink(32);
d) Drink drink2 = drink1;
e) drink1.gulp(2);
f) drink2.gulp(drink1.sip() / 2);
g) int r = drink1.sip() + drink2.sip();
h) System.out.print(r);
5) Choose a sequence of statements that prints 11. Do not include unneeded statements.
a)Drink drink1 = new Drink(12);
b) Drink drink1 = new Drink(16);
c) Drink drink2 = new Drink(32);
d) Drink drink2 = drink1;
e) drink1.gulp(2);
f) drink2.gulp(drink1.sip() / 2);
g) int r = drink1.sip() + drink2.sip();
h) System.out.print(r);
|
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started