Java please PART A: Implement a class called Student that has these private inst
ID: 3734691 • Letter: J
Question
Java please
PART A: Implement a class called Student that has these private instance variables name - a String indicating the name of the student . year - an int indicating the year that the student began his/her program. studentNumber-an int representing the student number Implement the following instance methods: get methods for all instance variables A zero-argument constructor with reasonable default values A constructor that accepts as arguments the student's name, number and starting year A toString0 method that returns a string representation of the student like this: Ralplh Smith #100654321 (2018) .Explanation / Answer
public class Student { private String name; //private instance variables private int year; private int studentNumer; private int getYear() { //get methods return year; } private String getName() { return name; } private int getStudentNumber() { return studentNumer; } Student() { //default constructor name = "null"; year = 0; studentNumer = 0; } Student(String name, int year, int studentNumer) { //parameterized constructor this.name = name; this.year = year; this.studentNumer = studentNumer; } public String toString() { //toString that returns details return name + " #" + studentNumer + " (" + year + ")"; } public static void main(String[] args) { Student s = new Student(); s = new Student("Smith", 2018, 100654321); System.out.println(s.toString()); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.