Question

(JAVA) Write an abstract superclass encapsulating a college    applicant: A college applicant has two attributes:...

(JAVA) Write an abstract superclass encapsulating a college
   applicant: A college applicant has two attributes:
   the applicant’s name and the college the applicant
   is applying to. This class has two non-abstract
   subclasses: one encapsulating an applicant for
   undergraduate school, and the other encapsulating
   an applicant for graduate school. An applicant for
   undergraduate school has two attributes: a SAT score
   and a GPA. An applicant for graduate school has one
   additional attribute: the college of origin.
   It also has a method that returns “from insideâ€
   if the college of origin is the same as the college
   applied to; otherwise, it returns “from outsideâ€.
   You also need to include a class to test two classes. (JAVA)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution:

Please find the code below for the above problem:

// super class with 2 attributes
abstract class Applicant{
   public String applicantsname;
   public String appliedCollegename;

   // class for undergraduate applicant
   class underGrad extends Applicant{
       double SATscore;
       double gpa;
   }
  
   // class for graduation applicant
   class Grad extends Applicant{
       double SATscore;
       double gpa;
       String collegeOfOrigin;
       String getCollegeName()
       {
           if(appliedCollegename == collegeOfOrigin)
               return "from inside";
           else
               return "from outside";
       }
       String fromInsideOrOutside = getCollegeName();
   }
  
   // class for testing
   public class Test {

       public void main(String[] args) {
           // TODO Auto-generated method stub

           Grad grad = new Grad();
           grad.applicantsname = "name of the applicant";
           grad.appliedCollegename = "name of the college applied for";
           grad.gpa = 9.4;
           grad.SATscore = 85;
           grad.collegeOfOrigin = "name of the college of origin";
       }
   }
}

Please find the attached screenshot for the same:

We had nothing much to do for the class UnderGrad, so I have just given values and tested the Class Grad.

You can easily do for UnderGrad by creating an instance for it and then give the values using the instance.

Thanks!

Add a comment
Know the answer?
Add Answer to:
(JAVA) Write an abstract superclass encapsulating a college    applicant: A college applicant has two attributes:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT