Exam 4: Writing Classes

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

Class Definition Ch 04-3 Consider a class called Building. This class consists of a number of floors (numberOfFloors) for the building, a current floor for the elevator (current), a requested floor of a person waiting for the elevator (requestedFloor), and methods for constructing the building object, for moving the elevator one floor up, for moving the elevator one floor down, for requesting the elevator and for starting the elevator going. Assume that requestedFloor will be set to 0 if there are currently no requests being made (or the last request has already been fulfilled). -Refer to Class Definition Ch 04-3: What visibility modifiers would you use for the methods that move the elevator up one floor, move the elevator down one floor, that request the elevator, and that start the elevator moving?

(Essay)
4.9/5
(31)

Which of the following reserved words in Java is used to create an instance of a class?

(Multiple Choice)
4.8/5
(36)

Class Definition Ch04-2 The following is from a class named BaseballPlayer. It contains the following data instances: private String name; private String position; private int numAtBats; private int numSingles; private int numDoubles; private int numTriples; private int numHomeRuns; private double battingAverage; -Refer to Class Definition Ch 04-2: Write a toString method that returns the player's name, position, and batting average. formatted to have one digit to the left of the decimal and three digits to the right of the decimal. Assume DecimalFormat has been imported.

(Essay)
4.7/5
(31)

Visibility modifiers include

(Multiple Choice)
4.8/5
(33)

The expressions that are passed to a method in an invocation are called

(Multiple Choice)
4.8/5
(27)

An example of passing a message to a String where the message has a String parameter would occur in which of the following messages?

(Multiple Choice)
4.7/5
(35)

Defining formal parameters requires including each parameter's type.

(True/False)
4.9/5
(39)

Which of the following is not a kind of object that is used to create a graphical user interface in JavaFX?

(Multiple Choice)
4.8/5
(31)

Class Definition Ch 04-1 import java.text.DecimalFormat; public class Student { private String name; private String major; private double gpa; private int hours; public Student(String newName, String newMajor, double newGPA, int newHours) { name = newName; major = newMajor; gpa = newGPA; hours = newHours; } public String toString() { // xxxx needs to be replaced DecimalFormat df = new DecimalFormat("xxxx"); return name + "\n" + major + "\n" + df.format(gpa) + "\n" + hours } } -Refer to Class Definition Ch 04-1: Assume that another method has been defined that will compute and return the student's class rank (Freshman, Sophomore, etc). It is defined as: public String getClassRank() Given that s1 is a student, which of the following would properly be used to get s1's class rank?

(Multiple Choice)
4.7/5
(36)

Java methods can return more than one item if they are modified with the reserved word continue, as in public continue int foo() {...}

(True/False)
4.9/5
(28)

The relationship between a class and an object is best described as

(Multiple Choice)
4.8/5
(42)

Write a portion of a class named Employee. An employee will have a name, ID number, position, and hourly wage. Define the instance data for this class.

(Essay)
4.8/5
(37)

All Java classes must contain a main method which is the first method executed when the Java class is called on.

(True/False)
4.8/5
(34)
Showing 41 - 53 of 53
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)