.SPRING 2017. CS 23 Programming Quiz# 3 Page 1 of 2 Dr. Badi, A. 90 nutes April1
ID: 3817073 • Letter: #
Question
.SPRING 2017. CS 23 Programming Quiz# 3 Page 1 of 2 Dr. Badi, A. 90 nutes April13, 2016 Name: Grade This is an open book and open notes programming quiz Answer all questions For partial credit, show your work. The figures below show the University, College, and Department class hierarchy, and the Education interface. The University is the parent class to College, and the College is the parent class to Department. University universityName universityAddr l Education (interface) 1 get DegreeName building Nunber department Name numberof Students The University class defines two private member variables: universityName, and universityAddress. The College class defines two private member variables: collegeNane and buildingNumber The Department class defines two private member variables: departmentName, and numberofstudents. 1- create Java classes to design and test this hierarchy.The classes are to be named as in the figures,ie. University, College, Department etc. Make sure to select suitable variable types (String, double, int, etc.) for the member variables. 2- Add a 'river class that contains a main0 function. This Driver class will be used to test the hierarchy. You can choose a different name for the Driver class, if you have an existing file with that name in the same directory. 3- For each class, define a default, no-argument constructor. 4- For each class, define a constructor that will assign values to all the class variables, including the variables that are part of the class's parents.Explanation / Answer
Below is the executable code with output :
Driver Class :
public class Driver {
public static void main(String[] args)
{
Department deparmnt = new Department("Biology", 230);
College colg = new College("Science,Engineering and Math", 27);
University uni = new University("BCU", "Dayton Beach,Florida");
System.out.println("University Name = "+uni.getUniversityName());
System.out.println("University Address = "+uni.getUniversityAddress());
System.out.println("College Name = "+colg.getCollegeName());
colg.getDegree();
System.out.println("Building Number = "+colg.getBuildingNumber());
System.out.println("Department Name = "+deparmnt.getDepartmentName());
System.out.println("No of students = "+deparmnt.getNumberOfStudents());
}
}
University Class :
public class University{
private String universityName;
private String universityAddress;
public University(String universityName, String universityAddress) {
super();
this.universityName = universityName;
this.universityAddress = universityAddress;
}
public String getUniversityName() {
return universityName;
}
public void setUniversityName(String universityName) {
this.universityName = universityName;
}
public String getUniversityAddress() {
return universityAddress;
}
public void setUniversityAddress(String universityAddress) {
this.universityAddress = universityAddress;
}
}
Department Class :
public class Department{
private String departmentName;
private int numberOfStudents;
public Department(String departmentName, int numberOfStudents) {
super();
this.departmentName = departmentName;
this.numberOfStudents = numberOfStudents;
}
public String getDepartmentName() {
return departmentName;
}
public void setDepartmentName(String departmentName) {
this.departmentName = departmentName;
}
public int getNumberOfStudents() {
return numberOfStudents;
}
public void setNumberOfStudents(int numberOfStudents) {
this.numberOfStudents = numberOfStudents;
}
}
College Class :
public class College implements Education{
private String collegeName;
private int buildingNumber;
public College(String collegeName, int buildingNumber) {
super();
this.collegeName = collegeName;
this.buildingNumber = buildingNumber;
}
public String getCollegeName() {
return collegeName;
}
public void setCollegeName(String collegeName) {
this.collegeName = collegeName;
}
public int getBuildingNumber() {
return buildingNumber;
}
public void setBuildingNumber(int buildingNumber) {
this.buildingNumber = buildingNumber;
}
public void getDegree(){System.out.println("Biology");}
}
Education Interface :
public interface Education {
void getDegree();
}
Output :
University Name = BCU
University Address = Dayton Beach,Florida
College Name = Science,Engineering and Math
Biology
Building Number = 27
Department Name = Biology
No of students = 230
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.