Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 - Given the following segment of code, // postcondition: returns x + y public int add(int x, int y) {} // postcondition: return x

1 - Given the following segment of code,

// postcondition: returns x + y public int add(int x, int y) {} // postcondition: return x * y public int multiply(int x, int y) {} which of the following corresponds to this expression? multiply(add(multiply(a, b), add(multiply(a, c), multiply(b, c))), 2)

Question 1 options:

1)

a * b + a * c + b * c * 2

2)

a * b + a * c + b * c + 2

3)

a * b + (a * c + b * c)

4)

(a * b + a * c + b * c) * 2

5)

2 * a * b + (a * c + b * c)

2 - The purpose of a method's precondition is to

Question 2 options:

1)

initialize the local variables of the method.

2)

describe the conditions under which the compiler is to stop compilation.

3)

describe the conditions under which the method may be called so that it satisfies its postcondition.

4)

describe the algorithm used by the method.

5)

describe the conditions that are true when the method completes.

3 - Given the following class

public class Magazine { private static double SUBSCRIPTION_DISCOUNT = .60; private String title; private String publisher; private double newsstandPrice; public Magazine(String theTitle, String thePublisher, double theNewsPrice) { title = theTitle; publisher = thePublisher; newsstandPrice = theNewsPrice; } public String getTitle() { return title; } public String getPublisher() { return publisher; } public double getNewsstandPrice() { return newsstandPrice; } public double getSubscriptionPrice() { // implementation not shown } public void setNewsstandPrice(double newPrice) { newsstandPrice = newPrice; } }

Which of the following methods is a mutator method?

Question 3 options:

1)

getTitle

2)

getPublisher

3)

getNewsstandPrice

4)

setNewsstandPrice

5)

All of the above are mutator methods.

4 - Given the following class

public class Magazine { private static double SUBSCRIPTION_DISCOUNT = .60; private String title; private String publisher; private double newsstandPrice; public Magazine(String theTitle, String thePublisher, double theNewsPrice) { title = theTitle; publisher = thePublisher; newsstandPrice = theNewsPrice; } public String getTitle() { return title; } public String getPublisher() { return publisher; } public double getNewsstandPrice() { return newsstandPrice; } public double getSubscriptionPrice() { // implementation not shown } public void setNewsstandPrice(double newPrice) { newsstandPrice = newPrice; } }

The getSubscriptionPrice method returns the price for a subscription to this Magazine. The subscription price is calculated by multiplying the newsstand price by SUBSCRIPTION_DISCOUNT, and then multiplying the result by 12, because there are 12 issues in a subscription. For example, if the newsstand price is $3.00, then the subscription price is $21.60, because .60 times $3.00 is $1.80, and $1.80 times 12 is $21.60.

Which of the following lines of code could be used to implement the getSubscriptionPrice method?

Question 4 options:

1)

return (getNewsstandPrice * SUBSCRIPTION_DISCOUNT) * 12;

2)

return (getNewsstandPrice / SUBSCRIPTION_DISCOUNT) * 12;

3)

return (getNewsstandPrice() * SUBSCRIPTION_DISCOUNT) * 12;

4)

return (getNewsstandPrice() / SUBSCRIPTION_DISCOUNT) * 12;

5)

return SUBSCRIPTION_DISCOUNT;

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Heikki Topi, Jeffrey A Hoffer, Ramesh Venkataraman

13th Edition

0134773659, 978-0134773650

More Books

Students also viewed these Databases questions