help creating a virtual Object
I'm stuck on how to get started on this part of my assignment. These are my instructions.
The next class that you need to create will be what I call a Virtual Object. It is an object that we are creating so that we can store data in a concise and thoughtful manner. The only thing we want to do here is store data for easy access and referencing from other classes.
Class Name: Student
Default Constructor – Should do nothing
Overridden Constructor – Should create a student with a name and all 10 grades
Global Variables:
strStudentName
dblAssignmentOne
dblAssignmentTwo
dblAssignmentThree
dblAssignmentFour
dblAssignmentFive
dblAssignmentSix
dblAssignmentSeven
dblAssignmentEight
dblAssignmentNine
dblAssignmentTen
Methods: Each global variable should have an accessor (getter) and a mutator (setter).
I posted a sample peice. Is this what it is asking for? or am I way off?
Code Java:
public class student{
public String getStudentName(String strStudentName){
return strStudentName;
}
pubic String setStudentName(String strStudentName){
this.strStudentName = strStudentName;
}
public String getdblAssignmentOne(double dblAssignmentOne){
return dblAssignmentOne;
}
pubic String setdblAssignmentOne(double dblAssignmentOne){
this.dblAssignmentOne = dblAssignmentOne;
}
Re: help creating a virtual Object
you're not way off, but slightly.
A getter is meant to "get" data. It doesn't require any input parameters, and should return the value in question.
An example getter:
Code java:
public class A
{
private String foo;
public String getFoo()
{
return foo;
}
}
By the same token, a setter "sets" data fields. It takes in input parameter(s) and modifies internal fields appropriately. A typical setter modifies one field exclusively. Almost always these methods do not return any values.
An example setter:
Code java:
public class A
{
private String foo;
public void setFoo(String value)
{
foo = value;
}
}