Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1 Objective This project will give you an opportunity to use many of the concept

ID: 3894191 • Letter: 1

Question

1 Objective

This project will give you an opportunity to use many of the concepts you’ve learned throughout the

quarter. It will include the familiar, like objects, and a new thing like storing user-defined objects in an

ArrayList, creating abstract classes, and implementing interfaces. After this project, you will have gotten

a good survey of object-oriented programming and its potential. Note that this project uses one Interface

and one abstract class.

2 What to Create

You are writing the application that deals with information about Pearson at College.

2.1 Enum classes

You should create two enumeration classes Sex and Level.The enumeration class Sex has only two elements: MALE and FEMALE.

The enumeration class Level has following elements: ESL1A, ESL1B, ESL2A, ESL2B, ESL3A, ESL3B, ESL4A, ESL4B, ESL5A, ESL5B, ESL6A, ESL6B.

2.2 Interfaces and Classes

For every class, you should decide which private variables are needed. Also, don’t forget about toString() method.

1 Write an interface Person that requires the implementation of typical features that return a First Name, Last Name, Id, and Sex of person.

2 Write an abstract class StudentsThe constructor of this class gets parameters id, first name, last name, sex, and month, day, year of birth. In this class, you should realize all methods of the interface. Also, this class includes one abstract method getPrice(), and methods that set and return credits of a student. A ESL student has every time 5 credits.

3 Write the ESL class that is a subclass of Student.The getPrice() method returns $25.0 every time. The constructor of this class gets parameters: id, first name, last name, day, month, year, sex, and level

4 Write the ESLStudents class.This class must contain ArrayList of ESL students and have methods which let to add a student, remove a student with a specific index, return numbers of students, return ESL student that has a specific index. Also, this class must have a method that called isFound(). This method gets the id of student and returns the index of this student or -1 if this id doesn't exist. Besides, you should realize a method that gets level and returns how many students have this level.

5 Write the College class that is a subclass of Student. The getPrice() method returns a value equals the cost of the one credit multiply by the number of credits.

6 Write the CollegeStudents class.This class must contain ArrayList of College students and have methods which let to add a student, remove a student with a specific index, return numbers of students, return College student that has a specific index. Also, this class must have a method that called isFound(). This method gets the id of student and returns the index of this student or -1 if this id doesn't exist. Besides, you should realize a method that returns how many full-time students there are. A full-time student must have 13 or more credits.

2.3 toString() method At the topmost class, create a toString() method that supplies all the information it knows about the students. In each subclass that adds information of interest, concatenate that information to the string created by its superclass.

3 General

• We don’t need a variety of constructors here; create constructors that include everything needed.

• You know enough that all your UI should guard against bad data types and out-of-range data; handle these gracefully with positive user interactions. Let the user try again if they make a mistake.

• Provide preconditions wherever they make sense and help guard against data from outside the class that might cause crashes or other bad behavior; throw appropriate exceptions in those cases.

• All classes should have toString methods with an attractive output.

5 Hints

• Pay close attention to the difference between IS A relationship (inheritance) and HAS A relationships (instantiation and use); use the right one here. We’ve done projects with both types of relationships this quarter.

• Build from the ground up. Write the interface first. Then code Student, writing and running the test code for each method you add. Once you’ve shored up that class, move onto ESLStudent. Again, incrementally develop and test. Once that’s solid, move to the next branch.

6 Testing

Create test methods for ESL, ESLStudents, College, CollegeStudents classes.

Please, do it in java

Explanation / Answer

The required enums, interface and class files are given below in the tables. I was able to complete this much within the limited time provided to us. Please submit a different question thread for the remaining ones. Hope you will understand it. You can give a thumbs up if you liked it.

public enum Sex {

MALE,

FEMALE

}

public enum Level {

ESL1A, ESL1B, ESL2A, ESL2B, ESL3A, ESL3B,

ESL4A, ESL4B, ESL5A, ESL5B, ESL6A, ESL6B

}

public interface Person {

public String getFirstName();

public void setFirstName(String fname);

public String getLastName();

public void setLastName(String lname);

public int getID();

public void setID(int id);

public Sex getGender();

public void setGender(Sex s);

}

