Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**Each instance of this class is a new Student.
- *
- * @author Stefan Idriceanu
- */
- public class Student
- {
- private final String name;
- private Phone phone;
- //the constructor for a Student
- //the student will come with no phone
- public Student(String theName)
- {
- name=theName;
- phone=null;
- }//student
- /**Used to make a new purchase.
- *
- * @param thePhone The name of the phone that is bought
- */
- //when a student purchases a phone the current phone is discarded
- public void purchasePhone(Phone thePhone)
- {
- phone=thePhone;
- }//purchasePhone
- /**The name of the student
- *
- * @return The name of the student.
- */
- //is used to give back the name instance variable of the student
- public String theName()
- {
- return name;
- }//theName
- /**The phone of the student.
- *
- * @return The object that represents the phone of the student.
- */
- //is used to give back the phone instance variable of the student
- public Phone getPhone()
- {
- return phone;
- }//getPhone
- /**Used to create a view upon the details of the student.
- *
- * @return A string with the details of the student.
- */
- //creates the way a Student will be printed out
- //we can see that the return is using an instance of the phone class
- public String toString()
- {
- if(phone==null)
- return "Student("+name+","+phone+")";
- else
- return "Student("+name+","+phone.toString();
- }//toString
- }//class Student
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement