Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

package KellyAvagyanP1; public interface Displayable { public abstract String display(); } public abstract class Person { private String firstName; private String lastName; public String getFirstName()

package KellyAvagyanP1;

public interface Displayable {

public abstract String display();

}

public abstract class Person {

private String firstName;

private String lastName;

public String getFirstName() {

return firstName;

}

public void setFirstName(String fname)

{

firstName = fname;

}

public String getLastName()

{

return lastName;

}

public void setLastName(String lname)

{

lastName = lname;

}

public String getFullName()

{

return (firstName + " " + lastName);

}

package KellyAvagyanP1;

import java.util.ArrayList;

public class ClassRoom extends Person implements Displayable{

private int roomNumber;

private Displayable teacher;

private ArrayList students;

public ClassRoom() {

}

public ClassRoom (int roomNumber,Displayable teacher, ArrayList students)

{

this.roomNumber = roomNumber;

this.teacher = teacher;

this.students = students;

}

@ Override

public String display()

{

String display = "";

display += "Room number:" + roomNumber;

display += " " + teacher.display();

for (int i =0; i< students.size(); i++)

{

display += " " + students.get(i).display();

}

return display;

}

}

{

}

}

public class School {

public static void main(String[] args) {

new PrintReports();

}

}

public class Student extends Person implements Displayable {

private int studentId;

private int finalGrade;

public Student( int studentId, String lastName, String firstName, int finalGrade)

{

setFirstName(firstName);

setLastName(lastName);

this.studentId = studentId;

this.finalGrade = finalGrade;

}

public int getStudentId()

{

return studentId;

}

public void setStudentId(int id)

{

studentId = id;

}

public int getFinalGrade()

{

return finalGrade;

}

public void setFinalGrade(int finalGrade)

{

this.finalGrade = finalGrade;

}

@Override

public String display()

{

return "Studen id " + studentId + getFullName() + "Final grade " + finalGrade;

}

}

Teacher

public class Teacher extends Person implements Displayable{

private String subject;

public Teacher (String firstName, String lastName, String subject)

{

setFirstName(firstName);

setLastName (lastName);

this.subject = subject;

}

public String getSubject()

{

return subject;

}

public void setSubject(String subject)

{

this.subject = subject;

}

@Override

public String display()

{

return getFullName() + " teaches " + subject;

}

}

PrintReport

package KellyAvagyanP1;

import java.util.*;

public class PrintReports {

Scanner in = new Scanner(System.in);

private char answer;

private ArrayList list = new ArrayList();

public PrintReports()

{

System.out.println("You need to create a Classroom");

do {

Displayable c = enterClassRoom();

list.add(c);

System.out.print("Enter another class room (Y or N) ");

answer = in.next().toLowerCase().charAt(0);

} while (answer != 'n');

report(list);

}

public Displayable enterClassRoom()

{

System.out.println("Enter a room number");

//Scanner input = new Scanner(System.in);

int roomNumber = in.nextInt();

if(roomNumber<100)

System.out.println ("Error. Please enter a number greater than 100");

Displayable teacher = enterTeacher();

String s = "";

do

{

//enterStudent();

Displayable student = enterStudent();

list.add(student);

}

while (s == "");

return new ClassRoom(roomNumber,teacher,list);

}

public Displayable enterTeacher()

{

System.out.println("Please enter your first and last names as well as the subject you teach.");

String firstName = in.nextLine();

String lastName = in.nextLine();

String subject = in.nextLine();

Teacher teacher = new Teacher(firstName, lastName, subject);

return teacher;

public Displayable enterStudent()

{

do {

System.out.println("Please enter your student Id, your first and last names as well as your final grade");

int id = in.nextInt();

String lastName = in.nextLine();

String firstName = in.nextLine();

int finalGrade = in.nextInt();

Student student = new Student(id, lastName, firstName, finalGrade);

return student;}

while(id < 0);

public void report(ArrayList)

I need to implement the very last method // void report(ArrayList) method

Here are the instructions to create the method

  • The void report(ArrayLIst) Method

I a for loop, iterate through the ArrayList collection containing the downcast Classroom objects.

Call the display() method defined in Classroom. It should report the room number.

It should call the display() method in the teacher variable to report the teacher assigned to the classroom.

In a for loop it should iterate through the ArrayList collection of Student objects calling the display() method for each one.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Joy L. Starks, Philip J. Pratt, Mary Z. Last

9th Edition

1337093424, 978-1337093422

More Books

Students also viewed these Databases questions

Question

1. Identify the sources for this conflict.

Answered: 1 week ago

Question

3. The group answers the questions.

Answered: 1 week ago