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
Q3: Defining formal parameters requires including each parameter's
Q12: For the questions below, use the following
Q13: To define a class that will represent
Q14: Consider a method defined with the header:
Q15: For the questions below, use the following
Q16: Instance data for a Java class
A) are
Q16: The relationship between a class and an
Q19: Which of the following Applet methods is
Q21: A variable whose scope is restricted to
Q21: All Java classes must contain a main
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