QUIZ 9

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

We want to create a class that represents a geometric sequence. A geometric sequence is a sequence of numbers that begin at some value and then multiplies each value by some constant to get the next value. For example, the geometric sequence 1, 2, 4, 8, 16 starts at 1 and multiplies each term by 2 to get the next. The geometric sequence 10.8, 5.4, 2.7, 1.35 starts at 10.8 and multiplies each term by 0.5 to get the next. The basic framework of a geometric sequence class is below: public class GeometricSequence { private double currentValue; private double multiplier; } Assume that the parameters to the constructor are initial and mult. What should the body of the constructor be?

currentValue = initial; multiplier = mult;

We want to create a class that represents a date. A date has a day, month, and year. For example, the date March 16, 2014 has the day 16, month 3, and year 2014. The basic framework of a date class is below: public class Date { private int day; private int month; private int year; } The default date will be set to January 1, 1990. What should the body of the constructor with zero parameters be?

day = 1; month = 1; year = 1990;

We want to create a class that represents a date. A date has a day, month, and year. For example, the date March 16, 2014 has the day 16, month 3, and year 2014. The parameter variables in the constructor for month, day, and year should be m, d and y. The basic framework of a date class is below: public class Date { private int day; private int month; private int year; } What should the body of the constructor be?

day = d; month = m; year = y;

Each object of a class has its own set of ___.

instance variables

We want to change the BankAccount class so that all accounts will have a monthly fee. The instance variable monthlyFee will hold the monthly fee. Which of the following constructors properly sets the monthly fee to a default value of 20?

public BankAccount (double initialBalance) { balance = initialBalance; monthlyFee = 20; }

We want to change the BankAccount class so that all accounts will have a monthly fee. The instance variable monthlyFee will hold the monthly fee. Which of the following is the correct public interface for a constructor that sets both the initial balance and monthly fee?

public BankAccount (double initialBalance, double monthlyFee)

We want to create a class that represents a date. A date has a day, month, and year. For example, the date March 16, 2014 has the day 16, month 3, and year 2014. The basic framework of a date class is below: public class Date { private int day; private int month; private int year; } We want to create a specific date using code like: Date first = new Date (16, 3, 2014); // Creates March 16, 2014 Date second = new Date (1, 9, 2013); // Creates September 1, 2013 Which of the constructor specifications below will allow this code to behave as desired?

public Date (int d, int m, int y)

We want to create a class that represents a geometric sequence. A geometric sequence is a sequence of numbers that begin at some value and then multiplies each value by some constant to get the next value. For example, the geometric sequence 1, 2, 4, 8, 16 starts at 1 and multiplies each term by 2 to get the next. The geometric sequence 10.8, 5.4, 2.7, 1.35 starts at 10.8 and multiplies each term by 0.5 to get the next. The basic framework of a geometric sequence class is below: public class GeometricSequence { private double currentValue; private double multiplier; } We want to create a geometric sequence using code like: GeometricSequence first = new GeometricSequence (1, 2); // Creates 1, 2, 4, 8, 16... GeometricSequence second = new GeometricSequence (10.8, 0.5); // Creates 10.8, 5.4, 2.7, 1.35 ... Which of the constructor specifications below will allow this code to behave as desired?

public GeometricSequence(double initial, double mult)

Which of the following corresponds to a valid constructor header for the Player class?

public Player()

Which of the following is a valid constructor header for the Player class that accepts the player name as a parameter?

public Player(String playerName)

Which of the following corresponds to the constructor body for a Square class that accepts an initial side length value called initialLength where the instance variable is named sideLength?

sideLength = initialLength;

Consider the constructor of the BankAccount class that has a parameter for the initial balance. Which line of code is equivalent to this constructor body? balance = initialBalance;

this.balance = initialBalance;

Which of the following statements is true about constructors?

Providing a constructor for a class is optional.

Consider the following code to declare a constructor for the Player class: public void Player(String playerName) { name = playerName; } Which statement is true?

The code compiles successfully but results in a logic error in the code that calls the method.

Which statement is true about the following constructor of the BankAccount class? public BankAccount(double balance) { this.balance = balance; }

The code sets the instance variable balance to the parameter variable balance.


Ensembles d'études connexes

Chapter 6: Understand Consumers and Business Markets

View Set

Topic 2 - volume of distribution

View Set

Astronomy Chapter 4 and 5 Study Guide

View Set

Chapter 1: Introduction to Legal Principles and Authorities

View Set

Chapter #14 - Servicing & Maintance

View Set

Elsevier NCLEX Renal/Musculoskeletal

View Set

AP Human Geography Sustainable Development Goals

View Set