Question

Create College.java to display information about students and faculty at your college. USE THE DBPM TEMPLATE...

Create College.java to display information about students and faculty at your college.
USE THE DBPM TEMPLATE AT THE BOTTOM !!!

Specifications

Use the DBPM Class Construction Format to create all of the classes, attributes and methods.

·         Create a Person class. The class stores first name, last name, and email address.
·         Create a class named Student that extends the Person class.
       This class stores a student id, major, student level (freshman, sophomore, junior, or senior).

·         Create a College class with the main method.

Student (example data)

Name: Frank Jones
Email: frank44@hotmail.com
Student id: M10293
Major: Business
Level: Sophomore

·         Create a class named Instructor that inherits from the Person class. This class stores a social security number, subject area taught and number of years worked as an instructor.

Faculty (example data)

Name: Anne Price
Email: anne@nctc.edu
Social security number: 111-11-1111
Subject area: Physics for 3 years.

Ask if you want to see the student or instructor information. Based on the response, display the appropriate information. The individual subclasses should handle the information for the student and the instructor.

--------------------

Further clarification:

In main, ask if they are a student or an instructor. Create the appropriate object and update the attributes. Then based on their response for a student or instructor, you will either go to the Student class or the Instructor class and display the information.

For extra credit (10 points): Create an array of student and instructor objects to store multiple instances.

Example output for the program on inheritance:

Are you a student or instructor: student

OUTPUT:
Name: Frank Jones
Email: frank44@hotmail.com
Student id: M10293
Major: Business
Level: Sophomore

Are you a student or instructor: instructor

OUTPUT:
Name: Anne Price
Email: anne@nctc.edu
Social security number: 111-11-1111
Subject area: Physics for 3 years.

---------------------------

Class Layout:

class Person {
}

class Student extends Person {
}

class Instructor extends Person {
}

public class College {

    class Student student;
    class Instructor instructor;

main () {

   // question: add student or instructor?
   // create student object and populate the data in the object
   // create instructor object and populate the data in the object
   // question: Ask if you want to see the student or the instructor?
   // Display either the student information or the instructor information
}
}

// DBPM TEMPLATE

package college;
import java.util.Scanner;

// Person CLASS
class Person {
private String firstName;
private String lastName;
private String emailAddress;

public Person() {
// initialize the three class attributes firstName, lastName, emailAddress

}

public Person(String emailAddress) {
this.firstName = "";
this.lastName = "";
this.emailAddress = emailAddress;
}

public Person(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
this.emailAddress = "";
}

public Person(String firstName, String lastName, String emailAddress) {
// initialize the three class attributes firstName, lastName, emailAddress

}

//Create setters and getters for firstName, lastName, emailAddress

}
// Instructor CLASS

class //Define the Instructor class as a subclass of Person {

private long SSN;
private String subject;
private long yearsWorked;

public Instructor() {
this.SSN = 0;
this.subject = "";
this.yearsWorked = 0;
}

public Instructor(String subject) {
//initialize the class attibutes SSN, subject, yearsWorked
}

public Instructor(long SSN, long yearsWorked) {
//initialize the class attibutes SSN, subject, yearsWorked
}

public Instructor(long SSN, String subject, long yearsWorked) {
//initialize the class attibutes SSN, subject, yearsWorked
}

//Create setters and getters for SSN, subject, yearsWorked

public void addInstructor() {
Scanner input = new Scanner(System.in);
String userValue = "";
System.out.println("*** INSTRUCTOR INFORMATION ***");
System.out.print("First Name ?:");
userValue = input.nextLine();
setFirstName(userValue);
System.out.print("Last Name ?:");
userValue = input.nextLine();
setLastName(userValue);
System.out.print("Email Address ?:");
userValue = input.nextLine();
setEmailAddress(userValue);
System.out.print("SSN ?:");
this.SSN = input.nextLong();
input.nextLine();
System.out.print("Subject ?:");
this.subject = input.nextLine();
System.out.print("Years Worked ?:");
this.yearsWorked = input.nextLong();
input.nextLine();
}

public void showInstructor() {
System.out.println("*** DISPLAY INSTRUCTOR INFORMATION ***");
System.out.println("Name :" + getFirstName() + " " + getLastName());
System.out.println("Email Address :" + getEmailAddress());
System.out.println("Social Security Number :" + this.SSN);
System.out.println("Subject Area :" + this.subject + " for " + this.yearsWorked);
}
}
// Student CLASS

class //Create the Student class as a subclass (child of Person) {

private long studentId;
private String major;
private String studentLevel;

//Complete the constructor. Initialize the attributes studentID, major, studentLevel
public Student() {

}

//Complete the overloaded constructor.Initialize the attributes studentID, major, studentLevel
public Student(long studentId) {

}
//Complete the overloaded constructor.Initialize the attributes studentId, major, studentLevel
public Student(String major, String studentLevel) {

}
//Complete the overloaded constructor.Initialize the attributes studentId, major, studentLevel
public Student(long studentId, String major, String studentLevel) {

}
//Create setters and getters for studentId, major, studentLevel