public abstract class Student implements Person {

private int ID;

private String firstName, lastName;

private Sex gender;

private int birthMonth;

private int birthDay;

private int birthYear;

public Student(int id, String fn, String ln, Sex s, int bm, int bd, int by)

{

ID = id;

firstName = fn;

lastName = ln;

gender = s;

birthMonth = bm;

birthDay = bd;

birthYear = by;

}

@Override

public String getFirstName()

{

return this.firstName;

}

@Override

public void setFirstName(String fname)

{

firstName = fname;

}

@Override

public String getLastName()

{

return this.lastName;

}

@Override

public void setLastName(String lname)

{

lastName = lname;

}

@Override

public int getID()

{

return this.ID;

}

@Override

public void setID(int id)

{

ID = id;

}

@Override

public Sex getGender()

{

return gender;

}

@Override

public void setGender(Sex s)

{

gender = s;

}

@Override

public String toString()

{

return "ID: " + ID + " " +

"First Name: " + firstName + " " +

"Last Name: " + lastName + " " +

"Gender: " + gender + " " +

"Birth Date: " + birthMonth + " - " + birthDay + " - " + birthYear;

}

public abstract double getPrice(); // abstract method

public abstract void setprice(double p); // abstract method

}

public class ESL extends Student{

private Level level;

public ESL(int id, String fn, String ln, Sex s, int bm, int bd, int by, Level l)

{

super(id, fn, ln, s, bm, bd, by);

level = l;

}

public Level getLevel()

{

return level;

}

public void setLevel(Level l)

{

level = l;

}

@Override

public double getPrice() {

return 25.0;

}

@Override

public void setprice(double p) {

// TODO Auto-generated method stub

}

public String toString()

{

return super.toString() + " "+

"Level: " + level;

}

}

import java.util.ArrayList;

public class ESLStudents {

private ArrayList<ESL> ESL_students;

public ESLStudents()

{

ESL_students = new ArrayList<>();

}

public void addStudent(ESL student)

{

ESL_students.add(student);

}

public boolean removeStudent(int index)

{

int size = getTotalStudents();

if(index < 0 || index > size)

return false;

else

{

ESL_students.remove(index);

return true;

}

}

public int getTotalStudents()

{

return ESL_students.size();

}

public int isFound(int id)

{

for(int i = 0; i < getTotalStudents(); i++)

{

if(id == ESL_students.get(i).getID())

return i;

}

return -1;

}

public int getStudentsHavingLevel(Level l)

{

int count = 0;

for(int i = 0; i < getTotalStudents(); i++)

{

if(ESL_students.get(i).getLevel() == l)

count++;

}

return count;

}

}

public class College extends Student {

private double valuePerCredit;

private int numCredits;

public College(int id, String fn, String ln, Sex s, int bm, int bd,

int by, double vpc, int numC)

{

super(id, fn, ln, s, bm, bd, by);

valuePerCredit = vpc;

numCredits = numC;

}

public double getValuePerCredit() {

return valuePerCredit;

}

public int getNumCredits() {

return numCredits;

}

public void setValuePerCredit(double valuePerCredit) {

this.valuePerCredit = valuePerCredit;

}

public void setNumCredits(int numCredits) {

this.numCredits = numCredits;

}

@Override

public double getPrice() {

return valuePerCredit * numCredits;

}

@Override

public void setprice(double p) {

// TODO Auto-generated method stub

}

public String toString()

{

return super.toString() + " " +

"Value/Credit: " + valuePerCredit + " " +

"Total Credits: " + numCredits + " ";

}

}

import java.util.ArrayList;

public class CollegeStudents {

private ArrayList<College> college_studs;

public CollegeStudents()

{

college_studs = new ArrayList<>();

}

public void addStudent(College student)

{

college_studs.add(student);

}

public boolean removeStudent(int index)

{

int size = getTotalStudents();

if(index < 0 || index > size)

return false;

else

{

college_studs.remove(index);

return true;

}

}

public int getTotalStudents()

{

return college_studs.size();

}

public int isFound(int id)

{

for(int i = 0; i < getTotalStudents(); i++)

{

if(id == college_studs.get(i).getID())

return i;

}

return -1;

}

public int getTotalFullTimeStudents()

{

int count = 0;

for(int i = 0; i < getTotalStudents(); i++)

{

if(college_studs.get(i).getPrice() >= 13)

count++;

}

return count;

}

}

Important Note: Create the java files with the exact names as given (i.e., Sex.java, Level.java, ESL.java, Student.java, Person.java, ESLStudents.java, College.java, CollegeStudents.java) and copy-paste their contents into them. These classes are merely raw class files. They don't have any main method into them. Hence they can not be made to run. You need a Driver program with a main method into it to use and run the classes.

Sex.java (enum)

public enum Sex {

MALE,

FEMALE

}