Question: PLEASE HELP WRITE MAIN College use only arrays and no arraylist validate email Id Objective In this project, youll create several classes using inheritance and
PLEASE HELP WRITE MAIN
College
use only arrays and no arraylist
validate email Id
Objective
In this project, youll create several classes using inheritance and polymorphism. This will require you to create abstract method and class. There wont be any exciting UI here, just some output of array data.
Structure
There are two types of College people: Students and Teachers.
All people have an ID, Name, and Email.
All IDs have validation rules, but rules differ:
Students 9 digits;
Teachers 6 alphanumeric.
For Students, we want to maintain a list of courses taken (up to 30 courses) and associated grades; we want to obtain overall grade averages as well.
For Teachers, we record courses they have taught (up to 50); we want a way to add courses to that list.
| Person |
| -id : String |
| -name : String |
| -email : String |
| Constructors |
| +Person(id : String, name: String) +Person(id : String, name: String, email : String ) |
| Accessors |
| +getId() : String |
| +getName() : String |
| +getEmail() : String |
| Mutators +setId(id : String) +setName(name: String) +setEmail(email : String) |
| Other Methods |
| +isValidId(id : String) : Boolean |
| +toString() : String |
| +test() |
** isValidId() method should be an abstract.
| Students |
| -courseTaken : String[30] |
| -courseGrades : Double[30] |
| -nextCourseIndex : Integer |
| Constructor |
| + Students (id : String, name: String, email : String ) |
| Methods |
| +isValidIdId(id : String) : Boolean |
| +courseCompletion(courseName : String, courseGrade : Double) |
| +getAverageGrade() : Double |
| +toString() : String |
| +test() |
| Teachers |
| -coursesTaught: String[50] |
| -nextCourseIndex : Integer |
| Constructor |
| + Students (id : String, name: String, email : String ) |
| Methods |
| +isValidIdId(id : String) : Boolean |
| +addCourseTaught (courseName : String) |
| +toString() : String |
| +test() |
Code Implementation
Create a main class which creates a new instance of the Students and Teachers classes and displays all information. See examples of output.
Testing
Write test methods for each of your methods.
Test with different courses and grades to make sure your algorithms are correct.
Manual inspection will be necessary; the debugger is your friend and will be very useful here.
----------------------------------
other specifics
1) must validate email id
2) Use only arrays and NO arraylist
Expert Answer
Friend answered this
Was this answer helpful?
0
1
684 answers
thanks for posting the question , we are glad to help you. Here are the 3 classes - Person, Students and Teachers
I noticed one thing, in the question, there is a method test() what exactly we have this method is not mentioned in the question, hence i have created one method but without any implementation.
Due to limited time, i could not manage to write the Main() class, but given all the other classes are implemented, writing the main drive class is pretty straight forward and i believe you should be able to do it without any issue
IF you need help please do let me know, i can assist you
Here are the code for the 3 classes
___________________________________________________________________________________________________
public abstract class Person{ private String id; private String name; private String email; public Person(String id, String name) { this.id = id; this.name = name; } public Person(String id, String name, String email) { this.id = id; this.name = name; this.email = email; } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public abstract boolean isValidId(String id); @Override public String toString() { return this.getId()+", "+this.getName()+", "+this.getEmail(); } public void test(){ } }__________________________________________________________________________________________________
import java.io.CharConversionException; public class Students extends Person{ private String courseTaken[]; private double courseGrades[]; private int nextCourseIndex; public Students(String id, String name, String email) { super(id, name, email); nextCourseIndex=0; courseTaken=new String[30]; courseGrades = new double[30]; } @Override public boolean isValidId(String id) { if(id.length()==9){ for(char c:id.toCharArray()){ if(!Character.isDigit(c)){ return false; } return true; } } return false; } public void courseCompletion(String courseName, double courseGrade){ if(nextCourseIndexcourseGrades.length){ courseTaken[nextCourseIndex]=courseName; courseGrades[nextCourseIndex]=courseGrade; nextCourseIndex++; } } public double getAverageGrade(){ if(nextCourseIndex==0){ return 0; }else{ double sumGrade=0; for(int index=0;indexnextCourseIndex;index++){ sumGrade+=courseGrades[index]; } return sumGrade/(nextCourseIndex); } } @Override public String toString() { return super.toString()+" Total students: "+nextCourseIndex+", Average Grade: "+getAverageGrade(); } public void test(){ } }___________________________________________________________________________________________________
public class Teachers extends Person{ private String[] courseTaught; private int nextCourseIndex; public Teachers(String id, String name, String email) { super(id, name, email); courseTaught= new String[50]; nextCourseIndex=0; } public void addCourseTaught(String courseName){ if(nextCourseIndexcourseTaught.length){ courseTaught[nextCourseIndex]=courseName; nextCourseIndex++; } } @Override public boolean isValidId(String id) { if(id.length()==6){ for(char c : id.toCharArray()){ if(!(Character.isLetter(c)||Character.isDigit(c))){ return false; } return true; } } return false; } @Override public String toString() { return super.toString()+" Total courses taught: "+nextCourseIndex; } public void test(){ } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
