Exam 4: Defining Classes I

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

Write a Java method that prints the phrase "Five purple people eaters were seen munching Martians".

Free
(Essay)
4.8/5
(36)
Correct Answer:
Verified

/** void method that prints a phrase */ public void printPhrase() { System.out.println("Five purple people eaters were seen munching Martians!"); }

Add two constructors to the Appointment class created in question #9.Include a default constructor and a constructor to initialize an Appointment to suitable arguments.

Free
(Essay)
4.8/5
(33)
Correct Answer:
Verified

/** Class constructors */ public Appointment() { startTime = 0; endTime = 0; dayOfWeek = ""; month = ""; day = 0; year = 0; } public Appointment(int st,int et,String dow,String m,int d,int y) { setStartTime(st); setEndTime(et); setDayOfWeek(dow); setMonth(m); setDay(d); setYear(y); }

Write a method called power the computes xn where x and n and positive integers.The method has two integer parameters and returns a value of type long.

Free
(Essay)
4.7/5
(33)
Correct Answer:
Verified

/** x and n are nonnegative integers */ public long power(int x,int n) { long result = 1; /** check for positive numbers */ if((x >= 0)&& (n >= 0)) { /** raise x to the nth power */ for(int i = n; i > 0; i--) result *= x; } else { result = 0; System.out.println("Fatal error.......positive integers required!"); } return result; }

A _________ states what is assumed to be true when the method is called.

(Multiple Choice)
4.8/5
(33)

Discuss the importance of accessor and mutator methods and how they apply to the abstraction concept.

(Essay)
4.9/5
(44)

In Java,call-by-value is only used with:

(Multiple Choice)
4.9/5
(38)

Two methods that are expected to be in all Java classes are:

(Multiple Choice)
4.9/5
(38)

An invocation of a method that returns a value can be used as an expression any place that a value of the Type_Returned can be used.

(True/False)
4.8/5
(35)

Discuss the public and private modifiers in context of methods and instance variables.

(Essay)
4.9/5
(32)

The body of a method that returns a value must contain at least one _________ statement.

(Multiple Choice)
4.8/5
(40)

The Java language supports global variables.

(True/False)
5.0/5
(43)

Accessor methods:

(Multiple Choice)
4.8/5
(35)

It is considered good programming practice to validate a value passed to a mutator method before setting the instance variable.

(True/False)
4.8/5
(42)

Java supports operator overloading.

(True/False)
4.8/5
(27)

Write a Java class that represents a Student with instance variables name,id,and gpa.Include constructors,accessor,mutator and any facilitator methods you may need.

(Essay)
4.8/5
(42)

A variable whose meaning is confined to a method definition is called an/a

(Multiple Choice)
4.9/5
(45)

A method that performs some action other than returning a value is called a __________ method.

(Multiple Choice)
4.8/5
(28)

Boolean expressions may be used to control if-else or while statements.

(True/False)
4.8/5
(37)

Only the default constructor has the this parameter.

(True/False)
4.8/5
(30)

Write a driver program to test your Student class created in question #14.

(Essay)
4.8/5
(39)
Showing 1 - 20 of 44
close modal

Filters

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