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 could be used to instantiate a new Student s1?

(Multiple Choice)
4.8/5
(35)

What are the objects needed in order to create a Java GUI (graphical user interface)?

(Multiple Choice)
4.9/5
(32)

The interface of a class is based on those data instances and methods that are declared public.

(True/False)
4.7/5
(43)

Regarding the software failure described at the Denver International Airport, it is critical to factor in errors and inefficiencies that always occur in a complex system.

(True/False)
4.9/5
(35)

When reasoning about a car, we use such information as its make and model, year, color, cost (or worth), number of miles, gas mileage, insurance cost, and so forth. Consider a program that will attempt to determine how practical a car might be on a road trip. Which of these types of information might you use in your program as instance data? Provide a justification for your selection.

(Essay)
5.0/5
(45)

Consider a method defined with the header: public void foo(int a, int b). Which of the following method calls is legal?

(Multiple Choice)
4.8/5
(33)

Every class definition must include a constructor.

(True/False)
5.0/5
(32)

Consider a Rational class designed to represent rational numbers as a pair of int's, along with methods reduce (to reduce the rational to simplest form), gcd (to find the greatest common divisor of two int's), as well as methods for addition, subtraction, multiplication, and division. Why should the reduce and gcd methods be declared to be private.

(Multiple Choice)
4.8/5
(37)

Write a statement to output the volume of the blue box.

(Essay)
4.8/5
(43)

Consider a sequence of method invocations as follows: main calls m1, m1 calls m2, m2 calls m3 and then m2 calls m4, m3 calls m5. If m4 has just terminated, what method will resume execution?

(Multiple Choice)
4.9/5
(39)

Another method that might be desired is one that updates the Student's number of credit hours. This method will receive a number of credit hours and add these to the Student's current hours. Which of the following methods would accomplish this?

(Multiple Choice)
4.9/5
(38)

Consider the "Push Me!" program described in section 4.7. As given the push counter starts at zero and is incremented each time the "Push Me!" button is pressed. Let's say that you want to add a class called ResetListener that resets the count to zero. Write the ResetListener class.

(Essay)
4.9/5
(41)

Explain why it would be a poor decision to make instance data public instead of private. Give an example of why this could result in a problem.

(Essay)
4.9/5
(39)

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

A variable whose scope is restricted to the method where it was declared is known as a(n)

(Multiple Choice)
4.8/5
(38)

An Employee will have a name, social security number, position, and hourly wages. Define the instance data for this class.

(Essay)
4.8/5
(35)

The software failure at the Denver International Airport's baggage handling system is a good example of

(Multiple Choice)
4.7/5
(41)

A GUI container is an object that defines a screen element.

(True/False)
4.8/5
(30)

Listener objects "wait" for an event to occur.

(True/False)
4.8/5
(44)

Write the constructor for this class.

(Essay)
5.0/5
(39)
Showing 21 - 40 of 56
close modal

Filters

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