CS 1401, Quiz #9

Date: Tuesday, March 15, 2005
Name (please type legibly, ideally in block letters): ______________________________________________________________________

1.      Inheritance. Assume that all students have a name, current load of credit hours, and a status (either “full” for fulltime, or “part” for parttime).  To be considered a fulltime student, a student must be taking at least 12 hours.  However, for graduate students the rule is different because of all their research work.  To be considered a fulltime student, a graduate student must be taking at least 9 hours.  The code below defines a superclass Student.  Write the code for a derived class (subclass) GraduateStudent.

public class Student  {

 

      // All students have a name and current hours

         private String name;

         private int hours;

      // Student status is based on number of current hours 

   private String status;

 

 

      //  Constructor

         public Student ( String inputName, int inputHours ) {

             name = inputName;

             hours = inputHours;

           }

 

      // Accessor method for name

         public String getName ( ) {

               return name;

           }

 

      // Other accessor methods omitted

 

 

// Facilitator method to return status

    public String findStatus ( int studentHours ) {

  if ( studentHours >= 12)  return “full”;

  else return “part”;

     }

   }

 

 

 

 

 

2.      Overloading methods.  Which of the following groups of methods are valid examples of overloaded methods?  Write “yes” in the blank to the left of the group if the methods are overloaded, and “no” in the blank if the methods in the group are not overloaded.    

a. _________        public Dog ( String name , double weight )   { … }

                              public Dog ( String name , double height )   { … }

 

b.___________     public void compute ( double amount )  { … }

                              public int compute ( double num )  { … }

 

c.__________       public Cat ( String name )  { … }

                              public Cat ( String name, double weight )  { … }

                              public Cat ( double weight )  { … }

 

c.__________       public int adjust ( double amount ) { … }

                              public void adjust ( double amount, double charge )  { … }