Multiple Choice
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) ?
A) "#.###"
B) "#.0"
C) "0.# "
D) "0.000"
E) "0.0##"
Correct Answer:

Verified
Correct Answer:
Verified
Q9: The behavior of an object is defined
Q11: An example of passing message to a
Q12: In order to preserve encapsulation of an
Q14: When reasoning about a car, we use
Q15: While multiple objects of the same class
Q16: Consider a sequence of method invocations as
Q17: A GUI container is an object that
Q19: Formal parameters are those that appear in
Q22: Explain why it would be a poor
Q50: Java methods can return more than one