Question
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
2 - The purpose of a method's precondition is to
Question 2 options:
|
| ||
|
| ||
|
| ||
|
| ||
|
|
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? (3 points)
Question 3 options:
|
| ||
|
| ||
|
| ||
|
| ||
|
|
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? (3 points)
Question 4 options:
|
| ||
|
| ||
|
| ||
|
| ||
|
|
5 - Given the following class
A public Person class is written, and the class has two private String instance variables to store the person's name: one named firstName and one named lastName. The class has two public accessor methods for these instance variables: public String getFirstName() and public String getLastName().
The class has another method: public String getLastPlusInitial(). This method returns a String consisting of the last name, then a comma and a space, then the first initial, and then a period. For example, if the person's name is Fred Flintstone, then getLastPlusInitial() would return "Flintstone, F."
The class has a fourth method: public String getFirstInitialPlusLast(). This method returns a String consisting of the first initial, then a period, and then the last name. For example, if the person's name is Wilma Flintstone, then gefirsInitialPlusLast() would return "W. Flintstone."
Which of the following could be used to implement getLastPlusInitial()? (3 points)
I. return (lastName + ", " + firstName.substring(0, 1) + "."); II. return (getLastName() + ", " + getFirstName().substring(0, 1) + "."); III. return (getLastName + ", " + getFirstName.substring(0, 1) + ".");
Question 5 options:
|
| ||
|
| ||
|
| ||
|
| ||
|
|
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