Question: Define a default constructor that initializes the fields name ( string ) and height ( double ) with the default values Void and - 1

Define a default constructor that initializes the fields name (string) and height (double) with the default values "Void" and -1.00, respectively.
Ex: If the input is Bob 5.00, then the output is:
Default values:
Name: Void, Height: -1.00
After mutator methods:
Name: Bob, Height: 5.00
Note: The class's print() method is called before and after the input is passed to the setters. public class Student {
private String name;
private double height;
/* Your code goes here */
public void setName(String studentName){
name = studentName;
}
public void setHeight(double studentHeight){
height = studentHeight;
}
public void print(){
System.out.print("Name: "+ name);
System.out.printf(", Height: %.2f
", height);
}
} StudentList.java: import java.util.Scanner;
public class StudentList {
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
String newName;
double newHeight;
Student favoriteStudent = new Student();
System.out.println("Default values: ");
favoriteStudent.print();
newName = scnr.next();
newHeight = scnr.nextDouble();
favoriteStudent.setName(newName);
favoriteStudent.setHeight(newHeight);
System.out.println("After mutator methods: ");
favoriteStudent.print();
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!