public void addStudent() {
Scanner input = new Scanner(System.in);
String userValue = "";
System.out.println("*** STUDENT INFORMATION ***");
System.out.print("First Name :");
userValue = input.nextLine();
setFirstName(userValue);
System.out.print("Last Name :");
userValue = input.nextLine();
setLastName(userValue);
System.out.print("Email Address :");
userValue = input.nextLine();
setEmailAddress(userValue);
System.out.print("Student Id :");
studentId = input.nextLong();
input.nextLine();
System.out.print("Major :");
this.major = input.nextLine();
System.out.print("Student Level :");
this.studentLevel = input.nextLine();
}

public void showStudent() {
System.out.println("*** DISPLAY STUDENT INFORMATION ***");
System.out.println("Name :" + getFirstName() + " " + getLastName());
System.out.println("Email Address :" + getEmailAddress());
System.out.println("Student Id :" + this.studentId);
System.out.println("Major :" + this.major);
System.out.println("Student Level :" + this.studentLevel);
}
}
// COLLEGE CLASS

public class College {
// Create a class attribute called student of type Student
// Create a class attribute called instructor of type Instructor

public College() {
this.student = new Student();
this.instructor = new Instructor();
}

public College(Student student) {
this.student = student;
this.instructor = new Instructor();
}

public College(Instructor instructor) {
this.student = new Student();
this.instructor = instructor;
}

public College(Student student, Instructor instructor) {
this.student = student;
this.instructor = instructor;
}

public College(Instructor instructor, Student student) {
this.student = student;
this.instructor = instructor;
}
//Create setters and getters for student and instructor

public void addSudent() {
student.addStudent();
}

public void addInstructor() {
instructor.addInstructor();
}

public void displayStudent() {
student.showStudent();
}

public void displayInstructor() {
instructor.showInstructor();
}
// --------------

/**
* *** MAIN LOGIC
*
* @param args
*/
public static void main(String[] args) {
String flag = "";
String userValue = "";
College Baylor = new College();
Scanner userInput = new Scanner(System.in);

do {
System.out.print("\nAdd student or instructor (s/i)?");
userValue = userInput.nextLine();

if ("s".equalsIgnoreCase(userValue)) {
Student student = new Student();
student.addStudent();
Baylor.setStudent(student);

} else if ("i".equalsIgnoreCase(userValue)) {
Instructor instructor = new Instructor();
instructor.addInstructor();
Baylor.setInstructor(instructor);
} else {
System.out.println("ERROR: Invalid Entry");
}

System.out.print("\nDisplay student or instructor (s/i)?");
userValue = userInput.nextLine();
if ("s".equalsIgnoreCase(userValue)) {
Baylor.getStudent();
Baylor.displayStudent();
} else if ("i".equalsIgnoreCase(userValue)) {
Baylor.getInstructor();
Baylor.displayInstructor();
}

System.out.print("\nWould you like to continue or exit(c/x):");
flag = userInput.nextLine();
} while (flag.equalsIgnoreCase("C"));
}

}

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

Person.java

