Question
Hi! I am currently working on my APCS course and I have a few homework questions that I do not understand. Any help would be
Hi! I am currently working on my APCS course and I have a few homework questions that I do not understand. Any help would be great. The language is java. Thank you!
4. 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, a space, and then the last name. For example, if the person's name is Wilma Flintstone, then getFirstInitialPlusLast()would return "W. Flintstone." Which of the following could not be used to implement getFirstInitialPlusLast()? I. return (firstName.substring(0,1) + ". " + lastName); II. return (getFirstName().substring(0,1) + ". " + getLastName()); III. return (getFirstName.substring(0,1) + ". " + getLastName) A. Statement II only B. Statments I and II only C. Statements I,II,and III D. Statements II and III only E. Statement III only 8. 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; } } Which of the following methods is an accessor method? I. getTitle II. getPublisher III. setNewsstandPrice A. Statement III only B. Statement II only C. Statement I and II only D. Statement I only E.S tatement I and III only 18. Given the following class: import java.util.ArrayList; public class RectangleTester { public static void main(String[ ] args) { ArrayList< Rectangle > shapes = new ArrayList< Rectangle >(); shapes.add(new Rectangle(1, 1)); shapes.add(new Rectangle(2, 2)); shapes.add(new Rectangle(3, 3)); shapes.add(new Rectangle(4, 4)); Rectangle dataRecord; for(int index = 0; index < shapes.size(); index++) { dataRecord = shapes.get(index); dataRecord.calcRectArea(); dataRecord.calcRectPerimeter(); System.out.println("Area = " + dataRecord.getArea()); System.out.println("Perimeter = " + dataRecord.getPerimeter()); } } } Assume that getArea() returns the area of a rectangle and getPerimeter() returns the perimeter of a rectangle. What will print when index = 0? A. Area = 9 and Parimeter = 12 B. Area = 1 and Perimeter = 4 C. Area = 16 and Perimeter = 16 D. Area = 25 and Perimeter = 20 E. Area = 4 and Perimeter = 8 20. Assume that you have a class with the following class declaration: public class SomeClass { // class implementation not shown } The following code exists inside a method of SomeClass, and this code compiles without errors: int result = calculate(4, 3.14); Which of the following is true about the calculate method? A. It is located in SomeClass B. Ii is a public method C. It is a private method D. It is not located in SomeClass E. It is an abstract method | |||||||
|
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