(Ignore my first version of this post.) Write an abstract super-class encapsulat
ID: 3658380 • Letter: #
Question
(Ignore my first version of this post.) Write an abstract super-class 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 sub-classes: one encapsulating an applicant for undergraduate school and the other encapsulating an applicant for graduate school. An applicant for undergraduate school has two additional attributes: an SAT score, and a GPA. An applicant for graduate school has one additional attribute: the college of origin. It also has a method which 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 these two classes.Explanation / Answer
import java.util.Scanner; abstract class CollegeApplicant { String applicantName; String collegeName; public String getApplicantName() { return applicantName; } public void setApplicantName(String applicantName) { this.applicantName = applicantName; } public String getCollegeName() { return collegeName; } public void setCollegeName(String collegeName) { this.collegeName = collegeName; } void checkCollege() { int choice; Graduate g = new Graduate(); Undergraduate ug = new Undergraduate(); Scanner input = new Scanner(System.in); System.out.println("1. Undergraduate"); System.out.println("2. Graduate"); System.out.println("enter your choice "); choice = input.nextInt(); if (choice == 1) { System.out.println("Enter SAT marks :"); ug.SAT = input.nextDouble(); System.out.println("Enter GPA marks :"); ug.GPA = input.nextDouble(); } else { System.out.println("Enter the origin of college:"); g.collegeOrigin = input.next(); System.out.println("Status :" + g.checkCollegeName()); } } class Undergraduate { double SAT; double GPA; } class Graduate { String collegeOrigin; String checkCollegeName() { String information = null; if (collegeName.equals(collegeName)) information = "from inside"; else information = "from outside"; return information; } } } public class TestCollege extends CollegeApplicant { public static void main(String[] args) { TestCollege tc = new TestCollege(); Scanner input = new Scanner(System.in); System.out.println("enter the name of applicant "); tc.setApplicantName(input.next()); System.out.println("enter the college name of applicant "); tc.setCollegeName(input.next()); tc.checkCollege(); } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.