Question: 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; } }For this exercise, we are going to revisit the Pie superclass thatwe saw as an example in the last lesson. We have addedthe Pumpkin class, which takes the number of slices and a booleanto indicate if it is made with canned pumpkin. We also added

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!