public class Person {
private String firstName, lastName, email;
  
public Person()
{
this.firstName = "";
this.lastName = "";
this.email = "";
}

public Person(String email)
{
this.firstName ="";
this.lastName = "";
this.email = email;
}
  
public Person(String firstName, String lastName)
{
this.firstName = firstName;
this.lastName = lastName;
this.email = "";
}

public Person(String firstName, String lastName, String email)
{
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
}

public String getFirstName() {
return firstName;
}

public String getLastName() {
return lastName;
}

public String getEmail() {
return email;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public void setEmail(String email) {
this.email = email;
}
  
@Override
public String toString()
{
return ("Name: " + getFirstName() + " " + getLastName()
+ "\nEmail: " + getEmail());
}
}

Instructor.java

import java.util.Scanner;

public class Instructor extends Person{
private long SSN;
private String subject;
private long yearsWorked;
  
public Instructor()
{
this.SSN = 0;
this.subject = "";
this.yearsWorked = 0;
}
  
public Instructor(String subject)
{
this.SSN = 0;
this.subject = subject;
this.yearsWorked = 0;
}
  
public Instructor(long SSN, long yearsWorked)
{
super();
this.SSN = SSN;
this.subject = "";
this.yearsWorked = yearsWorked;
}
  
public Instructor(long SSN, String subject, long yearsWorked)
{
this.SSN = SSN;
this.subject = subject;
this.yearsWorked = yearsWorked;
}

public long getSSN() {
return SSN;
}

public void setSSN(long SSN) {
this.SSN = SSN;
}

public String getSubject() {
return subject;
}

public void setSubject(String subject) {
this.subject = subject;
}

public long getYearsWorked() {
return yearsWorked;
}

public void setYearsWorked(long yearsWorked) {
this.yearsWorked = yearsWorked;
}
  
public void addInstructor() {
Scanner input = new Scanner(System.in);
String userValue = "";
System.out.println("*** INSTRUCTOR INFORMATION ***");
System.out.print("First Name ?:");
userValue = input.nextLine();
setFirstName(userValue);
System.out.print("Last Name ?:");
userValue = input.nextLine();
setLastName(userValue);
System.out.print("Email Address ?:");
userValue = input.nextLine();
setEmail(userValue);
System.out.print("SSN ?:");
this.SSN = input.nextLong();
input.nextLine();
System.out.print("Subject ?:");
this.subject = input.nextLine();
System.out.print("Years Worked ?:");
this.yearsWorked = input.nextLong();
input.nextLine();
}
  
public void showInstructor()
{
System.out.println("*** DISPLAY INSTRUCTOR INFORMATION ***");
System.out.println("Name :" + getFirstName() + " " + getLastName());
System.out.println("Email Address :" + getEmail());
System.out.println("Social Security Number :" + this.SSN);
System.out.println("Subject Area :" + this.subject + " for " + this.yearsWorked);
}
}

Student.java

import java.util.Scanner;

public class Student extends Person{
private long studentId;
private String major;
private String studentLevel;
  
public Student()
{
super();
this.studentId = 0;
this.major = "";
this.studentLevel = "";
}

public Student(long studentId)
{
this.studentId = studentId;
this.major = "";
this.studentLevel = "";
}

public Student(String major, String studentLevel)
{
this.studentId = 0;
this.major = major;
this.studentLevel = studentLevel;
}

public long getStudentId() {
return studentId;
}

public void setStudentId(long studentId) {
this.studentId = studentId;
}

public String getMajor() {
return major;
}

public void setMajor(String major) {
this.major = major;
}

public String getStudentLevel() {
return studentLevel;
}

public void setStudentLevel(String studentLevel) {
this.studentLevel = studentLevel;
}
  
public void addStudent() {
Scanner input = new Scanner(System.in);
String userValue = "";
System.out.println("*** STUDENT INFORMATION ***");
System.out.print("First Name :");
userValue = input.nextLine();
setFirstName(userValue);
System.out.print("Last Name :");
userValue = input.nextLine();
setLastName(userValue);
System.out.print("Email Address :");
userValue = input.nextLine();
setEmail(userValue);
System.out.print("Student Id :");
studentId = input.nextLong();
input.nextLine();
System.out.print("Major :");
this.major = input.nextLine();
System.out.print("Student Level :");
this.studentLevel = input.nextLine();
}
  
public void showStudent()
{
System.out.println("*** DISPLAY STUDENT INFORMATION ***");
System.out.println("Name :" + getFirstName() + " " + getLastName());
System.out.println("Email Address :" + getEmail());
System.out.println("Student Id :" + this.studentId);
System.out.println("Major :" + this.major);
System.out.println("Student Level :" + this.studentLevel);
}
}

College. java (Main class)

import java.util.Scanner;

public class College {
private Student student;
private Instructor instructor;

public College()
{
this.student = new Student();
this.instructor = new Instructor();
}
  
public College(Student student)
{
this.student = student;
this.instructor = new Instructor();
}
  
public College(Instructor instructor)
{
this.student = new Student();
this.instructor = instructor;
}
  
public College(Student student, Instructor instructor)
{
this.student = student;
this.instructor = instructor;
}

public Student getStudent() {
return student;
}

public void setStudent(Student student) {
this.student = student;
}

public Instructor getInstructor() {
return instructor;
}

public void setInstructor(Instructor instructor) {
this.instructor = instructor;
}
  
public void addSudent() {
student.addStudent();
}

public void addInstructor() {
instructor.addInstructor();
}

public void displayStudent() {
student.showStudent();
}

public void displayInstructor() {
instructor.showInstructor();
}
  
public static void main(String[]args)
{
String flag = "";
String userValue = "";
College Baylor = new College();
Scanner userInput = new Scanner(System.in);
  
do
{
System.out.print("\nAdd student or instructor (s/i)? ");
userValue = userInput.nextLine();

if ("s".equalsIgnoreCase(userValue))
{
Student student = new Student();
student.addStudent();
Baylor.setStudent(student);
}
else if ("i".equalsIgnoreCase(userValue))
{
Instructor instructor = new Instructor();
instructor.addInstructor();
Baylor.setInstructor(instructor);
}
else
{
System.out.println("ERROR: Invalid Entry");
}
  
System.out.print("\nDisplay student or instructor (s/i)? ");
userValue = userInput.nextLine();
if ("s".equalsIgnoreCase(userValue))
{
Baylor.getStudent();
Baylor.displayStudent();
}
else if ("i".equalsIgnoreCase(userValue))
{
Baylor.getInstructor();
Baylor.displayInstructor();
}

System.out.print("\nWould you like to continue or exit(c/x):");
flag = userInput.nextLine();
}while (flag.equalsIgnoreCase("C"));
}
}

****************************************************************** SCREENSHOT *********************************************************

Add a comment
Know the answer?
Add Answer to:
Create College.java to display information about students and faculty at your college. USE THE DBPM TEMPLATE...
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