Question
I have some basic questions for my java APCS class. I am not completely sure of the answers, anything would help. Thanks you! 5. The
I have some basic questions for my java APCS class. I am not completely sure of the answers, anything would help. Thanks you!
5. The purpose of a method's precondition is to
A. Describe the algorithm used by the method
B. Describe the conditions under which the compiler is to stop compilation |
C. Initialize the local variables of the method |
D. Describe the conditions that are true when the method completes
E. Describe the conditions under which the method may be called so that it satisfies its postcondition
13. What is the purpose of a class constructor?
A. To invoke a class method
B. To initialize the instance variables
C. To calculate return values for the class
D. Initialize the local variables of the method |
E. To provide client code for the class
15. Which of the following could be a constructor for the public class SomeClass?
I. SomeClass()
II. int SomeClass()
III. SomeClass(int a, String s)
A. Statement II only
B. Statement I only
C. Statement III only
D. Statements I and II only
E. Statements I and III only
17. Given the following class:
public class Magazine { private double discountRate = 0.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 a magazine. The subscription price is calculated by multiplying the newsstand price by discountRate, and then multiplying the result by 12, because there are 12 issues per subscription. For example, if the newsstand price is $3.00, then the subscription price is $21.60, because 0.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?
A. return discountRate;
B. return (getNewsstandPrice / discountRate) * 12;
C. return (getNewsstandPrice() * discountRate) * 12;
D. return (getNewsstandPrice * discountRate) * 12;
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