Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

6. Suppose for a school there are three types of personnels: Student can only park in Lot 1; Faculty can park in Lot 1

6. Suppose for a school there are three types of personnels: Student can only park in Lot 1; Faculty can parkPersonnel Type} public static void main (String[] args) { Personnel [] personnels = new Personnel [3]; personnels [0] = new

6. Suppose for a school there are three types of personnels: Student can only park in Lot 1; Faculty can park in Lot 1 and 2; Service can park in any parking lots. One way to achieve this is by using conditional as following. public class PersonnelType { 1; 3; public static final int STUDENT public static final int FACULTY = 2; public static final int SERVICE private int typeCode; public PersonnelType (int typeCode) { this.typeCode = typeCode; } public int getTypeCode () { return typeCode; = } Personnel Type"); public boolean canParkInLot (int i) { switch (getTypeCode ()) { case STUDENT: lot + ": } case FACULTY: return (i==1); default: case SERVICE: } return (i==1) | (i==2); return true; Rewrite the above method using Polymorphism (either inheritance or implementation) so that conditionals are no longer needed. You can use the following class to test your implementation. throw new RuntimeException ("Unexpected public class PersonnelTester { public static void canParkInLot (Personnel [] personnels) { for (Personnel person: personnels) { for (int lot=1;lot } public static void main(String[] args) { Personnel [] personnels = new Personnel [3]; personnels [0] = new Student (); personnels [1] = new Faculty(); personnels [2] = new Service (); canPark InLot (personnels); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

public class PersonnelType public static final int ... 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

Data Analysis And Decision Making

Authors: Christian Albright, Wayne Winston, Christopher Zappe

4th Edition

538476125, 978-0538476126

More Books

Students also viewed these Programming questions

Question

In Problems 1118, mentally solve each equation. 6x = -24

Answered: 1 week ago