Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assistance in JAVA please Using the template provided below, write a driver class Destinations java that performs the ToDo tasks in the order indicated. Your

Assistance in JAVA pleaseimage text in transcribedimage text in transcribed

Using the template provided below, write a driver class Destinations java that performs the "ToDo tasks in the order indicated. Your code will be tested for output and additional unit tests will be performed. Include, but do not call, getlden that returns "Program 5a, Firstname Lastname tificationStringo Tips: An ArrayList type is indexed but instead of using braces such as myArrayListCO], we use a method myArrayList.get (0) Methods can be "strung together with the dot operator. For example, o places get (0 returns a Place object for index 0 (the Original Pancake House Eatery object) places get (0) getName0 returns a Place object then for that object calls its getName0resulting in a String object original Pancake House places get (0).getName0.equals( Phil's BBQ') tests this Place object's name against "Phils BBQ" resulting in false Don't rewrite code! If a method exists to perform the task you need, use it! Casting (oh m We have an ArrayList of Place objects. Now, recall this parent class can be a reference to its subclasses. So why can't we write this? System. out. println (places .get (0 getName This works System.out println (places .get (0) getcuisine This doesn't work. getName is a method in the superclass Place. So the object at index 0 s-a Place (a Eatery is a Place and the superclass method get is inherited. Yay! getcuisine however, is a method in the subclass Eatery. A Place is not necessarily an Eatery, that is, it could be an Attraction or a Place. The compiler cannot guarantee that the getcuisine method exists, so it indicates an error at compile time The solution is to cast the retrieved object to the subclass that contains the method. Eatery pancake Eatery) places get (0) System.out.println (pancake.getcuisine

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

Database Security

Authors: Alfred Basta, Melissa Zgola

1st Edition

1435453905, 978-1435453906

More Books

Students also viewed these Databases questions