Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Institute Demo (70) The following is a simple example of aggregation. In this example we have an Institute which has a number of departments, and

  1. Institute Demo (70) The following is a simple example of aggregation. In this example we have an Institute which has a number of departments, and each department has a number of students, as shown below. (In Java Lanaguage)

Student class (10)

Has three instance variables:

name and dept are of type String

id is an int

Default constructor uses mutators to set name and dept to and id to 0.

The other constructor has three parameters for Siring name, int id, and String dept and uses the mutators to set the instance variables for these values.

There are three mutators and three accessors methods for the three instance variables.There is a toString() method which returns the name, id and dept as a String on a single line

Department class (10)

Has two instance variables.

deptName a String variable

studentList an ArrayList of type Student

Default constructor uses the mutator to set deptName to

The other constructor has a String parameter for the deptName and uses a mutator to set the instance variable for this value.

method addStudent has a reference to a Student as a parameter and a void return.

It adds the reference to the Student to the studentList

method getStudentList has a no parameters and a reference to an ArrayList of type Student as a return value.

It returns a reference to the ArrayList studentList for this department

There is a mutator and accessor method for deptName.

Institute class (20)

Has two instance variables.

instituteName a String variable

departmentsList an ArrayList of type Department

Default constructor uses the mutator to set instituteName to

The other constructor has a String parameter for the instituteName and uses a mutator to set the instance variable for this value.

There is a mutator and accessor method for instituteName.

method addDepartment has a reference to a Department as a parameter and a void return.

It adds the reference to the Department to the departmentList

method getDepartmentsList has a no parameters and a reference to an ArrayList of type Department as a return value.

It returns a reference to the ArrayList departmentsList for this department

method getTotalStudentsInInstitute has no parameters and returns an int this may be done with enhance for or regular for

set noOfStudents to 0

for each department

for each student in the department

increment the noOfstudents by 1

return noOfstudents

InstituteDemo class (30)

Create a Scanner to read from the keyboard

Create a Random class object with a seed of 5

Create a new Institute named BITS

Create a Department CS named CS

Create a Department EE named EE

Create a Department Other named Other

Add each Department to the institutes departmentsList ArrayList

Do 6 times

Request and read in a students name

Request and read in a students Department

Generate a student ID from 1 to 100000 using the Random object you created

Create a student using the name, id and department information

Add the student to the appropriate departments studentList

Produce the output shown below. (Note: Dont forget the last line with the total number of students. Also note that students are list by department)

Sample Input:

Please enter the student name: Ciro

Please enter the Department name CS or EE: CS

Please enter the student name: Armando

Please enter the Department name CS or EE: EE

Please enter the student name: Max

Please enter the Department name CS or EE: EE

Please enter the student name: Pedro

Please enter the Department name CS or EE: YY

Please enter the student name: Jairo

Please enter the Department name CS or EE: CS

Please enter the student name: Simon

Please enter the Department name CS or EE: EE

Sample Output

Institute Name: BITS

Ciro 79488 CS

Jairo 14507 CS

Armando 50093 EE

Max 33475 EE

Simon 17606 EE

Pedro 69425 YY

Total students in institute: 6

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

SQL Server T-SQL Recipes

Authors: David Dye, Jason Brimhall

4th Edition

1484200616, 9781484200612

More Books

Students also viewed these Databases questions

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago