Kevin J.

asked • 10/23/20

I need to Modify the objectstudent JAVA program to add a private variable zipcode, you must also add setters and getter method

class Student

{

private int id;

private String name;


public Student()

{

id = 8;

name = "John";

}


public int getid()

{

return id;

}

public String getname()

{

return name;

}

public void setid(int newid)

{

id = newid;

}

public void setname(String newname)

{

name = newname;

}

public String toString()

{

String result = Integer.toString(id)+" "+name;

return result;

}

}

class TestStudent1

{

public static void main(String args[])

{Student s0=new Student();

System.out.println(s0);

Student s1=new Student();

s1.setid(312);

s1.setname("Patrick");

System.out.println("ID is " + s1.getid());

System.out.println("The student name is " + s1.getname());

}

}

Patrick B.

Source code in the RESOURCES section under this link
Report

10/24/20

1 Expert Answer

By:

Patrick B. answered • 10/24/20

Tutor
4.7 (31)

Math and computer tutor/teacher

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.