Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this exercise, we are going to revisit the Pie superclass that we saw as an example in the last lesson. We have added the

For this exercise, we are going to revisit the Pie superclass that we saw as an example in the last lesson. We have added the Pumpkin class, which takes the number of slices and a boolean to indicate if it is made with canned pumpkin. We also added a getType() method in the Pie class.

For this exercise, you need to create either an Array or an ArrayList and add 3 pies to that list, an Apple, a Pumpkin, and a third type using the Pie class.

After adding these to your list, loop through and print out the type using the getType() method in the pie class.

Sample Output

Pie: Pumpkin Pie: Apple Pie: Blueberry

import java.util.ArrayList;

public class PieTester { public static void main(String[] args) { // Start here! } }

public class PumpkinPie extends Pie { private boolean canned;

public PumpkinPie (int slices, boolean canned) { super("Pumpkin", slices); this.canned = canned; } public boolean canned() { return canned; } }

public class ApplePie extends Pie {

public ApplePie (int slices) { super("Apple", slices); } public boolean hasSlice() { return super.getSlices() > 0; } @Override public void eatSlice() { if (this.hasSlice()) { super.eatSlice(); } } }

public class Pie {

private String type; private int slices; public Pie (String type, int slices) { this.type = type; this.slices = slices; } public int getSlices (){ return slices; } public void eatSlice(){ slices --; } public String getType(){ return type; } }image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

ETA Pies CodeHS C Get Homework Help With Chegg X C Get Homework Help With Chegg X C Get Homework Help With Chegg X + C codehs.com/student/2052620/section/164847/assignment/28754613/ : Sandbox My Sections Practice + Resume All Waseem Status: Not Submitted 9.5.6: Pies Save Submit + Continue RUN CODE | TEST CASES ASSIGNMENT DOCS | GRADE MORE 5 points Status: Not Submitted FILES 1 import java.util.ArrayList; 2 3 public class Pietester 4-{ 5 public static void main(String[] args) 6 - { 7 // Start here! 8 } 9 } 10 For this exercise, we are going to revisit the Pie superclass that we saw as an example in the last lesson. We have added the Pumpkin class, which takes the number of slices and a boolean to indicate if it is made with canned pumpkin. We also added a getType() method in the Pie class. PieTester.java PumpkinPie.java For this exercise, you need to create either an Array or an ArrayList and add 3 pies to that list, an Apple, a Pumpkin, and a third type using the Pie class. D ApplePie.java Pie.java After adding these to your list, loop through and print out the type using the getType() method in the pie class. Sample Output Pie: Pumpkin Pie: Apple Pie: Blueberry 0; 11 } 12 13 @Override 14 public void eatslice) 15 { 16 if (this.hasslice) 17- { 18 super.eatslice(); 19 20 21 22 Ple.java After adding these to your list, loop through and print out the type using the getType() method in the pie class. Sample Output Pie: Pumpkin Pie: Apple Pie: Blueberry } }

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

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students also viewed these Databases questions

Question

What are the purposes of promotion ?

Answered: 1 week ago

Question

Define promotion.

Answered: 1 week ago

Question

Write a note on transfer policy.

Answered: 1 week ago

Question

=+What is the nature of the plant or site-level role of unions?

Answered: 1 week ago

Question

=+such as the dirigenti in Italy?

Answered: 1 week ago