java—使用多态性填充数组

dohp0rv5  于 2021-07-09  发布在  Java
关注(0)|答案(0)|浏览(227)

这是我的密码。我的工作做得有点过头了。我不应该只做一个申请者,我应该做很多,我应该把申请者分成两个不同的数组,一个是毕业生,一个是本科生。我需要帮助找出如何使一个空数组,并填补这些申请人。一个开始会有帮助

import java.util.Scanner;

public 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;

}
public 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.checkCollege());

    }

}
public class Undergraduate
{
    double SAT;
    double GPA;

}
public class Graduate
{
    String collegeOrigin;
    String checkCollege()
    {
        String information = null;
        if (collegeName.equals(collegeName)) information = "Applicant is applying from inside";
        else information = "Applicant is applying from outside";
        return information;

    }

}

}

客户

import java.util.Scanner;

public class CollegeApplicantClient 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();

  }

 }

下面是一个可能输出的示例

Name: Joe

College Applied to: Harvard

SAT:    5

GPA:    2

Name: Tom

College Applied to: Yale

College of Origin: NYU – from outside

我需要能够把毕业生排成一排,把本科生排成一排。完成后再显示

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题