Exam 4: Writing Classes

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

For the questions below, use the following class definition. 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( ) { DecimalFormat df = new DecimalFormat("xxxx"); // xxxx needs to be replaced return name + "\n" + major + "\n" + df.format(gpa) + "\n" + hours } } -Which of the following patterns should be used in place of "xxxx" when instantiating df so that the gpa to be output in typical form (like 3.810)?

(Multiple Choice)
4.7/5
(37)

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
(36)

Accessors and mutators provide mechanisms for controlled access to a well-encapsulated class.

(True/False)
5.0/5
(44)

Write the constructor, which is passed the player's name and position.

(Essay)
4.9/5
(29)

A method defined in a class can access the class' instance data without needing to pass them as parameters or declare them as local variables.

(True/False)
4.8/5
(39)

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

(True/False)
4.8/5
(36)

Add a constructor to class Box for a cube, which has only 1 parameter, side.

(Essay)
4.8/5
(31)

In order to preserve encapsulation of an object, we would do all of the following except for which one?

(Multiple Choice)
4.9/5
(30)

Defining formal parameters requires including each parameters type.

(True/False)
4.9/5
(34)

StringTokenizer is a class in the java.util library that can divide a String based on some delimiter String (a delimiter is a separator). If the instruction StringTokener st = new StringTokenizer(str, "&&"); is executed, where str is some String, then st divides up str into separate Strings whenever

(Multiple Choice)
4.9/5
(38)

The behavior of an object is defined by the object's

(Multiple Choice)
4.9/5
(41)

Which of the following Applet methods is called automatically when the applet is first loaded?

(Multiple Choice)
4.8/5
(33)

For the questions below, use the following class definition. 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( ) { DecimalFormat df = new DecimalFormat("xxxx"); // xxxx needs to be replaced return name + "\n" + major + "\n" + df.format(gpa) + "\n" + hours } } -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)
5.0/5
(34)

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

(Multiple Choice)
4.9/5
(39)

An object should be encapsulated in order to guard its data and methods from inappropriate access.

(True/False)
4.8/5
(41)

Instance data for a Java class

(Multiple Choice)
4.9/5
(35)
Showing 41 - 56 of 56
close modal

Filters

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