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
}
}
-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?
A) public int updateHours( ) { return hours; }
B) public void updateHours( ) { hours++; }
C) public updateHours(int moreHours) { hours += moreHours; }
D) public void updateHours(int moreHours) { hours += moreHours; }
E) public int updateHours(int moreHours) { return hours + moreHours; }
Correct Answer:

Verified
Correct Answer:
Verified
Q7: The following method header definition will result
Q39: Which of the following reserved words in
Q40: Write the statement to instantiate an Box
Q41: Write the constructor, which is passed the
Q42: What happens if you declare a class
Q43: Write the constructor for this class.
Q45: Consider a method defined with the header:
Q46: Write a statement to instantiate a cube
Q48: For the questions below, use the following
Q49: The expressions that are passed to a