6. Suppose for a school there are three types of personnels: Student can only park in...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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<=3;lot++) { System.out.println (person.getType () + + person.canParkInLot (lot)); can park in 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); } 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<=3;lot++) { System.out.println (person.getType () + + person.canParkInLot (lot)); can park in 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); }
Expert Answer:
Answer rating: 100% (QA)
public class PersonnelType public static final int ... View the full answer
Related Book For
Data Analysis and Decision Making
ISBN: 978-0538476126
4th edition
Authors: Christian Albright, Wayne Winston, Christopher Zappe
Posted Date:
Students also viewed these programming questions
-
Do stock prices reflect/embed available information (eg., the economic impact of the Pandemic)?. Argue if the markets are efficient or the markets are inefficient.
-
A registered dealer, based in Chandigarh, makes a supply to another registered dealer located in Chandigarh, valuing rupees 1,20,000. The applicable rate of GST is 12%. Calculate the amount of tax...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
In Problems 1118, mentally solve each equation. 6x = -24
-
A soap bubble (n = 1.33) is floating in air. If the thickness of the bubble wall is 115 nm, what is the wavelength of the light that is most strongly reflected?
-
The Blade Division of Dana Company produces hardened steel blades. One third of the Blade Division's output is sold to the Lawn Products Division of Dana; the remainder is sold to outside customers....
-
The numbers of weeks the 33 leading movies remained at number 1 as of March 2018. Find the mean, the median, and the mode of the data, if possible. If any measure cannot be found or does not...
-
Bel-Air, Inc., is a small engineering corporation that surveys land for development. The company has grown rapidly over the past few years, and management has to decide whether to hire new engineers...
-
Costs per Equivalent Unit and Production Costsof direct materials.Cost per equivalent units of $ 9 . 6 0 for Direct Materials and $ 3 . 0 0 for Conversion Costs.a . Cost of beginning work in process...
-
In Figure P3-53, calculate the temperatures at points 1, 2, 3, and 4 using the numerical method. Figure P3-53 700 C 100 C 400 C 3 500 C
-
Given Matrix: 7 3 S F = 6 8 10 12 1816 Find inverse F -1 = 3
-
What would happen to the cost per equivalent unit for March 2021 for the Welding Department if the overhead was allocated based on the amount of direct material in the Welding Department instead of...
-
2023 PMI Pulse of the Profession for background and context, what thoughts do you have re: the power skills and how organizations should focus more on soft skills and why.? Given the information...
-
What master data is exclusively necessary for the design to operate process?
-
After reading the Way-Mart Case from our textbook, respond to the following prompts in one to four sentences: Based on the information in the case (and as of the case's date, 2013) Does Walmart have...
-
What term describes the estimated amount of capital that is being used each year?
-
Using the indirect method, if equipment is sold at a gain, the a. sale proceeds received are deducted in the operating activities section. b. sale proceeds received are added in the operating...
-
Determine whether the lines are parallel, perpendicular, or neither. 2x + 3y = -12, 2y - 3x = 8
-
Based on Marcus (1990). The Balboa mutual fund has beaten the Standard and Poors 500 during 11 of the last 13 years. People use this as an argument that you can beat the market. Here is another way...
-
The file S02_55.xlsx contains monthly retail sales of beer, wine, and liquor at U.S. liquor stores. a. Is seasonality present in these data? If so, characterize the seasonality pattern and then...
-
Political polls typically sample randomly from the U.S. population to investigate the percentage of voters who favor some candidate or issue. The number of people polled is usually on the order of...
-
Using the demand and cost curves of an individual firm in oligopoly, demonstrate the effects of each of the following: a. The Clean Air Act b. The Nutrition and Labeling Act c. A ban on smoking...
-
Kodak has developed an important brand name through its advertising, innovation, and product quality and service. Suppose Kodak sets up a network of exclusive dealerships, and one of the dealers...
-
Explain why a market in which broadcast licenses can be purchased might be more efficient than having the FCC assign licenses on some basis designed by the FCC.
Study smarter with the SolutionInn App