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
Q1: StringTokenizer is a class in the java.util
Q3: The behavior of an object is defined
Q4: Which of the following reserved words in
Q5: A class' constructor usually defines
A) how an
Q7: In order to preserve encapsulation of an
Q8: Consider a Rational class designed to represent
Q9: An example of passing message to a
Q21: Having multiple class methods of the same
Q28: If a method does not have a
Q37: Consider a sequence of method invocations as
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents