Class Definition Ch 04-1
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()
{
// xxxx needs to be replaced
DecimalFormat df = new DecimalFormat("xxxx") ; return name + "\n" + major + "\n" + df.format(gpa)
+ "\n" + hours
}
}
-Refer to Class Definition Ch 04-1: Which of the following patterns should be used in place of "xxxx" when instantiating df so that the gpa to be output is in typical form (like 3.810) ?
A) "#.###"
B) "#.0"
C) "0.#"
D) "0.000"
E) "0.0##"
Correct Answer:
Verified
Q21: A variable whose scope is restricted to
Q22: The software failure at the Denver International
Q23: Class Definition Ch 04-1
import java.text.DecimalFormat;
public class Student
{
private
Q24: In a UML diagram for a class
A)
Q25: Consider a Rational class designed to represent
Q27: Instance data for a Java class
A) are
Q28: If a method does not have a
Q29: A class's constructor usually defines
A) how an
Q30: Visibility modifiers include
A) public, private
B) public, private,
Q31: Given the method defined here, which of
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